2012-11-18 46 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;」但是

相關問題