Reorg headers and only print unexpected errno's

This commit is contained in:
2024-08-16 14:25:41 -07:00
parent ce54746a4a
commit 2952abe811

View File

@@ -6,8 +6,10 @@
#include <string.h>
#include <string>
#include <string_view>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <thread>
#include <unistd.h>
@@ -166,16 +168,8 @@ double toSeconds(timeval t) {
return double(t.tv_sec) + double(t.tv_usec) * 1e-6;
}
#include <linux/perf_event.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef __linux__
#include <linux/perf_event.h>
struct PerfCounter {
PerfCounter(int type, int config, const std::string &labels = {})
: labels(labels) {
@@ -190,6 +184,9 @@ struct PerfCounter {
pe.exclude_hv = 1;
fd = perf_event_open(&pe, 0, -1, -1, 0);
if (fd < 0 && errno != ENOENT && errno != EINVAL) {
perror(labels.c_str());
}
}
int64_t total() const {
@@ -278,7 +275,6 @@ int main(int argc, char **argv) {
cacheCounters.emplace_back(PERF_TYPE_HW_CACHE,
id | (op << 8) | (result << 16), labels);
if (!cacheCounters.back().ok()) {
fprintf(stderr, "Could not open cache event: %s\n", labels.c_str());
cacheCounters.pop_back();
}
}