[英]The syscall __NR_perf_event_open seems doesn't work on Android
我想为我的Android应用程序使用__NR_perf_event_open的系统调用。
该代码可以在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:错误的文件描述符。
因为pid == -1和cpu == -1无效。 您可以在http://web.eece.maine.edu/~vweaver/projects/perf_events/perf_event_open.html中进行检查
您尚未配置“ struct perf_event_attr pe;” 然而
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.