aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/util
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-05-26 03:17:18 -0400
committerIngo Molnar <mingo@elte.hu>2009-05-26 05:59:34 -0400
commit5242519b0296d128425368fc6ab17f541d5fa775 (patch)
tree2fb13c01ff80c4ff0818bdcb2d9d9edfbe244036 /Documentation/perf_counter/util
parent8ad8db3788fd9a449941fb2392ca85af4ee1cde1 (diff)
perf stat: Convert to Git option parsing
Remove getopt usage and use Git's much more advanced and more compact command option library. Extend the event parser library with the extensions that were in perf-stat before. Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: John Kacur <jkacur@redhat.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/util')
-rw-r--r--Documentation/perf_counter/util/parse-events.c82
-rw-r--r--Documentation/perf_counter/util/parse-events.h10
2 files changed, 82 insertions, 10 deletions
diff --git a/Documentation/perf_counter/util/parse-events.c b/Documentation/perf_counter/util/parse-events.c
index 77d0917d55d3..88c903eb260a 100644
--- a/Documentation/perf_counter/util/parse-events.c
+++ b/Documentation/perf_counter/util/parse-events.c
@@ -8,6 +8,7 @@
8int nr_counters; 8int nr_counters;
9 9
10__u64 event_id[MAX_COUNTERS] = { }; 10__u64 event_id[MAX_COUNTERS] = { };
11int event_mask[MAX_COUNTERS];
11 12
12struct event_symbol { 13struct event_symbol {
13 __u64 event; 14 __u64 event;
@@ -37,6 +38,64 @@ static struct event_symbol event_symbols[] = {
37 {EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_MIGRATIONS), "migrations", }, 38 {EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_MIGRATIONS), "migrations", },
38}; 39};
39 40
41#define __PERF_COUNTER_FIELD(config, name) \
42 ((config & PERF_COUNTER_##name##_MASK) >> PERF_COUNTER_##name##_SHIFT)
43
44#define PERF_COUNTER_RAW(config) __PERF_COUNTER_FIELD(config, RAW)
45#define PERF_COUNTER_CONFIG(config) __PERF_COUNTER_FIELD(config, CONFIG)
46#define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE)
47#define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT)
48
49static char *hw_event_names[] = {
50 "CPU cycles",
51 "instructions",
52 "cache references",
53 "cache misses",
54 "branches",
55 "branch misses",
56 "bus cycles",
57};
58
59static char *sw_event_names[] = {
60 "cpu clock ticks",
61 "task clock ticks",
62 "pagefaults",
63 "context switches",
64 "CPU migrations",
65 "minor faults",
66 "major faults",
67};
68
69char *event_name(int ctr)
70{
71 __u64 config = event_id[ctr];
72 int type = PERF_COUNTER_TYPE(config);
73 int id = PERF_COUNTER_ID(config);
74 static char buf[32];
75
76 if (PERF_COUNTER_RAW(config)) {
77 sprintf(buf, "raw 0x%llx", PERF_COUNTER_CONFIG(config));
78 return buf;
79 }
80
81 switch (type) {
82 case PERF_TYPE_HARDWARE:
83 if (id < PERF_HW_EVENTS_MAX)
84 return hw_event_names[id];
85 return "unknown-hardware";
86
87 case PERF_TYPE_SOFTWARE:
88 if (id < PERF_SW_EVENTS_MAX)
89 return sw_event_names[id];
90 return "unknown-software";
91
92 default:
93 break;
94 }
95
96 return "unknown";
97}
98
40/* 99/*
41 * Each event can have multiple symbolic names. 100 * Each event can have multiple symbolic names.
42 * Symbolic names are (almost) exactly matched. 101 * Symbolic names are (almost) exactly matched.
@@ -46,12 +105,23 @@ static __u64 match_event_symbols(const char *str)
46 __u64 config, id; 105 __u64 config, id;
47 int type; 106 int type;
48 unsigned int i; 107 unsigned int i;
108 char mask_str[4];
49 109
50 if (sscanf(str, "r%llx", &config) == 1) 110 if (sscanf(str, "r%llx", &config) == 1)
51 return config | PERF_COUNTER_RAW_MASK; 111 return config | PERF_COUNTER_RAW_MASK;
52 112
53 if (sscanf(str, "%d:%llu", &type, &id) == 2) 113 switch (sscanf(str, "%d:%llu:%2s", &type, &id, mask_str)) {
54 return EID(type, id); 114 case 3:
115 if (strchr(mask_str, 'k'))
116 event_mask[nr_counters] |= EVENT_MASK_USER;
117 if (strchr(mask_str, 'u'))
118 event_mask[nr_counters] |= EVENT_MASK_KERNEL;
119 case 2:
120 return EID(type, id);
121
122 default:
123 break;
124 }
55 125
56 for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { 126 for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
57 if (!strncmp(str, event_symbols[i].symbol, 127 if (!strncmp(str, event_symbols[i].symbol,
@@ -86,14 +156,6 @@ again:
86 return 0; 156 return 0;
87} 157}
88 158
89#define __PERF_COUNTER_FIELD(config, name) \
90 ((config & PERF_COUNTER_##name##_MASK) >> PERF_COUNTER_##name##_SHIFT)
91
92#define PERF_COUNTER_RAW(config) __PERF_COUNTER_FIELD(config, RAW)
93#define PERF_COUNTER_CONFIG(config) __PERF_COUNTER_FIELD(config, CONFIG)
94#define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE)
95#define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT)
96
97/* 159/*
98 * Create the help text for the event symbols: 160 * Create the help text for the event symbols:
99 */ 161 */
diff --git a/Documentation/perf_counter/util/parse-events.h b/Documentation/perf_counter/util/parse-events.h
index 6e2ebe5ff7d7..0da306bb9028 100644
--- a/Documentation/perf_counter/util/parse-events.h
+++ b/Documentation/perf_counter/util/parse-events.h
@@ -1,6 +1,16 @@
1 1
2/*
3 * Parse symbolic events/counts passed in as options:
4 */
5
2extern int nr_counters; 6extern int nr_counters;
3extern __u64 event_id[MAX_COUNTERS]; 7extern __u64 event_id[MAX_COUNTERS];
8extern int event_mask[MAX_COUNTERS];
9
10#define EVENT_MASK_KERNEL 1
11#define EVENT_MASK_USER 2
12
13extern char *event_name(int ctr);
4 14
5extern int parse_events(const struct option *opt, const char *str, int unset); 15extern int parse_events(const struct option *opt, const char *str, int unset);
6 16