Skip to content

Commit 590c35d

Browse files
andreas-abelcopybara-github
authored andcommitted
Add cache size overrides to the context.
PiperOrigin-RevId: 831510353 Change-Id: Ic83ab97fb648f7c75df285d19afc6509dbe32799
1 parent b56f1e2 commit 590c35d

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

fleetbench/benchmark_main.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ int main(int argc, char* argv[]) {
143143
}
144144
fleetbench::DynamicRegistrar::Get()->Run();
145145

146+
fleetbench::AddEffectiveCacheSizeToContextIfSpecified();
146147
fleetbench::FleetbenchReporter display_reporter(
147148
benchmark::CreateDefaultDisplayReporter());
148149
if (!fleetbench::FindInCommandLine("--benchmark_out=")) {

fleetbench/common/common.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,24 @@ bool UseExplicitIterationCounts() {
268268
!FindInCommandLine("--benchmark_list_tests");
269269
}
270270

271+
void AddEffectiveCacheSizeToContextIfSpecified() {
272+
if (absl::GetFlag(FLAGS_L1_data_size).has_value() ||
273+
absl::GetFlag(FLAGS_L2_size).has_value() ||
274+
absl::GetFlag(FLAGS_L3_size).has_value()) {
275+
benchmark::AddCustomContext("Effective L1 Data size [KiB]",
276+
absl::StrCat(GetCacheSize(1, "Data") / 1024));
277+
benchmark::AddCustomContext("Effective L2 size [KiB]",
278+
absl::StrCat(GetCacheSize(2) / 1024));
279+
benchmark::AddCustomContext("Effective L3 size [KiB]",
280+
absl::StrCat(GetCacheSize(3) / 1024));
281+
}
282+
}
283+
271284
bool FleetbenchReporter::ReportContext(
272285
const benchmark::BenchmarkReporter::Context& context) {
273286
reporter_->SetOutputStream(&this->GetOutputStream());
274287
reporter_->SetErrorStream(&this->GetErrorStream());
275288
bool result = reporter_->ReportContext(context);
276-
if (absl::GetFlag(FLAGS_L1_data_size).has_value() ||
277-
absl::GetFlag(FLAGS_L2_size).has_value() ||
278-
absl::GetFlag(FLAGS_L3_size).has_value()) {
279-
auto& err = this->GetErrorStream();
280-
err << "Effective CPU Cache Sizes:\n";
281-
err << " L1 Data " << GetCacheSize(1, "Data") / 1024 << " KiB\n";
282-
err << " L2 " << GetCacheSize(2) / 1024 << " KiB\n";
283-
err << " L3 " << GetCacheSize(3) / 1024 << " KiB\n";
284-
}
285289
return result;
286290
}
287291

fleetbench/common/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,9 @@ bool FindInCommandLine(absl::string_view s, bool exact_match = false);
141141
// `/iterations:x` when explicit iteration counts are used.
142142
bool UseExplicitIterationCounts();
143143

144+
// Adds the effective cache sizes to the benchmark context if the cache sizes
145+
// are specified by the corresponding flags.
146+
void AddEffectiveCacheSizeToContextIfSpecified();
147+
144148
} // namespace fleetbench
145149
#endif // THIRD_PARTY_FLEETBENCH_COMMON_COMMON_H_

0 commit comments

Comments
 (0)