Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[6893b5]: utils / op_perf_events_checker.c Maximize Restore History

Download this file

op_perf_events_checker.c    71 lines (64 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* @file op-perf-events-checker.c
*
* Utility program for determining the existence and functionality
* of the Linux kernel's Performance Events Subsystem.
*
* @remark Copyright 2011 OProfile authors
* @remark Read the file COPYING
*
* Created on: Dec 7, 2011
* @author Maynard Johnson
* (C) Copyright IBM Corp. 2011
*
*/
#include <sys/types.h>
#include <unistd.h>
#include <asm/unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "config.h"
#if HAVE_PERF_EVENTS
#include <linux/perf_event.h>
struct perf_event_attr attr;
pid_t pid ;
#endif
static void usage(void)
{
fprintf(stderr, "usage: op-check-perfevents [OPTION]\n");
fprintf(stderr, "\t-h, --help\t\tPrint this help message\n");
fprintf(stderr, "\t-v, --verbose\t\tPrint errno value of perf_event_open syscall\n");
}
int main(int argc, char **argv)
{
int _verbose = 0;
if (argc > 1) {
if ((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help"))) {
usage();
return 0;
} else if ((!strcmp(argv[1], "-v")) || (!strcmp(argv[1], "--verbose"))) {
_verbose = 1;
} else {
usage();
return -1;
}
}
#if HAVE_PERF_EVENTS
/* If perf_events syscall is not implemented, the syscall below will fail
* with ENOSYS (38). If implemented, but the processor type on which this
* program is running is not supported by perf_events, the syscall returns
* ENOENT (2).
*/
memset(&attr, 0, sizeof(attr));
attr.size = sizeof(attr);
attr.sample_type = PERF_SAMPLE_IP;
pid = getpid();
syscall(__NR_perf_event_open, &attr, pid, 0, -1, 0);
if (_verbose)
fprintf(stderr, "perf_event_open syscall returned %s\n", strerror(errno));
return errno;
#else
return -1;
#endif
}