Skip to content

Commit d815807

Browse files
authored
Add more metrics for benchmarking. (#157)
1 parent dcaf53d commit d815807

File tree

576 files changed

+1207
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

576 files changed

+1207
-40
lines changed

core/control_plane/control_plane_objects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void TableConfiguration::setTableKeyMatch(const IR::Expression *tableKeyMatch) {
310310
_tableKeyMatch = tableKeyMatch;
311311
// When we set the table key match, we also need to recompute the match of all table entries.
312312
auto z3TableKeyMatch = Z3Cache::set(tableKeyMatch);
313-
for (auto &tableMatchEntry : _tableEntries) {
313+
for (const auto &tableMatchEntry : _tableEntries) {
314314
tableMatchEntry.get().setZ3Condition(z3TableKeyMatch);
315315
}
316316
}

core/lib/incremental_analysis.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,15 @@ class IncrementalAnalysis : public ICastable {
111111
/// affect the semantics of the program, and specialize the program if necessary.
112112
std::optional<const IR::P4Program *> processControlPlaneUpdate(
113113
const IR::P4Program &program, const ControlPlaneUpdate &controlPlaneUpdate) {
114+
printInfo("Processing 1 control plane update.");
114115
ASSIGN_OR_RETURN(SymbolSet symbolSet, convertControlPlaneUpdate(controlPlaneUpdate),
115116
std::nullopt);
116117
ASSIGN_OR_RETURN(bool changeNeeded, checkForSemanticsChange(symbolSet), std::nullopt);
117118
printInfo("Change in semantics detected: %1%", changeNeeded ? "yes" : "no");
118119
if (!changeNeeded) {
119120
return std::optional{nullptr};
120121
}
121-
122-
auto newProgram = specializeProgram(program);
123-
return newProgram;
122+
return specializeProgram(program);
124123
}
125124

126125
/// Receive a series of control plane updates, convert each update to its intermediate
@@ -143,7 +142,6 @@ class IncrementalAnalysis : public ICastable {
143142
return std::optional{nullptr};
144143
}
145144
}
146-
147145
return specializeProgram(program);
148146
}
149147

core/specialization/flay_service.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,33 @@ int FlayServiceBase::specializeProgram() {
6666
int FlayServiceBase::processControlPlaneUpdate(const ControlPlaneUpdate &controlPlaneUpdate) {
6767
Util::ScopedTimer timer("Processing control plane update");
6868
const auto *optimizedProg = &originalProgram();
69+
_updateCount++;
70+
bool hasRespecialized = false;
6971
for (const auto &[analysisName, incrementalAnalysis] : _incrementalAnalysisMap) {
7072
auto optProgram =
7173
incrementalAnalysis->processControlPlaneUpdate(*optimizedProg, controlPlaneUpdate);
7274
if (!optProgram.has_value()) {
7375
return EXIT_FAILURE;
7476
}
7577
if (optProgram.value() != nullptr) {
78+
_respecializationCount++;
7679
optimizedProg = optProgram.value();
7780
_optimizedProgram = optimizedProg;
81+
hasRespecialized = true;
7882
}
7983
}
84+
if (hasRespecialized) {
85+
_respecializationCount++;
86+
}
8087
return EXIT_SUCCESS;
8188
}
8289

8390
int FlayServiceBase::processControlPlaneUpdate(
8491
const std::vector<const ControlPlaneUpdate *> &controlPlaneUpdates) {
8592
Util::ScopedTimer timer("Processing control plane updates");
93+
_updateCount += controlPlaneUpdates.size();
8694
const auto *optimizedProg = &originalProgram();
95+
bool hasRespecialized = false;
8796
for (const auto &[analysisName, incrementalAnalysis] : _incrementalAnalysisMap) {
8897
auto optProgram =
8998
incrementalAnalysis->processControlPlaneUpdate(*optimizedProg, controlPlaneUpdates);
@@ -93,8 +102,12 @@ int FlayServiceBase::processControlPlaneUpdate(
93102
if (optProgram.value() != nullptr) {
94103
optimizedProg = optProgram.value();
95104
_optimizedProgram = optimizedProg;
105+
hasRespecialized = true;
96106
}
97107
}
108+
if (hasRespecialized) {
109+
_respecializationCount++;
110+
}
98111
return EXIT_SUCCESS;
99112
}
100113

@@ -107,19 +120,19 @@ void FlayServiceBase::recordProgramChange() const {
107120
statementCountBefore, statementCountAfter, stmtPct);
108121
}
109122

110-
std::vector<AnalysisStatistics *> FlayServiceBase::computeFlayServiceStatistics() const {
123+
FlayServiceStatisticsMap FlayServiceBase::computeFlayServiceStatistics() const {
111124
auto statementCountBefore = countStatements(midEndProgram());
112125
auto statementCountAfter = countStatements(optimizedProgram());
113126
auto cyclomaticComplexity = computeCyclomaticComplexity(midEndProgram());
114127
auto numParsersPaths = ParserPathsCounter::computeParserPaths(midEndProgram());
115-
std::vector<AnalysisStatistics *> statistics;
116-
statistics.reserve(_incrementalAnalysisMap.size() + 1);
128+
FlayServiceStatisticsMap statistics;
117129
for (const auto &[analysisName, incrementalAnalysis] : _incrementalAnalysisMap) {
118-
statistics.push_back(incrementalAnalysis->computeAnalysisStatistics());
130+
statistics.emplace(analysisName, incrementalAnalysis->computeAnalysisStatistics());
119131
}
120-
statistics.push_back(new FlayServiceStatistics(&optimizedProgram(), statementCountBefore,
121-
statementCountAfter, cyclomaticComplexity,
122-
numParsersPaths));
132+
statistics.emplace(
133+
"main", new FlayServiceStatistics(&optimizedProgram(), statementCountBefore,
134+
statementCountAfter, cyclomaticComplexity,
135+
numParsersPaths, updateCount(), respecializationCount()));
123136
return statistics;
124137
}
125138

core/specialization/flay_service.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,56 @@ inline double measureSizeDifference(const IR::P4Program &programBefore,
4747
struct FlayServiceStatistics : public AnalysisStatistics {
4848
FlayServiceStatistics(const IR::P4Program *optimizedProgram, uint64_t statementCountBefore,
4949
uint64_t statementCountAfter, size_t cyclomaticComplexity,
50-
size_t numParsersPaths)
50+
size_t numParsersPaths, size_t numUpdatesProcessed,
51+
size_t numRespecializations)
5152
: optimizedProgram(optimizedProgram),
5253
statementCountBefore(statementCountBefore),
5354
statementCountAfter(statementCountAfter),
5455
cyclomaticComplexity(cyclomaticComplexity),
55-
numParsersPaths(numParsersPaths) {}
56+
numParsersPaths(numParsersPaths),
57+
numUpdatesProcessed(numUpdatesProcessed),
58+
numRespecializations(numRespecializations) {}
5659

57-
// The optimized program.
60+
/// The optimized program.
5861
const IR::P4Program *optimizedProgram;
59-
// The number of statements in the original program.
62+
/// The number of statements in the original program.
6063
uint64_t statementCountBefore;
61-
// The number of statements in the optimized program.
64+
/// The number of statements in the optimized program.
6265
uint64_t statementCountAfter;
63-
// The cyclomatic complexity of the input program.
66+
/// The cyclomatic complexity of the input program.
6467
size_t cyclomaticComplexity;
65-
// The total number of paths for parsers
68+
/// The total number of paths for parsers
6669
size_t numParsersPaths;
70+
/// The total number of updates processed.
71+
size_t numUpdatesProcessed = 0;
72+
/// The total number of times a respecialization was necessary.
73+
size_t numRespecializations = 0;
6774

6875
[[nodiscard]] std::string toFormattedString() const override {
6976
std::stringstream output;
7077
output << "\nstatement_count_before:" << statementCountBefore << "\n";
7178
output << "statement_count_after:" << statementCountAfter << "\n";
7279
output << "cyclomatic_complexity:" << cyclomaticComplexity << "\n";
7380
output << "num_parsers_paths:" << numParsersPaths << "\n";
81+
output << "num_updates_processed:" << numUpdatesProcessed << "\n";
82+
output << "num_respecializations:" << numRespecializations << "\n";
7483
return output.str();
7584
}
7685

7786
DECLARE_TYPEINFO(FlayServiceStatistics);
7887
};
7988

89+
/// Maps a particular specialization category to its statistics.
90+
using FlayServiceStatisticsMap = ordered_map<std::string, AnalysisStatistics *>;
91+
8092
class FlayServiceBase {
93+
private:
94+
/// Number of updates processed.
95+
size_t _updateCount = 0;
96+
97+
/// Number of times respecialization was necessary.
98+
size_t _respecializationCount = 0;
99+
81100
protected:
82101
/// The incremental analysis.
83102
IncrementalAnalysisMap _incrementalAnalysisMap;
@@ -94,6 +113,12 @@ class FlayServiceBase {
94113

95114
int specializeProgram();
96115

116+
/// Return the number of updates processed.
117+
[[nodiscard]] size_t updateCount() const { return _updateCount; }
118+
119+
/// Return the number of times respecialization was necessary.
120+
[[nodiscard]] size_t respecializationCount() const { return _respecializationCount; }
121+
97122
public:
98123
explicit FlayServiceBase(const FlayCompilerResult &compilerResult,
99124
IncrementalAnalysisMap incrementalAnalysisMap);
@@ -121,7 +146,7 @@ class FlayServiceBase {
121146
const std::vector<const ControlPlaneUpdate *> &controlPlaneUpdates);
122147

123148
/// Compute and return some statistics on the changes in the program.
124-
[[nodiscard]] std::vector<AnalysisStatistics *> computeFlayServiceStatistics() const;
149+
[[nodiscard]] FlayServiceStatisticsMap computeFlayServiceStatistics() const;
125150
};
126151

127152
} // namespace P4::P4Tools::Flay

core/specialization/service_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ std::vector<std::string> FlayServiceWrapper::findFiles(std::string_view pattern)
8282
return files;
8383
}
8484

85-
std::vector<AnalysisStatistics *> FlayServiceWrapper::computeFlayServiceStatistics() const {
85+
FlayServiceStatisticsMap FlayServiceWrapper::computeFlayServiceStatistics() const {
8686
return _flayService.computeFlayServiceStatistics();
8787
}
8888

core/specialization/service_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FlayServiceWrapper {
3636
void outputOptimizedProgram(const std::filesystem::path &optimizedOutputFile);
3737

3838
/// Compute and return some statistics on the changes in the program.
39-
[[nodiscard]] std::vector<AnalysisStatistics *> computeFlayServiceStatistics() const;
39+
[[nodiscard]] FlayServiceStatisticsMap computeFlayServiceStatistics() const;
4040
};
4141

4242
} // namespace P4::P4Tools::Flay

flay.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int runServer(const FlayOptions &flayOptions, const FlayCompilerResult &flayComp
5151
}
5252
#endif
5353

54-
std::optional<std::vector<AnalysisStatistics *>> runServiceWrapper(
54+
std::optional<FlayServiceStatisticsMap> runServiceWrapper(
5555
const FlayOptions &flayOptions, const FlayCompilerResult &compilerResult,
5656
IncrementalAnalysisMap incrementalAnalysisMap) {
5757
auto controlPlaneApi = flayOptions.controlPlaneApi();
@@ -159,7 +159,7 @@ int Flay::mainImpl(const CompilerResult &compilerResult) {
159159
return ::P4::errorCount() == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
160160
}
161161

162-
std::optional<std::vector<AnalysisStatistics *>> optimizeProgramImpl(
162+
std::optional<FlayServiceStatisticsMap> optimizeProgramImpl(
163163
std::optional<std::reference_wrapper<const std::string>> program,
164164
const FlayOptions &flayOptions) {
165165
// Register supported Flay targets.
@@ -213,8 +213,8 @@ std::optional<std::vector<AnalysisStatistics *>> optimizeProgramImpl(
213213
return runServiceWrapper(flayOptions, flayCompilerResult, std::move(incrementalAnalysisMap));
214214
}
215215

216-
std::optional<std::vector<AnalysisStatistics *>> Flay::optimizeProgram(
217-
const std::string &program, const FlayOptions &flayOptions) {
216+
std::optional<FlayServiceStatisticsMap> Flay::optimizeProgram(const std::string &program,
217+
const FlayOptions &flayOptions) {
218218
try {
219219
return optimizeProgramImpl(program, flayOptions);
220220
} catch (const std::exception &e) {
@@ -226,8 +226,7 @@ std::optional<std::vector<AnalysisStatistics *>> Flay::optimizeProgram(
226226
return std::nullopt;
227227
}
228228

229-
std::optional<std::vector<AnalysisStatistics *>> Flay::optimizeProgram(
230-
const FlayOptions &flayOptions) {
229+
std::optional<FlayServiceStatisticsMap> Flay::optimizeProgram(const FlayOptions &flayOptions) {
231230
try {
232231
return optimizeProgramImpl(std::nullopt, flayOptions);
233232
} catch (const std::exception &e) {

flay.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ class Flay : public AbstractP4cTool<FlayOptions> {
1818
virtual ~Flay() = default;
1919

2020
/// Analyse the given program and return an optimized version.
21-
static std::optional<std::vector<AnalysisStatistics *>> optimizeProgram(
22-
const std::string &program, const FlayOptions &flayOptions);
21+
static std::optional<FlayServiceStatisticsMap> optimizeProgram(const std::string &program,
22+
const FlayOptions &flayOptions);
2323

2424
/// Open the program file specified in the compiler options, preprocess it, and return an
2525
/// optimized version.
26-
static std::optional<std::vector<AnalysisStatistics *>> optimizeProgram(
27-
const FlayOptions &flayOptions);
26+
static std::optional<FlayServiceStatisticsMap> optimizeProgram(const FlayOptions &flayOptions);
2827
};
2928

3029
} // namespace P4::P4Tools::Flay

targets/bmv2/test/testdata/action-synth.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:1
33
statement_count_after:1
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/action-two-params.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ statement_count_before:2
44
statement_count_after:1
55
cyclomatic_complexity:2
66
num_parsers_paths:1
7+
num_updates_processed:0
8+
num_respecializations:0
79

targets/bmv2/test/testdata/action_profile-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ statement_count_before:4
55
statement_count_after:2
66
cyclomatic_complexity:6
77
num_parsers_paths:1
8+
num_updates_processed:0
9+
num_respecializations:0
810

targets/bmv2/test/testdata/action_profile_max_group_size_annotation.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ statement_count_before:4
55
statement_count_after:2
66
cyclomatic_complexity:6
77
num_parsers_paths:1
8+
num_updates_processed:0
9+
num_respecializations:0
810

targets/bmv2/test/testdata/action_profile_sum_of_members_annotation.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ statement_count_before:4
55
statement_count_after:2
66
cyclomatic_complexity:6
77
num_parsers_paths:1
8+
num_updates_processed:0
9+
num_respecializations:0
810

targets/bmv2/test/testdata/action_selector_shared-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ statement_count_before:4
66
statement_count_after:2
77
cyclomatic_complexity:6
88
num_parsers_paths:1
9+
num_updates_processed:0
10+
num_respecializations:0
911

targets/bmv2/test/testdata/action_selector_unused-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:0
33
statement_count_after:0
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/annotation-inline-propagate.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:4
33
statement_count_after:4
44
cyclomatic_complexity:2
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/arith-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:5
33
statement_count_after:5
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/arith1-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:5
33
statement_count_after:5
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/arith2-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:5
33
statement_count_after:5
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/arith3-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:5
33
statement_count_after:5
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/arith4-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:5
33
statement_count_after:5
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/arith5-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:5
33
statement_count_after:5
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/array-copy-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:5
33
statement_count_after:5
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

targets/bmv2/test/testdata/basic2-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ statement_count_before:3
55
statement_count_after:2
66
cyclomatic_complexity:2
77
num_parsers_paths:1
8+
num_updates_processed:0
9+
num_respecializations:0
810

targets/bmv2/test/testdata/basic_routing-bmv2.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ statement_count_before:20
1212
statement_count_after:15
1313
cyclomatic_complexity:15
1414
num_parsers_paths:2
15+
num_updates_processed:0
16+
num_respecializations:0
1517

targets/bmv2/test/testdata/bool_to_bit_cast.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ statement_count_before:6
33
statement_count_after:6
44
cyclomatic_complexity:0
55
num_parsers_paths:1
6+
num_updates_processed:0
7+
num_respecializations:0
68

0 commit comments

Comments
 (0)