mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v1.05] Improve error reporting due to perf_event_paranoid issues
This commit is contained in:
@@ -45,10 +45,6 @@ int64_t measure_max_frequency(uint32_t core) {
|
|||||||
return -1;
|
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;
|
clockid_t clock = CLOCK_PROCESS_CPUTIME_ID;
|
||||||
|
|
||||||
struct perf_event_attr pe;
|
struct perf_event_attr pe;
|
||||||
@@ -76,9 +72,17 @@ int64_t measure_max_frequency(uint32_t core) {
|
|||||||
fd = perf_event_open(&pe, pid, core, -1, 0);
|
fd = perf_event_open(&pe, pid, core, -1, 0);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
perror("perf_event_open");
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* frequency_banner = "cpufetch is measuring the max frequency...";
|
||||||
|
printf("%s", frequency_banner);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
uint64_t iters = 10000000;
|
uint64_t iters = 10000000;
|
||||||
struct timespec start, end;
|
struct timespec start, end;
|
||||||
if (clock_gettime(clock, &start) == -1) {
|
if (clock_gettime(clock, &start) == -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user