Add cycles_total
Some checks failed
Tests / Clang total: 2840, passed: 2840
Clang |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |0|0|0|0|:clap:
Tests / Debug total: 2838, passed: 2838
weaselab/conflict-set/pipeline/head There was a failure building this commit

This commit is contained in:
2024-08-15 15:13:00 -07:00
parent 72469ebb6e
commit 5a132799a4

View File

@@ -174,14 +174,14 @@ double toSeconds(timeval t) {
#include <unistd.h> #include <unistd.h>
#ifdef __linux__ #ifdef __linux__
struct InstructionCount { struct PerfCounter {
InstructionCount() { explicit PerfCounter(int event) {
struct perf_event_attr pe; struct perf_event_attr pe;
memset(&pe, 0, sizeof(pe)); memset(&pe, 0, sizeof(pe));
pe.type = PERF_TYPE_HARDWARE; pe.type = PERF_TYPE_HARDWARE;
pe.size = sizeof(pe); pe.size = sizeof(pe);
pe.config = PERF_COUNT_HW_INSTRUCTIONS; pe.config = event;
pe.inherit = 1; pe.inherit = 1;
pe.exclude_kernel = 1; pe.exclude_kernel = 1;
pe.exclude_hv = 1; pe.exclude_hv = 1;
@@ -202,7 +202,7 @@ struct InstructionCount {
return count; return count;
} }
~InstructionCount() { close(fd); } ~PerfCounter() { close(fd); }
private: private:
int fd; int fd;
@@ -215,7 +215,8 @@ private:
} }
}; };
#else #else
struct InstructionCount { struct PerfCounter {
explicit PerPerfCounter(int) {}
int64_t total() { return 0; } int64_t total() { return 0; }
}; };
#endif #endif
@@ -232,7 +233,8 @@ int main(int argc, char **argv) {
int metricsCount; int metricsCount;
cs.getMetricsV1(&metrics, &metricsCount); cs.getMetricsV1(&metrics, &metricsCount);
InstructionCount instructions; PerfCounter instructions{PERF_COUNT_HW_INSTRUCTIONS};
PerfCounter cycles{PERF_COUNT_HW_CPU_CYCLES};
auto w = std::thread{workload, &cs}; auto w = std::thread{workload, &cs};
for (;;) { for (;;) {
@@ -265,6 +267,11 @@ int main(int argc, char **argv) {
"instructions_total "; "instructions_total ";
body += std::to_string(instructions.total()); body += std::to_string(instructions.total());
body += "\n"; body += "\n";
body += "# HELP cycles_total Total number of cycles\n"
"# TYPE cycles_total counter\n"
"cycles_total ";
body += std::to_string(cycles.total());
body += "\n";
for (int i = 0; i < metricsCount; ++i) { for (int i = 0; i < metricsCount; ++i) {
body += "# HELP "; body += "# HELP ";