2012-11-18 48 views
0

我想为我的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:错误的文件描述符。

回答

0

因为pid == -1和cpu == -1无效。你可以检查它在http://web.eece.maine.edu/~vweaver/projects/perf_events/perf_event_open.html

+0

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

0

你还没有配置“struct perf_event_attr pe;”但是

相关问题