P4C
The P4 Compiler
Loading...
Searching...
No Matches
metricsStructure.h
1/*
2Structure definitions used by the code metric collection passes.
3*/
4
5#ifndef FRONTENDS_P4_METRICS_METRICSSTRUCTURE_H_
6#define FRONTENDS_P4_METRICS_METRICSSTRUCTURE_H_
7
8#include <string>
9
10#include "lib/cstring.h"
11#include "lib/ordered_map.h"
12
13namespace P4 {
14
16 unsigned numOperations = 0;
17 unsigned totalSize = 0;
18};
19
21 P4::ordered_map<cstring, PacketModification> perPacket; // Packet type -> operations.
25};
26
28 unsigned variables = 0;
29 unsigned states = 0;
30 unsigned enums = 0;
31 unsigned conditionals = 0;
32 unsigned actions = 0;
33 unsigned functions = 0;
34 unsigned parameters = 0;
35 unsigned returns = 0;
36
37 // Overloads "-" to prevent negative deltas.
38 UnusedCodeInstances operator-(const UnusedCodeInstances &other) const {
40 result.variables = (variables > other.variables) ? (variables - other.variables) : 0;
41 result.states = (states > other.states) ? (states - other.states) : 0;
42 result.enums = (enums > other.enums) ? (enums - other.enums) : 0;
43 result.conditionals =
44 (conditionals > other.conditionals) ? (conditionals - other.conditionals) : 0;
45 result.actions = (actions > other.actions) ? (actions - other.actions) : 0;
46 result.functions = (functions > other.functions) ? (functions - other.functions) : 0;
47 result.parameters = (parameters > other.parameters) ? (parameters - other.parameters) : 0;
48 result.returns = (returns > other.returns) ? (returns - other.returns) : 0;
49 return result;
50 }
51};
52
54 unsigned externFunctions = 0;
55 unsigned externStructures = 0;
56 unsigned externFunctionUses = 0;
57 unsigned externStructUses = 0;
58};
59
60struct UnusedCodeHelperVars { // Variables for storing inter-pass data.
61 UnusedCodeInstances interPassCounts;
62 std::vector<cstring> beforeActions;
63 std::vector<cstring> afterActions;
64 std::vector<cstring> beforeVariables;
65 std::vector<cstring> afterVariables;
66};
67
69 unsigned numTables = 0;
70 // Table name -> value
74
75 unsigned totalKeys = 0;
76 unsigned totalKeySizeSum = 0;
77 double avgKeySize = 0;
78 double avgKeysPerTable = 0.0;
79 unsigned maxKeysPerTable = 0;
80
81 unsigned totalActions = 0;
82 double avgActionsPerTable = 0.0;
83 unsigned maxActionsPerTable = 0;
84};
85
87 P4::ordered_map<cstring, unsigned> blockNestingDepth; // Block name -> max depth.
88 double avgNestingDepth = 0.0;
89 unsigned maxNestingDepth = 0;
90};
91
93 P4::ordered_map<cstring, unsigned> StateComplexity; // State name -> complexity.
94 unsigned totalStates = 0;
95};
96
98 unsigned uniqueOperators = 0;
99 unsigned uniqueOperands = 0;
100 unsigned totalOperators = 0;
101 unsigned totalOperands = 0;
102 unsigned vocabulary = 0.0;
103 unsigned length = 0.0;
104 double difficulty = 0.0;
105 double volume = 0.0;
106 double effort = 0.0;
107 double deliveredBugs = 0.0;
108};
109
111 unsigned numHeaders = 0;
112 double avgFieldsNum = 0.0;
113 double avgFieldSize = 0.0;
114 // Header name -> value
117};
118
119struct Metrics {
120 unsigned linesOfCode = 0;
121 unsigned inlinedActions = 0;
122 UnusedCodeInstances unusedCodeInstances;
123 UnusedCodeHelperVars helperVars;
124 NestingDepthMetrics nestingDepth;
125 HalsteadMetrics halsteadMetrics;
126 HeaderMetrics headerMetrics;
127 HeaderPacketMetrics headerManipulationMetrics; // Header addition and removal operations.
128 HeaderPacketMetrics headerModificationMetrics; // Assignment operations.
129 MatchActionTableMetrics matchActionTableMetrics;
130 ParserMetrics parserMetrics;
131 P4::ordered_map<cstring, unsigned> cyclomaticComplexity; // Function name -> CC value.
132 ExternMetrics externMetrics;
133};
134
135} // namespace P4
136
137#endif /* FRONTENDS_P4_METRICS_METRICSSTRUCTURE_H_ */
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition metricsStructure.h:53
Definition metricsStructure.h:97
Definition metricsStructure.h:110
Definition metricsStructure.h:20
Definition metricsStructure.h:68
Definition metricsStructure.h:119
Definition metricsStructure.h:86
Definition metricsStructure.h:15
Definition metricsStructure.h:92
Definition metricsStructure.h:60
Definition metricsStructure.h:27