Created
March 29, 2011 04:28
-
-
Save chaosgame/891812 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <linux/perf_event.h> | |
#include <asm/unistd.h> | |
#include <sys/ioctl.h> | |
static inline | |
int sys_perf_event_open(struct perf_event_attr *attr, | |
pid_t pid, int cpu, int group_fd, | |
unsigned long flags) | |
{ | |
attr->size = sizeof(*attr); | |
return syscall(__NR_perf_event_open, attr, pid, cpu, | |
group_fd, flags); | |
} | |
static inline | |
void write_pmcnt_register() | |
{ | |
asm volatile ("mcr p15, 0, r0, c9, c13, 2" :: ); | |
} | |
int main() | |
{ | |
struct perf_event_attr attr; | |
memset(&attr, '\0', sizeof(attr)); | |
attr.disabled = 1; | |
attr.type = PERF_TYPE_HARDWARE; | |
attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS; | |
int fd = sys_perf_event_open(&attr, 0, -1, -1, 0); | |
ioctl(fd, PERF_EVENT_IOC_ENABLE); | |
write_pmcnt_register(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment