我想爲我的Android應用程序使用__NR_perf_event_open的系統調用。系統調用__NR_perf_event_open似乎無法在Android上工作
該代碼在Linux上正常運行,但在Android上不起作用。
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <perf_event.h>
#include <asm/unistd.h>
long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
int cpu, int group_fd, unsigned long flags)
{
int ret;
ret = syscall(__NR_perf_event_open, hw_event, pid, cpu,
group_fd, flags);
return ret;
}
int main() {
//In the main function, I call perf_event_open:
struct perf_event_attr pe;
int fd;
fd = perf_event_open(&pe, 0, -1, -1, 0);
...
}
但是,fd總是返回值-1。當我使用「errno.h」時,它給出了錯誤信息:EBADF:錯誤的文件描述符。
int perf_event_open(struct perf_event_attr * attr,pid_t pid,int cpu,int group_fd,unsigned long flags); 因此 fd = perf_event_open(&pe,0,-1,-1,0) pid = 0 cpu = -1它是有效的組合。 但是,即使是 perf_event_open(&pe,/ * pid */0,/ * cpu */- 1,/ group_id */- 1,PERF_FLAG_PID_CGROUP); 返回errno = 9「錯誤的文件編號」:( – Leo