Add more perf counters

This commit is contained in:
2024-08-16 10:57:00 -07:00
parent b009de1c2b
commit b15959d62c

View File

@@ -175,7 +175,7 @@ double toSeconds(timeval t) {
#ifdef __linux__ #ifdef __linux__
struct PerfCounter { struct PerfCounter {
explicit PerfCounter(int event) { PerfCounter(int type, int event) {
struct perf_event_attr pe; struct perf_event_attr pe;
memset(&pe, 0, sizeof(pe)); memset(&pe, 0, sizeof(pe));
@@ -216,7 +216,7 @@ private:
}; };
#else #else
struct PerfCounter { struct PerfCounter {
explicit PerPerfCounter(int) {} PerfCounter(int, int) {}
int64_t total() { return 0; } int64_t total() { return 0; }
}; };
#endif #endif
@@ -233,8 +233,12 @@ int main(int argc, char **argv) {
int metricsCount; int metricsCount;
cs.getMetricsV1(&metrics, &metricsCount); cs.getMetricsV1(&metrics, &metricsCount);
PerfCounter instructions{PERF_COUNT_HW_INSTRUCTIONS}; PerfCounter instructions{PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS};
PerfCounter cycles{PERF_COUNT_HW_CPU_CYCLES}; PerfCounter cycles{PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES};
PerfCounter cacheRef{PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES};
PerfCounter cacheMiss{PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES};
PerfCounter branch{PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS};
PerfCounter branchMiss{PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES};
auto w = std::thread{workload, &cs}; auto w = std::thread{workload, &cs};
for (;;) { for (;;) {
@@ -272,6 +276,26 @@ int main(int argc, char **argv) {
"cycles_total "; "cycles_total ";
body += std::to_string(cycles.total()); body += std::to_string(cycles.total());
body += "\n"; body += "\n";
body += "# HELP cache_references_total Total number of cache references\n"
"# TYPE cache_references_total counter\n"
"cache_references_total ";
body += std::to_string(cacheRef.total());
body += "\n";
body += "# HELP cache_misses_total Total number of cache misses\n"
"# TYPE cache_misses_total counter\n"
"cache_misses_total ";
body += std::to_string(cacheMiss.total());
body += "\n";
body += "# HELP branch_instructions_total Total number of branch "
"instructions\n"
"# TYPE branch_instructions_total counter\n"
"branch_instructions_total ";
body += std::to_string(branch.total());
body += "\n";
body += "# HELP branch_misses_total Total number of branch misses\n"
"# TYPE branch_misses_total counter\n"
"branch_misses_total ";
body += std::to_string(branchMiss.total());
for (int i = 0; i < metricsCount; ++i) { for (int i = 0; i < metricsCount; ++i) {
body += "# HELP "; body += "# HELP ";