mirror of
https://github.com/plasma-umass/coz.git
synced 2024-10-26 07:39:17 +03:00
Merge pull request #86 from llvilanova/patch/perf-perms
perf: Be more informative about errors with perf's permissions
This commit is contained in:
commit
913b76898e
@ -54,7 +54,24 @@ perf_event::perf_event(struct perf_event_attr& pe, pid_t pid, int cpu) :
|
||||
|
||||
// Open the file
|
||||
_fd = perf_event_open(&pe, pid, cpu, -1, 0);
|
||||
REQUIRE(_fd != -1) << "Failed to open perf event";
|
||||
if (_fd == -1) {
|
||||
std::string path = "/proc/sys/kernel/perf_event_paranoid";
|
||||
|
||||
FILE *file = fopen(path.c_str(), "r");
|
||||
REQUIRE(file != NULL) << "Failed to open " << path << ": " << strerror(errno);
|
||||
|
||||
char value_str[3];
|
||||
int res = fread(value_str, sizeof(value_str), 1, file);
|
||||
REQUIRE(res != -1) << "Failed to read from " << path << ": " << strerror(errno);
|
||||
|
||||
value_str[2] = '\0';
|
||||
int value = atoi(value_str);
|
||||
|
||||
FATAL << "Failed to open perf event. "
|
||||
<< "Consider tweaking " << path << " to 2 or less "
|
||||
<< "(current value is " << value << "), "
|
||||
<< "or run coz as a privileged user (with CAP_SYS_ADMIN).";
|
||||
}
|
||||
|
||||
// If sampling, map the perf event file
|
||||
if(pe.sample_type != 0 && pe.sample_period != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user