2012-11-18 5 views
0

Android 앱에 __NR_perf_event_open의 syscall을 사용하고 싶습니다.syscall __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;"를 구성하지 않았습니다. 아직

관련 문제