From 35483cc4938e33c6e76f475a7346bb91a4082baa Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Fri, 16 Feb 2024 23:54:08 +0100 Subject: [PATCH] [v1.05] Improve error reporting due to perf_event_paranoid issues --- src/common/freq.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/freq.c b/src/common/freq.c index 60b33cb..41c8dfe 100644 --- a/src/common/freq.c +++ b/src/common/freq.c @@ -45,10 +45,6 @@ int64_t measure_max_frequency(uint32_t core) { return -1; } - const char* frequency_banner = "cpufetch is measuring the max frequency..."; - printf("%s", frequency_banner); - fflush(stdout); - clockid_t clock = CLOCK_PROCESS_CPUTIME_ID; struct perf_event_attr pe; @@ -63,7 +59,7 @@ int64_t measure_max_frequency(uint32_t core) { #elif ARCH_ARM // TODO nop_function = nop_function_arm; -#endif +#endif memset(&pe, 0, sizeof(struct perf_event_attr)); pe.type = PERF_TYPE_HARDWARE; @@ -76,9 +72,17 @@ int64_t measure_max_frequency(uint32_t core) { fd = perf_event_open(&pe, pid, core, -1, 0); if (fd == -1) { perror("perf_event_open"); + if (errno == EPERM || errno == EACCES) { + printf("You may not have permission to collect stats.\n"); + printf("Consider tweaking /proc/sys/kernel/perf_event_paranoid or running as root.\n"); + } return -1; } + const char* frequency_banner = "cpufetch is measuring the max frequency..."; + printf("%s", frequency_banner); + fflush(stdout); + uint64_t iters = 10000000; struct timespec start, end; if (clock_gettime(clock, &start) == -1) {