test perf_event: minor fixes(add signal handling. etc.)
Change-Id: I837d962bcaf13d3a523f80ff77f75b7fd51a98b7
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/perf_event.h>
|
||||
#include <asm/unistd.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
//#include "perftool.h"
|
||||
|
||||
@ -23,6 +25,12 @@ perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
usr1_handler(int signum)
|
||||
{
|
||||
puts("perf counter overflow.");
|
||||
}
|
||||
|
||||
long
|
||||
pe_opener(long group_fd, int mode, int type, unsigned long config)
|
||||
{
|
||||
@ -53,7 +61,23 @@ pe_opener(long group_fd, int mode, int type, unsigned long config)
|
||||
}
|
||||
|
||||
fd = perf_event_open(&pe, 0, -1, group_fd, 0);
|
||||
if (fd != -1) {
|
||||
struct sigaction act = {
|
||||
.sa_handler = usr1_handler,
|
||||
};
|
||||
|
||||
if (sigaction(SIGUSR1, &act, NULL)) {
|
||||
close(fd);
|
||||
fd = -1;
|
||||
};
|
||||
}
|
||||
|
||||
if (fd != -1) {
|
||||
if (fcntl(fd, F_SETSIG, SIGUSR1)) {
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user