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