diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-20 18:54:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-20 18:54:37 -0400 |
commit | 467f9957d9283be40101d7255d06fae7e211ff4c (patch) | |
tree | 71d155ab52b3a78bc88d0c8088b09b3c37f9357a /tools/perf/util | |
parent | 78f28b7c555359c67c2a0d23f7436e915329421e (diff) | |
parent | cdf8073d6b2c6c5a3cd6ce0e6c1297157f7f99ba (diff) |
Merge branch 'perfcounters-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perfcounters-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (58 commits)
perf_counter: Fix perf_copy_attr() pointer arithmetic
perf utils: Use a define for the maximum length of a trace event
perf: Add timechart help text and add timechart to "perf help"
tracing, x86, cpuidle: Move the end point of a C state in the power tracer
perf utils: Be consistent about minimum text size in the svghelper
perf timechart: Add "perf timechart record"
perf: Add the timechart tool
perf: Add a SVG helper library file
tracing, perf: Convert the power tracer into an event tracer
perf: Add a sample_event type to the event_union
perf: Allow perf utilities to have "callback" options without arguments
perf: Store trace event name/id pairs in perf.data
perf: Add a timestamp to fork events
sched_clock: Make it NMI safe
perf_counter: Fix up swcounter throttling
x86, perf_counter, bts: Optimize BTS overflow handling
perf sched: Add --input=file option to builtin-sched.c
perf trace: Sample timestamp and cpu when using record flag
perf tools: Increase MAX_EVENT_LENGTH
perf tools: Fix memory leak in read_ftrace_printk()
...
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/event.h | 10 | ||||
-rw-r--r-- | tools/perf/util/header.c | 67 | ||||
-rw-r--r-- | tools/perf/util/header.h | 6 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 237 | ||||
-rw-r--r-- | tools/perf/util/parse-options.h | 2 | ||||
-rw-r--r-- | tools/perf/util/svghelper.c | 384 | ||||
-rw-r--r-- | tools/perf/util/svghelper.h | 25 | ||||
-rw-r--r-- | tools/perf/util/thread.c | 4 | ||||
-rw-r--r-- | tools/perf/util/thread.h | 9 | ||||
-rw-r--r-- | tools/perf/util/trace-event-info.c | 7 | ||||
-rw-r--r-- | tools/perf/util/trace-event-parse.c | 45 | ||||
-rw-r--r-- | tools/perf/util/trace-event-read.c | 6 | ||||
-rw-r--r-- | tools/perf/util/trace-event.h | 5 |
13 files changed, 729 insertions, 78 deletions
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index fa2d4e91d329..018d414a09d1 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -39,6 +39,7 @@ struct fork_event { | |||
39 | struct perf_event_header header; | 39 | struct perf_event_header header; |
40 | u32 pid, ppid; | 40 | u32 pid, ppid; |
41 | u32 tid, ptid; | 41 | u32 tid, ptid; |
42 | u64 time; | ||
42 | }; | 43 | }; |
43 | 44 | ||
44 | struct lost_event { | 45 | struct lost_event { |
@@ -52,13 +53,19 @@ struct lost_event { | |||
52 | */ | 53 | */ |
53 | struct read_event { | 54 | struct read_event { |
54 | struct perf_event_header header; | 55 | struct perf_event_header header; |
55 | u32 pid,tid; | 56 | u32 pid, tid; |
56 | u64 value; | 57 | u64 value; |
57 | u64 time_enabled; | 58 | u64 time_enabled; |
58 | u64 time_running; | 59 | u64 time_running; |
59 | u64 id; | 60 | u64 id; |
60 | }; | 61 | }; |
61 | 62 | ||
63 | struct sample_event{ | ||
64 | struct perf_event_header header; | ||
65 | u64 array[]; | ||
66 | }; | ||
67 | |||
68 | |||
62 | typedef union event_union { | 69 | typedef union event_union { |
63 | struct perf_event_header header; | 70 | struct perf_event_header header; |
64 | struct ip_event ip; | 71 | struct ip_event ip; |
@@ -67,6 +74,7 @@ typedef union event_union { | |||
67 | struct fork_event fork; | 74 | struct fork_event fork; |
68 | struct lost_event lost; | 75 | struct lost_event lost; |
69 | struct read_event read; | 76 | struct read_event read; |
77 | struct sample_event sample; | ||
70 | } event_t; | 78 | } event_t; |
71 | 79 | ||
72 | struct map { | 80 | struct map { |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index ec4d4c2f9522..bb4fca3efcc3 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -7,9 +7,8 @@ | |||
7 | #include "header.h" | 7 | #include "header.h" |
8 | 8 | ||
9 | /* | 9 | /* |
10 | * | 10 | * Create new perf.data header attribute: |
11 | */ | 11 | */ |
12 | |||
13 | struct perf_header_attr *perf_header_attr__new(struct perf_counter_attr *attr) | 12 | struct perf_header_attr *perf_header_attr__new(struct perf_counter_attr *attr) |
14 | { | 13 | { |
15 | struct perf_header_attr *self = malloc(sizeof(*self)); | 14 | struct perf_header_attr *self = malloc(sizeof(*self)); |
@@ -43,9 +42,8 @@ void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) | |||
43 | } | 42 | } |
44 | 43 | ||
45 | /* | 44 | /* |
46 | * | 45 | * Create new perf.data header: |
47 | */ | 46 | */ |
48 | |||
49 | struct perf_header *perf_header__new(void) | 47 | struct perf_header *perf_header__new(void) |
50 | { | 48 | { |
51 | struct perf_header *self = malloc(sizeof(*self)); | 49 | struct perf_header *self = malloc(sizeof(*self)); |
@@ -86,6 +84,46 @@ void perf_header__add_attr(struct perf_header *self, | |||
86 | self->attr[pos] = attr; | 84 | self->attr[pos] = attr; |
87 | } | 85 | } |
88 | 86 | ||
87 | #define MAX_EVENT_NAME 64 | ||
88 | |||
89 | struct perf_trace_event_type { | ||
90 | u64 event_id; | ||
91 | char name[MAX_EVENT_NAME]; | ||
92 | }; | ||
93 | |||
94 | static int event_count; | ||
95 | static struct perf_trace_event_type *events; | ||
96 | |||
97 | void perf_header__push_event(u64 id, const char *name) | ||
98 | { | ||
99 | if (strlen(name) > MAX_EVENT_NAME) | ||
100 | printf("Event %s will be truncated\n", name); | ||
101 | |||
102 | if (!events) { | ||
103 | events = malloc(sizeof(struct perf_trace_event_type)); | ||
104 | if (!events) | ||
105 | die("nomem"); | ||
106 | } else { | ||
107 | events = realloc(events, (event_count + 1) * sizeof(struct perf_trace_event_type)); | ||
108 | if (!events) | ||
109 | die("nomem"); | ||
110 | } | ||
111 | memset(&events[event_count], 0, sizeof(struct perf_trace_event_type)); | ||
112 | events[event_count].event_id = id; | ||
113 | strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1); | ||
114 | event_count++; | ||
115 | } | ||
116 | |||
117 | char *perf_header__find_event(u64 id) | ||
118 | { | ||
119 | int i; | ||
120 | for (i = 0 ; i < event_count; i++) { | ||
121 | if (events[i].event_id == id) | ||
122 | return events[i].name; | ||
123 | } | ||
124 | return NULL; | ||
125 | } | ||
126 | |||
89 | static const char *__perf_magic = "PERFFILE"; | 127 | static const char *__perf_magic = "PERFFILE"; |
90 | 128 | ||
91 | #define PERF_MAGIC (*(u64 *)__perf_magic) | 129 | #define PERF_MAGIC (*(u64 *)__perf_magic) |
@@ -106,6 +144,7 @@ struct perf_file_header { | |||
106 | u64 attr_size; | 144 | u64 attr_size; |
107 | struct perf_file_section attrs; | 145 | struct perf_file_section attrs; |
108 | struct perf_file_section data; | 146 | struct perf_file_section data; |
147 | struct perf_file_section event_types; | ||
109 | }; | 148 | }; |
110 | 149 | ||
111 | static void do_write(int fd, void *buf, size_t size) | 150 | static void do_write(int fd, void *buf, size_t size) |
@@ -154,6 +193,11 @@ void perf_header__write(struct perf_header *self, int fd) | |||
154 | do_write(fd, &f_attr, sizeof(f_attr)); | 193 | do_write(fd, &f_attr, sizeof(f_attr)); |
155 | } | 194 | } |
156 | 195 | ||
196 | self->event_offset = lseek(fd, 0, SEEK_CUR); | ||
197 | self->event_size = event_count * sizeof(struct perf_trace_event_type); | ||
198 | if (events) | ||
199 | do_write(fd, events, self->event_size); | ||
200 | |||
157 | 201 | ||
158 | self->data_offset = lseek(fd, 0, SEEK_CUR); | 202 | self->data_offset = lseek(fd, 0, SEEK_CUR); |
159 | 203 | ||
@@ -169,6 +213,10 @@ void perf_header__write(struct perf_header *self, int fd) | |||
169 | .offset = self->data_offset, | 213 | .offset = self->data_offset, |
170 | .size = self->data_size, | 214 | .size = self->data_size, |
171 | }, | 215 | }, |
216 | .event_types = { | ||
217 | .offset = self->event_offset, | ||
218 | .size = self->event_size, | ||
219 | }, | ||
172 | }; | 220 | }; |
173 | 221 | ||
174 | lseek(fd, 0, SEEK_SET); | 222 | lseek(fd, 0, SEEK_SET); |
@@ -234,6 +282,17 @@ struct perf_header *perf_header__read(int fd) | |||
234 | lseek(fd, tmp, SEEK_SET); | 282 | lseek(fd, tmp, SEEK_SET); |
235 | } | 283 | } |
236 | 284 | ||
285 | if (f_header.event_types.size) { | ||
286 | lseek(fd, f_header.event_types.offset, SEEK_SET); | ||
287 | events = malloc(f_header.event_types.size); | ||
288 | if (!events) | ||
289 | die("nomem"); | ||
290 | do_read(fd, events, f_header.event_types.size); | ||
291 | event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); | ||
292 | } | ||
293 | self->event_offset = f_header.event_types.offset; | ||
294 | self->event_size = f_header.event_types.size; | ||
295 | |||
237 | self->data_offset = f_header.data.offset; | 296 | self->data_offset = f_header.data.offset; |
238 | self->data_size = f_header.data.size; | 297 | self->data_size = f_header.data.size; |
239 | 298 | ||
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 5d0a72ecc919..7b0e84a87179 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
@@ -19,6 +19,8 @@ struct perf_header { | |||
19 | s64 attr_offset; | 19 | s64 attr_offset; |
20 | u64 data_offset; | 20 | u64 data_offset; |
21 | u64 data_size; | 21 | u64 data_size; |
22 | u64 event_offset; | ||
23 | u64 event_size; | ||
22 | }; | 24 | }; |
23 | 25 | ||
24 | struct perf_header *perf_header__read(int fd); | 26 | struct perf_header *perf_header__read(int fd); |
@@ -27,6 +29,10 @@ void perf_header__write(struct perf_header *self, int fd); | |||
27 | void perf_header__add_attr(struct perf_header *self, | 29 | void perf_header__add_attr(struct perf_header *self, |
28 | struct perf_header_attr *attr); | 30 | struct perf_header_attr *attr); |
29 | 31 | ||
32 | void perf_header__push_event(u64 id, const char *name); | ||
33 | char *perf_header__find_event(u64 id); | ||
34 | |||
35 | |||
30 | struct perf_header_attr * | 36 | struct perf_header_attr * |
31 | perf_header_attr__new(struct perf_counter_attr *attr); | 37 | perf_header_attr__new(struct perf_counter_attr *attr); |
32 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); | 38 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index a587d41ae3c9..89172fd0038b 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "exec_cmd.h" | 6 | #include "exec_cmd.h" |
7 | #include "string.h" | 7 | #include "string.h" |
8 | #include "cache.h" | 8 | #include "cache.h" |
9 | #include "header.h" | ||
9 | 10 | ||
10 | int nr_counters; | 11 | int nr_counters; |
11 | 12 | ||
@@ -18,6 +19,12 @@ struct event_symbol { | |||
18 | const char *alias; | 19 | const char *alias; |
19 | }; | 20 | }; |
20 | 21 | ||
22 | enum event_result { | ||
23 | EVT_FAILED, | ||
24 | EVT_HANDLED, | ||
25 | EVT_HANDLED_ALL | ||
26 | }; | ||
27 | |||
21 | char debugfs_path[MAXPATHLEN]; | 28 | char debugfs_path[MAXPATHLEN]; |
22 | 29 | ||
23 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x | 30 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x |
@@ -139,7 +146,7 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) | |||
139 | (strcmp(evt_dirent.d_name, "..")) && \ | 146 | (strcmp(evt_dirent.d_name, "..")) && \ |
140 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) | 147 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) |
141 | 148 | ||
142 | #define MAX_EVENT_LENGTH 30 | 149 | #define MAX_EVENT_LENGTH 512 |
143 | 150 | ||
144 | int valid_debugfs_mount(const char *debugfs) | 151 | int valid_debugfs_mount(const char *debugfs) |
145 | { | 152 | { |
@@ -344,7 +351,7 @@ static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int | |||
344 | return -1; | 351 | return -1; |
345 | } | 352 | } |
346 | 353 | ||
347 | static int | 354 | static enum event_result |
348 | parse_generic_hw_event(const char **str, struct perf_counter_attr *attr) | 355 | parse_generic_hw_event(const char **str, struct perf_counter_attr *attr) |
349 | { | 356 | { |
350 | const char *s = *str; | 357 | const char *s = *str; |
@@ -356,7 +363,7 @@ parse_generic_hw_event(const char **str, struct perf_counter_attr *attr) | |||
356 | * then bail out: | 363 | * then bail out: |
357 | */ | 364 | */ |
358 | if (cache_type == -1) | 365 | if (cache_type == -1) |
359 | return 0; | 366 | return EVT_FAILED; |
360 | 367 | ||
361 | while ((cache_op == -1 || cache_result == -1) && *s == '-') { | 368 | while ((cache_op == -1 || cache_result == -1) && *s == '-') { |
362 | ++s; | 369 | ++s; |
@@ -402,27 +409,115 @@ parse_generic_hw_event(const char **str, struct perf_counter_attr *attr) | |||
402 | attr->type = PERF_TYPE_HW_CACHE; | 409 | attr->type = PERF_TYPE_HW_CACHE; |
403 | 410 | ||
404 | *str = s; | 411 | *str = s; |
405 | return 1; | 412 | return EVT_HANDLED; |
413 | } | ||
414 | |||
415 | static enum event_result | ||
416 | parse_single_tracepoint_event(char *sys_name, | ||
417 | const char *evt_name, | ||
418 | unsigned int evt_length, | ||
419 | char *flags, | ||
420 | struct perf_counter_attr *attr, | ||
421 | const char **strp) | ||
422 | { | ||
423 | char evt_path[MAXPATHLEN]; | ||
424 | char id_buf[4]; | ||
425 | u64 id; | ||
426 | int fd; | ||
427 | |||
428 | if (flags) { | ||
429 | if (!strncmp(flags, "record", strlen(flags))) { | ||
430 | attr->sample_type |= PERF_SAMPLE_RAW; | ||
431 | attr->sample_type |= PERF_SAMPLE_TIME; | ||
432 | attr->sample_type |= PERF_SAMPLE_CPU; | ||
433 | } | ||
434 | } | ||
435 | |||
436 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, | ||
437 | sys_name, evt_name); | ||
438 | |||
439 | fd = open(evt_path, O_RDONLY); | ||
440 | if (fd < 0) | ||
441 | return EVT_FAILED; | ||
442 | |||
443 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | ||
444 | close(fd); | ||
445 | return EVT_FAILED; | ||
446 | } | ||
447 | |||
448 | close(fd); | ||
449 | id = atoll(id_buf); | ||
450 | attr->config = id; | ||
451 | attr->type = PERF_TYPE_TRACEPOINT; | ||
452 | *strp = evt_name + evt_length; | ||
453 | |||
454 | return EVT_HANDLED; | ||
455 | } | ||
456 | |||
457 | /* sys + ':' + event + ':' + flags*/ | ||
458 | #define MAX_EVOPT_LEN (MAX_EVENT_LENGTH * 2 + 2 + 128) | ||
459 | static enum event_result | ||
460 | parse_subsystem_tracepoint_event(char *sys_name, char *flags) | ||
461 | { | ||
462 | char evt_path[MAXPATHLEN]; | ||
463 | struct dirent *evt_ent; | ||
464 | DIR *evt_dir; | ||
465 | |||
466 | snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name); | ||
467 | evt_dir = opendir(evt_path); | ||
468 | |||
469 | if (!evt_dir) { | ||
470 | perror("Can't open event dir"); | ||
471 | return EVT_FAILED; | ||
472 | } | ||
473 | |||
474 | while ((evt_ent = readdir(evt_dir))) { | ||
475 | char event_opt[MAX_EVOPT_LEN + 1]; | ||
476 | int len; | ||
477 | unsigned int rem = MAX_EVOPT_LEN; | ||
478 | |||
479 | if (!strcmp(evt_ent->d_name, ".") | ||
480 | || !strcmp(evt_ent->d_name, "..") | ||
481 | || !strcmp(evt_ent->d_name, "enable") | ||
482 | || !strcmp(evt_ent->d_name, "filter")) | ||
483 | continue; | ||
484 | |||
485 | len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s", sys_name, | ||
486 | evt_ent->d_name); | ||
487 | if (len < 0) | ||
488 | return EVT_FAILED; | ||
489 | |||
490 | rem -= len; | ||
491 | if (flags) { | ||
492 | if (rem < strlen(flags) + 1) | ||
493 | return EVT_FAILED; | ||
494 | |||
495 | strcat(event_opt, ":"); | ||
496 | strcat(event_opt, flags); | ||
497 | } | ||
498 | |||
499 | if (parse_events(NULL, event_opt, 0)) | ||
500 | return EVT_FAILED; | ||
501 | } | ||
502 | |||
503 | return EVT_HANDLED_ALL; | ||
406 | } | 504 | } |
407 | 505 | ||
408 | static int parse_tracepoint_event(const char **strp, | 506 | |
507 | static enum event_result parse_tracepoint_event(const char **strp, | ||
409 | struct perf_counter_attr *attr) | 508 | struct perf_counter_attr *attr) |
410 | { | 509 | { |
411 | const char *evt_name; | 510 | const char *evt_name; |
412 | char *flags; | 511 | char *flags; |
413 | char sys_name[MAX_EVENT_LENGTH]; | 512 | char sys_name[MAX_EVENT_LENGTH]; |
414 | char id_buf[4]; | ||
415 | int fd; | ||
416 | unsigned int sys_length, evt_length; | 513 | unsigned int sys_length, evt_length; |
417 | u64 id; | ||
418 | char evt_path[MAXPATHLEN]; | ||
419 | 514 | ||
420 | if (valid_debugfs_mount(debugfs_path)) | 515 | if (valid_debugfs_mount(debugfs_path)) |
421 | return 0; | 516 | return 0; |
422 | 517 | ||
423 | evt_name = strchr(*strp, ':'); | 518 | evt_name = strchr(*strp, ':'); |
424 | if (!evt_name) | 519 | if (!evt_name) |
425 | return 0; | 520 | return EVT_FAILED; |
426 | 521 | ||
427 | sys_length = evt_name - *strp; | 522 | sys_length = evt_name - *strp; |
428 | if (sys_length >= MAX_EVENT_LENGTH) | 523 | if (sys_length >= MAX_EVENT_LENGTH) |
@@ -434,32 +529,22 @@ static int parse_tracepoint_event(const char **strp, | |||
434 | 529 | ||
435 | flags = strchr(evt_name, ':'); | 530 | flags = strchr(evt_name, ':'); |
436 | if (flags) { | 531 | if (flags) { |
437 | *flags = '\0'; | 532 | /* split it out: */ |
533 | evt_name = strndup(evt_name, flags - evt_name); | ||
438 | flags++; | 534 | flags++; |
439 | if (!strncmp(flags, "record", strlen(flags))) | ||
440 | attr->sample_type |= PERF_SAMPLE_RAW; | ||
441 | } | 535 | } |
442 | 536 | ||
443 | evt_length = strlen(evt_name); | 537 | evt_length = strlen(evt_name); |
444 | if (evt_length >= MAX_EVENT_LENGTH) | 538 | if (evt_length >= MAX_EVENT_LENGTH) |
445 | return 0; | 539 | return EVT_FAILED; |
446 | |||
447 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, | ||
448 | sys_name, evt_name); | ||
449 | fd = open(evt_path, O_RDONLY); | ||
450 | if (fd < 0) | ||
451 | return 0; | ||
452 | 540 | ||
453 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | 541 | if (!strcmp(evt_name, "*")) { |
454 | close(fd); | 542 | *strp = evt_name + evt_length; |
455 | return 0; | 543 | return parse_subsystem_tracepoint_event(sys_name, flags); |
456 | } | 544 | } else |
457 | close(fd); | 545 | return parse_single_tracepoint_event(sys_name, evt_name, |
458 | id = atoll(id_buf); | 546 | evt_length, flags, |
459 | attr->config = id; | 547 | attr, strp); |
460 | attr->type = PERF_TYPE_TRACEPOINT; | ||
461 | *strp = evt_name + evt_length; | ||
462 | return 1; | ||
463 | } | 548 | } |
464 | 549 | ||
465 | static int check_events(const char *str, unsigned int i) | 550 | static int check_events(const char *str, unsigned int i) |
@@ -477,7 +562,7 @@ static int check_events(const char *str, unsigned int i) | |||
477 | return 0; | 562 | return 0; |
478 | } | 563 | } |
479 | 564 | ||
480 | static int | 565 | static enum event_result |
481 | parse_symbolic_event(const char **strp, struct perf_counter_attr *attr) | 566 | parse_symbolic_event(const char **strp, struct perf_counter_attr *attr) |
482 | { | 567 | { |
483 | const char *str = *strp; | 568 | const char *str = *strp; |
@@ -490,31 +575,32 @@ parse_symbolic_event(const char **strp, struct perf_counter_attr *attr) | |||
490 | attr->type = event_symbols[i].type; | 575 | attr->type = event_symbols[i].type; |
491 | attr->config = event_symbols[i].config; | 576 | attr->config = event_symbols[i].config; |
492 | *strp = str + n; | 577 | *strp = str + n; |
493 | return 1; | 578 | return EVT_HANDLED; |
494 | } | 579 | } |
495 | } | 580 | } |
496 | return 0; | 581 | return EVT_FAILED; |
497 | } | 582 | } |
498 | 583 | ||
499 | static int parse_raw_event(const char **strp, struct perf_counter_attr *attr) | 584 | static enum event_result |
585 | parse_raw_event(const char **strp, struct perf_counter_attr *attr) | ||
500 | { | 586 | { |
501 | const char *str = *strp; | 587 | const char *str = *strp; |
502 | u64 config; | 588 | u64 config; |
503 | int n; | 589 | int n; |
504 | 590 | ||
505 | if (*str != 'r') | 591 | if (*str != 'r') |
506 | return 0; | 592 | return EVT_FAILED; |
507 | n = hex2u64(str + 1, &config); | 593 | n = hex2u64(str + 1, &config); |
508 | if (n > 0) { | 594 | if (n > 0) { |
509 | *strp = str + n + 1; | 595 | *strp = str + n + 1; |
510 | attr->type = PERF_TYPE_RAW; | 596 | attr->type = PERF_TYPE_RAW; |
511 | attr->config = config; | 597 | attr->config = config; |
512 | return 1; | 598 | return EVT_HANDLED; |
513 | } | 599 | } |
514 | return 0; | 600 | return EVT_FAILED; |
515 | } | 601 | } |
516 | 602 | ||
517 | static int | 603 | static enum event_result |
518 | parse_numeric_event(const char **strp, struct perf_counter_attr *attr) | 604 | parse_numeric_event(const char **strp, struct perf_counter_attr *attr) |
519 | { | 605 | { |
520 | const char *str = *strp; | 606 | const char *str = *strp; |
@@ -530,13 +616,13 @@ parse_numeric_event(const char **strp, struct perf_counter_attr *attr) | |||
530 | attr->type = type; | 616 | attr->type = type; |
531 | attr->config = config; | 617 | attr->config = config; |
532 | *strp = endp; | 618 | *strp = endp; |
533 | return 1; | 619 | return EVT_HANDLED; |
534 | } | 620 | } |
535 | } | 621 | } |
536 | return 0; | 622 | return EVT_FAILED; |
537 | } | 623 | } |
538 | 624 | ||
539 | static int | 625 | static enum event_result |
540 | parse_event_modifier(const char **strp, struct perf_counter_attr *attr) | 626 | parse_event_modifier(const char **strp, struct perf_counter_attr *attr) |
541 | { | 627 | { |
542 | const char *str = *strp; | 628 | const char *str = *strp; |
@@ -569,37 +655,84 @@ parse_event_modifier(const char **strp, struct perf_counter_attr *attr) | |||
569 | * Each event can have multiple symbolic names. | 655 | * Each event can have multiple symbolic names. |
570 | * Symbolic names are (almost) exactly matched. | 656 | * Symbolic names are (almost) exactly matched. |
571 | */ | 657 | */ |
572 | static int parse_event_symbols(const char **str, struct perf_counter_attr *attr) | 658 | static enum event_result |
659 | parse_event_symbols(const char **str, struct perf_counter_attr *attr) | ||
573 | { | 660 | { |
574 | if (!(parse_tracepoint_event(str, attr) || | 661 | enum event_result ret; |
575 | parse_raw_event(str, attr) || | 662 | |
576 | parse_numeric_event(str, attr) || | 663 | ret = parse_tracepoint_event(str, attr); |
577 | parse_symbolic_event(str, attr) || | 664 | if (ret != EVT_FAILED) |
578 | parse_generic_hw_event(str, attr))) | 665 | goto modifier; |
579 | return 0; | 666 | |
667 | ret = parse_raw_event(str, attr); | ||
668 | if (ret != EVT_FAILED) | ||
669 | goto modifier; | ||
670 | |||
671 | ret = parse_numeric_event(str, attr); | ||
672 | if (ret != EVT_FAILED) | ||
673 | goto modifier; | ||
674 | |||
675 | ret = parse_symbolic_event(str, attr); | ||
676 | if (ret != EVT_FAILED) | ||
677 | goto modifier; | ||
580 | 678 | ||
679 | ret = parse_generic_hw_event(str, attr); | ||
680 | if (ret != EVT_FAILED) | ||
681 | goto modifier; | ||
682 | |||
683 | return EVT_FAILED; | ||
684 | |||
685 | modifier: | ||
581 | parse_event_modifier(str, attr); | 686 | parse_event_modifier(str, attr); |
582 | 687 | ||
583 | return 1; | 688 | return ret; |
584 | } | 689 | } |
585 | 690 | ||
691 | static void store_event_type(const char *orgname) | ||
692 | { | ||
693 | char filename[PATH_MAX], *c; | ||
694 | FILE *file; | ||
695 | int id; | ||
696 | |||
697 | sprintf(filename, "/sys/kernel/debug/tracing/events/%s/id", orgname); | ||
698 | c = strchr(filename, ':'); | ||
699 | if (c) | ||
700 | *c = '/'; | ||
701 | |||
702 | file = fopen(filename, "r"); | ||
703 | if (!file) | ||
704 | return; | ||
705 | if (fscanf(file, "%i", &id) < 1) | ||
706 | die("cannot store event ID"); | ||
707 | fclose(file); | ||
708 | perf_header__push_event(id, orgname); | ||
709 | } | ||
710 | |||
711 | |||
586 | int parse_events(const struct option *opt __used, const char *str, int unset __used) | 712 | int parse_events(const struct option *opt __used, const char *str, int unset __used) |
587 | { | 713 | { |
588 | struct perf_counter_attr attr; | 714 | struct perf_counter_attr attr; |
715 | enum event_result ret; | ||
716 | |||
717 | if (strchr(str, ':')) | ||
718 | store_event_type(str); | ||
589 | 719 | ||
590 | for (;;) { | 720 | for (;;) { |
591 | if (nr_counters == MAX_COUNTERS) | 721 | if (nr_counters == MAX_COUNTERS) |
592 | return -1; | 722 | return -1; |
593 | 723 | ||
594 | memset(&attr, 0, sizeof(attr)); | 724 | memset(&attr, 0, sizeof(attr)); |
595 | if (!parse_event_symbols(&str, &attr)) | 725 | ret = parse_event_symbols(&str, &attr); |
726 | if (ret == EVT_FAILED) | ||
596 | return -1; | 727 | return -1; |
597 | 728 | ||
598 | if (!(*str == 0 || *str == ',' || isspace(*str))) | 729 | if (!(*str == 0 || *str == ',' || isspace(*str))) |
599 | return -1; | 730 | return -1; |
600 | 731 | ||
601 | attrs[nr_counters] = attr; | 732 | if (ret != EVT_HANDLED_ALL) { |
602 | nr_counters++; | 733 | attrs[nr_counters] = attr; |
734 | nr_counters++; | ||
735 | } | ||
603 | 736 | ||
604 | if (*str == 0) | 737 | if (*str == 0) |
605 | break; | 738 | break; |
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index 8aa3464c7090..2ee248ff27e5 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h | |||
@@ -104,6 +104,8 @@ struct option { | |||
104 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } | 104 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } |
105 | #define OPT_CALLBACK(s, l, v, a, h, f) \ | 105 | #define OPT_CALLBACK(s, l, v, a, h, f) \ |
106 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f) } | 106 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f) } |
107 | #define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \ | ||
108 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG } | ||
107 | #define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \ | 109 | #define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \ |
108 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d, .flags = PARSE_OPT_LASTARG_DEFAULT } | 110 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d, .flags = PARSE_OPT_LASTARG_DEFAULT } |
109 | 111 | ||
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c new file mode 100644 index 000000000000..b0fcecdf378d --- /dev/null +++ b/tools/perf/util/svghelper.c | |||
@@ -0,0 +1,384 @@ | |||
1 | /* | ||
2 | * svghelper.c - helper functions for outputting svg | ||
3 | * | ||
4 | * (C) Copyright 2009 Intel Corporation | ||
5 | * | ||
6 | * Authors: | ||
7 | * Arjan van de Ven <arjan@linux.intel.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; version 2 | ||
12 | * of the License. | ||
13 | */ | ||
14 | |||
15 | #include <stdio.h> | ||
16 | #include <stdlib.h> | ||
17 | #include <unistd.h> | ||
18 | #include <string.h> | ||
19 | |||
20 | #include "svghelper.h" | ||
21 | |||
22 | static u64 first_time, last_time; | ||
23 | static u64 turbo_frequency, max_freq; | ||
24 | |||
25 | |||
26 | #define SLOT_MULT 30.0 | ||
27 | #define SLOT_HEIGHT 25.0 | ||
28 | #define WIDTH 1000.0 | ||
29 | |||
30 | #define MIN_TEXT_SIZE 0.001 | ||
31 | |||
32 | static u64 total_height; | ||
33 | static FILE *svgfile; | ||
34 | |||
35 | static double cpu2slot(int cpu) | ||
36 | { | ||
37 | return 2 * cpu + 1; | ||
38 | } | ||
39 | |||
40 | static double cpu2y(int cpu) | ||
41 | { | ||
42 | return cpu2slot(cpu) * SLOT_MULT; | ||
43 | } | ||
44 | |||
45 | static double time2pixels(u64 time) | ||
46 | { | ||
47 | double X; | ||
48 | |||
49 | X = WIDTH * (time - first_time) / (last_time - first_time); | ||
50 | return X; | ||
51 | } | ||
52 | |||
53 | void open_svg(const char *filename, int cpus, int rows) | ||
54 | { | ||
55 | |||
56 | svgfile = fopen(filename, "w"); | ||
57 | if (!svgfile) { | ||
58 | fprintf(stderr, "Cannot open %s for output\n", filename); | ||
59 | return; | ||
60 | } | ||
61 | total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT; | ||
62 | fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n"); | ||
63 | fprintf(svgfile, "<svg width=\"%4.1f\" height=\"%llu\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", WIDTH, total_height); | ||
64 | |||
65 | fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n"); | ||
66 | |||
67 | fprintf(svgfile, " rect { stroke-width: 1; }\n"); | ||
68 | fprintf(svgfile, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n"); | ||
69 | fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | ||
70 | fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | ||
71 | fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | ||
72 | fprintf(svgfile, " rect.waiting { fill:rgb(255,255, 0); fill-opacity:0.3; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | ||
73 | fprintf(svgfile, " rect.cpu { fill:rgb(192,192,192); fill-opacity:0.2; stroke-width:0.5; stroke:rgb(128,128,128); } \n"); | ||
74 | fprintf(svgfile, " rect.pstate { fill:rgb(128,128,128); fill-opacity:0.8; stroke-width:0; } \n"); | ||
75 | fprintf(svgfile, " rect.c1 { fill:rgb(255,214,214); fill-opacity:0.5; stroke-width:0; } \n"); | ||
76 | fprintf(svgfile, " rect.c2 { fill:rgb(255,172,172); fill-opacity:0.5; stroke-width:0; } \n"); | ||
77 | fprintf(svgfile, " rect.c3 { fill:rgb(255,130,130); fill-opacity:0.5; stroke-width:0; } \n"); | ||
78 | fprintf(svgfile, " rect.c4 { fill:rgb(255, 88, 88); fill-opacity:0.5; stroke-width:0; } \n"); | ||
79 | fprintf(svgfile, " rect.c5 { fill:rgb(255, 44, 44); fill-opacity:0.5; stroke-width:0; } \n"); | ||
80 | fprintf(svgfile, " rect.c6 { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; } \n"); | ||
81 | fprintf(svgfile, " line.pstate { stroke:rgb(255,255, 0); stroke-opacity:0.8; stroke-width:2; } \n"); | ||
82 | |||
83 | fprintf(svgfile, " ]]>\n </style>\n</defs>\n"); | ||
84 | } | ||
85 | |||
86 | void svg_box(int Yslot, u64 start, u64 end, const char *type) | ||
87 | { | ||
88 | if (!svgfile) | ||
89 | return; | ||
90 | |||
91 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", | ||
92 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); | ||
93 | } | ||
94 | |||
95 | void svg_sample(int Yslot, int cpu, u64 start, u64 end, const char *type) | ||
96 | { | ||
97 | double text_size; | ||
98 | if (!svgfile) | ||
99 | return; | ||
100 | |||
101 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", | ||
102 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); | ||
103 | |||
104 | text_size = (time2pixels(end)-time2pixels(start)); | ||
105 | if (cpu > 9) | ||
106 | text_size = text_size/2; | ||
107 | if (text_size > 1.25) | ||
108 | text_size = 1.25; | ||
109 | if (text_size > MIN_TEXT_SIZE) | ||
110 | fprintf(svgfile, "<text transform=\"translate(%1.8f,%1.8f)\" font-size=\"%1.6fpt\">%i</text>\n", | ||
111 | time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1); | ||
112 | |||
113 | } | ||
114 | |||
115 | static char *cpu_model(void) | ||
116 | { | ||
117 | static char cpu_m[255]; | ||
118 | char buf[256]; | ||
119 | FILE *file; | ||
120 | |||
121 | cpu_m[0] = 0; | ||
122 | /* CPU type */ | ||
123 | file = fopen("/proc/cpuinfo", "r"); | ||
124 | if (file) { | ||
125 | while (fgets(buf, 255, file)) { | ||
126 | if (strstr(buf, "model name")) { | ||
127 | strncpy(cpu_m, &buf[13], 255); | ||
128 | break; | ||
129 | } | ||
130 | } | ||
131 | fclose(file); | ||
132 | } | ||
133 | return cpu_m; | ||
134 | } | ||
135 | |||
136 | void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq) | ||
137 | { | ||
138 | char cpu_string[80]; | ||
139 | if (!svgfile) | ||
140 | return; | ||
141 | |||
142 | max_freq = __max_freq; | ||
143 | turbo_frequency = __turbo_freq; | ||
144 | |||
145 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"cpu\"/>\n", | ||
146 | time2pixels(first_time), | ||
147 | time2pixels(last_time)-time2pixels(first_time), | ||
148 | cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); | ||
149 | |||
150 | sprintf(cpu_string, "CPU %i", (int)cpu+1); | ||
151 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\">%s</text>\n", | ||
152 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); | ||
153 | |||
154 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n", | ||
155 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model()); | ||
156 | } | ||
157 | |||
158 | void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name) | ||
159 | { | ||
160 | double width; | ||
161 | |||
162 | if (!svgfile) | ||
163 | return; | ||
164 | |||
165 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", | ||
166 | time2pixels(start), time2pixels(end)-time2pixels(start), cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT, type); | ||
167 | width = time2pixels(end)-time2pixels(start); | ||
168 | if (width > 6) | ||
169 | width = 6; | ||
170 | |||
171 | if (width > MIN_TEXT_SIZE) | ||
172 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"%3.4fpt\">%s</text>\n", | ||
173 | time2pixels(start), cpu2y(cpu), width, name); | ||
174 | } | ||
175 | |||
176 | void svg_cstate(int cpu, u64 start, u64 end, int type) | ||
177 | { | ||
178 | double width; | ||
179 | char style[128]; | ||
180 | |||
181 | if (!svgfile) | ||
182 | return; | ||
183 | |||
184 | |||
185 | if (type > 6) | ||
186 | type = 6; | ||
187 | sprintf(style, "c%i", type); | ||
188 | |||
189 | fprintf(svgfile, "<rect class=\"%s\" x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\"/>\n", | ||
190 | style, | ||
191 | time2pixels(start), time2pixels(end)-time2pixels(start), | ||
192 | cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); | ||
193 | |||
194 | width = time2pixels(end)-time2pixels(start); | ||
195 | if (width > 6) | ||
196 | width = 6; | ||
197 | |||
198 | if (width > MIN_TEXT_SIZE) | ||
199 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"%3.4fpt\">C%i</text>\n", | ||
200 | time2pixels(start), cpu2y(cpu), width, type); | ||
201 | } | ||
202 | |||
203 | static char *HzToHuman(unsigned long hz) | ||
204 | { | ||
205 | static char buffer[1024]; | ||
206 | unsigned long long Hz; | ||
207 | |||
208 | memset(buffer, 0, 1024); | ||
209 | |||
210 | Hz = hz; | ||
211 | |||
212 | /* default: just put the Number in */ | ||
213 | sprintf(buffer, "%9lli", Hz); | ||
214 | |||
215 | if (Hz > 1000) | ||
216 | sprintf(buffer, " %6lli Mhz", (Hz+500)/1000); | ||
217 | |||
218 | if (Hz > 1500000) | ||
219 | sprintf(buffer, " %6.2f Ghz", (Hz+5000.0)/1000000); | ||
220 | |||
221 | if (Hz == turbo_frequency) | ||
222 | sprintf(buffer, "Turbo"); | ||
223 | |||
224 | return buffer; | ||
225 | } | ||
226 | |||
227 | void svg_pstate(int cpu, u64 start, u64 end, u64 freq) | ||
228 | { | ||
229 | double height = 0; | ||
230 | |||
231 | if (!svgfile) | ||
232 | return; | ||
233 | |||
234 | if (max_freq) | ||
235 | height = freq * 1.0 / max_freq * (SLOT_HEIGHT + SLOT_MULT); | ||
236 | height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height; | ||
237 | fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n", | ||
238 | time2pixels(start), time2pixels(end), height, height); | ||
239 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"0.25pt\">%s</text>\n", | ||
240 | time2pixels(start), height+0.9, HzToHuman(freq)); | ||
241 | |||
242 | } | ||
243 | |||
244 | |||
245 | void svg_partial_wakeline(u64 start, int row1, int row2) | ||
246 | { | ||
247 | double height; | ||
248 | |||
249 | if (!svgfile) | ||
250 | return; | ||
251 | |||
252 | |||
253 | if (row1 < row2) { | ||
254 | if (row1) | ||
255 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | ||
256 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); | ||
257 | |||
258 | if (row2) | ||
259 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | ||
260 | time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT); | ||
261 | } else { | ||
262 | if (row2) | ||
263 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | ||
264 | time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); | ||
265 | |||
266 | if (row1) | ||
267 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | ||
268 | time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT); | ||
269 | } | ||
270 | height = row1 * SLOT_MULT; | ||
271 | if (row2 > row1) | ||
272 | height += SLOT_HEIGHT; | ||
273 | if (row1) | ||
274 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", | ||
275 | time2pixels(start), height); | ||
276 | } | ||
277 | |||
278 | void svg_wakeline(u64 start, int row1, int row2) | ||
279 | { | ||
280 | double height; | ||
281 | |||
282 | if (!svgfile) | ||
283 | return; | ||
284 | |||
285 | |||
286 | if (row1 < row2) | ||
287 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | ||
288 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT); | ||
289 | else | ||
290 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | ||
291 | time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT); | ||
292 | |||
293 | height = row1 * SLOT_MULT; | ||
294 | if (row2 > row1) | ||
295 | height += SLOT_HEIGHT; | ||
296 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", | ||
297 | time2pixels(start), height); | ||
298 | } | ||
299 | |||
300 | void svg_interrupt(u64 start, int row) | ||
301 | { | ||
302 | if (!svgfile) | ||
303 | return; | ||
304 | |||
305 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", | ||
306 | time2pixels(start), row * SLOT_MULT); | ||
307 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", | ||
308 | time2pixels(start), row * SLOT_MULT + SLOT_HEIGHT); | ||
309 | } | ||
310 | |||
311 | void svg_text(int Yslot, u64 start, const char *text) | ||
312 | { | ||
313 | if (!svgfile) | ||
314 | return; | ||
315 | |||
316 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\">%s</text>\n", | ||
317 | time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text); | ||
318 | } | ||
319 | |||
320 | static void svg_legenda_box(int X, const char *text, const char *style) | ||
321 | { | ||
322 | double boxsize; | ||
323 | boxsize = SLOT_HEIGHT / 2; | ||
324 | |||
325 | fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", | ||
326 | X, boxsize, boxsize, style); | ||
327 | fprintf(svgfile, "<text transform=\"translate(%4.8f, %4.8f)\" font-size=\"%4.4fpt\">%s</text>\n", | ||
328 | X + boxsize + 5, boxsize, 0.8 * boxsize, text); | ||
329 | } | ||
330 | |||
331 | void svg_legenda(void) | ||
332 | { | ||
333 | if (!svgfile) | ||
334 | return; | ||
335 | |||
336 | svg_legenda_box(0, "Running", "sample"); | ||
337 | svg_legenda_box(100, "Idle","rect.c1"); | ||
338 | svg_legenda_box(200, "Deeper Idle", "rect.c3"); | ||
339 | svg_legenda_box(350, "Deepest Idle", "rect.c6"); | ||
340 | svg_legenda_box(550, "Sleeping", "process2"); | ||
341 | svg_legenda_box(650, "Waiting for cpu", "waiting"); | ||
342 | svg_legenda_box(800, "Blocked on IO", "blocked"); | ||
343 | } | ||
344 | |||
345 | void svg_time_grid(u64 start, u64 end) | ||
346 | { | ||
347 | u64 i; | ||
348 | |||
349 | first_time = start; | ||
350 | last_time = end; | ||
351 | |||
352 | first_time = first_time / 100000000 * 100000000; | ||
353 | |||
354 | if (!svgfile) | ||
355 | return; | ||
356 | |||
357 | i = first_time; | ||
358 | while (i < last_time) { | ||
359 | int color = 220; | ||
360 | double thickness = 0.075; | ||
361 | if ((i % 100000000) == 0) { | ||
362 | thickness = 0.5; | ||
363 | color = 192; | ||
364 | } | ||
365 | if ((i % 1000000000) == 0) { | ||
366 | thickness = 2.0; | ||
367 | color = 128; | ||
368 | } | ||
369 | |||
370 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%llu\" style=\"stroke:rgb(%i,%i,%i);stroke-width:%1.3f\"/>\n", | ||
371 | time2pixels(i), SLOT_MULT/2, time2pixels(i), total_height, color, color, color, thickness); | ||
372 | |||
373 | i += 10000000; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | void svg_close(void) | ||
378 | { | ||
379 | if (svgfile) { | ||
380 | fprintf(svgfile, "</svg>\n"); | ||
381 | fclose(svgfile); | ||
382 | svgfile = NULL; | ||
383 | } | ||
384 | } | ||
diff --git a/tools/perf/util/svghelper.h b/tools/perf/util/svghelper.h new file mode 100644 index 000000000000..ad79b5dc53de --- /dev/null +++ b/tools/perf/util/svghelper.h | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef _INCLUDE_GUARD_SVG_HELPER_ | ||
2 | #define _INCLUDE_GUARD_SVG_HELPER_ | ||
3 | |||
4 | #include "types.h" | ||
5 | |||
6 | extern void open_svg(const char *filename, int cpus, int rows); | ||
7 | extern void svg_box(int Yslot, u64 start, u64 end, const char *type); | ||
8 | extern void svg_sample(int Yslot, int cpu, u64 start, u64 end, const char *type); | ||
9 | extern void svg_cpu_box(int cpu, u64 max_frequency, u64 turbo_frequency); | ||
10 | |||
11 | |||
12 | extern void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name); | ||
13 | extern void svg_cstate(int cpu, u64 start, u64 end, int type); | ||
14 | extern void svg_pstate(int cpu, u64 start, u64 end, u64 freq); | ||
15 | |||
16 | |||
17 | extern void svg_time_grid(u64 start, u64 end); | ||
18 | extern void svg_legenda(void); | ||
19 | extern void svg_wakeline(u64 start, int row1, int row2); | ||
20 | extern void svg_partial_wakeline(u64 start, int row1, int row2); | ||
21 | extern void svg_interrupt(u64 start, int row); | ||
22 | extern void svg_text(int Yslot, u64 start, const char *text); | ||
23 | extern void svg_close(void); | ||
24 | |||
25 | #endif | ||
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 7635928ca278..45efb5db0d19 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
@@ -8,7 +8,7 @@ | |||
8 | 8 | ||
9 | static struct thread *thread__new(pid_t pid) | 9 | static struct thread *thread__new(pid_t pid) |
10 | { | 10 | { |
11 | struct thread *self = malloc(sizeof(*self)); | 11 | struct thread *self = calloc(1, sizeof(*self)); |
12 | 12 | ||
13 | if (self != NULL) { | 13 | if (self != NULL) { |
14 | self->pid = pid; | 14 | self->pid = pid; |
@@ -85,7 +85,7 @@ register_idle_thread(struct rb_root *threads, struct thread **last_match) | |||
85 | { | 85 | { |
86 | struct thread *thread = threads__findnew(0, threads, last_match); | 86 | struct thread *thread = threads__findnew(0, threads, last_match); |
87 | 87 | ||
88 | if (!thread || thread__set_comm(thread, "[init]")) { | 88 | if (!thread || thread__set_comm(thread, "swapper")) { |
89 | fprintf(stderr, "problem inserting idle task.\n"); | 89 | fprintf(stderr, "problem inserting idle task.\n"); |
90 | exit(-1); | 90 | exit(-1); |
91 | } | 91 | } |
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 634f2809a342..32aea3c1c2ad 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
@@ -4,10 +4,11 @@ | |||
4 | #include "symbol.h" | 4 | #include "symbol.h" |
5 | 5 | ||
6 | struct thread { | 6 | struct thread { |
7 | struct rb_node rb_node; | 7 | struct rb_node rb_node; |
8 | struct list_head maps; | 8 | struct list_head maps; |
9 | pid_t pid; | 9 | pid_t pid; |
10 | char *comm; | 10 | char shortname[3]; |
11 | char *comm; | ||
11 | }; | 12 | }; |
12 | 13 | ||
13 | int thread__set_comm(struct thread *self, const char *comm); | 14 | int thread__set_comm(struct thread *self, const char *comm); |
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c index 6c9302a7274c..1fd824c1f1c4 100644 --- a/tools/perf/util/trace-event-info.c +++ b/tools/perf/util/trace-event-info.c | |||
@@ -458,7 +458,7 @@ static void read_proc_kallsyms(void) | |||
458 | static void read_ftrace_printk(void) | 458 | static void read_ftrace_printk(void) |
459 | { | 459 | { |
460 | unsigned int size, check_size; | 460 | unsigned int size, check_size; |
461 | const char *path; | 461 | char *path; |
462 | struct stat st; | 462 | struct stat st; |
463 | int ret; | 463 | int ret; |
464 | 464 | ||
@@ -468,14 +468,15 @@ static void read_ftrace_printk(void) | |||
468 | /* not found */ | 468 | /* not found */ |
469 | size = 0; | 469 | size = 0; |
470 | write_or_die(&size, 4); | 470 | write_or_die(&size, 4); |
471 | return; | 471 | goto out; |
472 | } | 472 | } |
473 | size = get_size(path); | 473 | size = get_size(path); |
474 | write_or_die(&size, 4); | 474 | write_or_die(&size, 4); |
475 | check_size = copy_file(path); | 475 | check_size = copy_file(path); |
476 | if (size != check_size) | 476 | if (size != check_size) |
477 | die("error in size of file '%s'", path); | 477 | die("error in size of file '%s'", path); |
478 | 478 | out: | |
479 | put_tracing_file(path); | ||
479 | } | 480 | } |
480 | 481 | ||
481 | static struct tracepoint_path * | 482 | static struct tracepoint_path * |
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index 629e602d9405..f6a8437141c8 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
@@ -1776,6 +1776,29 @@ static unsigned long long read_size(void *ptr, int size) | |||
1776 | } | 1776 | } |
1777 | } | 1777 | } |
1778 | 1778 | ||
1779 | unsigned long long | ||
1780 | raw_field_value(struct event *event, const char *name, void *data) | ||
1781 | { | ||
1782 | struct format_field *field; | ||
1783 | |||
1784 | field = find_any_field(event, name); | ||
1785 | if (!field) | ||
1786 | return 0ULL; | ||
1787 | |||
1788 | return read_size(data + field->offset, field->size); | ||
1789 | } | ||
1790 | |||
1791 | void *raw_field_ptr(struct event *event, const char *name, void *data) | ||
1792 | { | ||
1793 | struct format_field *field; | ||
1794 | |||
1795 | field = find_any_field(event, name); | ||
1796 | if (!field) | ||
1797 | return NULL; | ||
1798 | |||
1799 | return data + field->offset; | ||
1800 | } | ||
1801 | |||
1779 | static int get_common_info(const char *type, int *offset, int *size) | 1802 | static int get_common_info(const char *type, int *offset, int *size) |
1780 | { | 1803 | { |
1781 | struct event *event; | 1804 | struct event *event; |
@@ -1799,7 +1822,7 @@ static int get_common_info(const char *type, int *offset, int *size) | |||
1799 | return 0; | 1822 | return 0; |
1800 | } | 1823 | } |
1801 | 1824 | ||
1802 | static int parse_common_type(void *data) | 1825 | int trace_parse_common_type(void *data) |
1803 | { | 1826 | { |
1804 | static int type_offset; | 1827 | static int type_offset; |
1805 | static int type_size; | 1828 | static int type_size; |
@@ -1832,7 +1855,7 @@ static int parse_common_pid(void *data) | |||
1832 | return read_size(data + pid_offset, pid_size); | 1855 | return read_size(data + pid_offset, pid_size); |
1833 | } | 1856 | } |
1834 | 1857 | ||
1835 | static struct event *find_event(int id) | 1858 | struct event *trace_find_event(int id) |
1836 | { | 1859 | { |
1837 | struct event *event; | 1860 | struct event *event; |
1838 | 1861 | ||
@@ -2420,8 +2443,8 @@ get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func, | |||
2420 | int type; | 2443 | int type; |
2421 | int pid; | 2444 | int pid; |
2422 | 2445 | ||
2423 | type = parse_common_type(next->data); | 2446 | type = trace_parse_common_type(next->data); |
2424 | event = find_event(type); | 2447 | event = trace_find_event(type); |
2425 | if (!event) | 2448 | if (!event) |
2426 | return NULL; | 2449 | return NULL; |
2427 | 2450 | ||
@@ -2502,8 +2525,8 @@ print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec) | |||
2502 | int type; | 2525 | int type; |
2503 | int i; | 2526 | int i; |
2504 | 2527 | ||
2505 | type = parse_common_type(ret_rec->data); | 2528 | type = trace_parse_common_type(ret_rec->data); |
2506 | ret_event = find_event(type); | 2529 | ret_event = trace_find_event(type); |
2507 | 2530 | ||
2508 | field = find_field(ret_event, "rettime"); | 2531 | field = find_field(ret_event, "rettime"); |
2509 | if (!field) | 2532 | if (!field) |
@@ -2696,11 +2719,13 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs, | |||
2696 | nsecs -= secs * NSECS_PER_SEC; | 2719 | nsecs -= secs * NSECS_PER_SEC; |
2697 | usecs = nsecs / NSECS_PER_USEC; | 2720 | usecs = nsecs / NSECS_PER_USEC; |
2698 | 2721 | ||
2699 | type = parse_common_type(data); | 2722 | type = trace_parse_common_type(data); |
2700 | 2723 | ||
2701 | event = find_event(type); | 2724 | event = trace_find_event(type); |
2702 | if (!event) | 2725 | if (!event) { |
2703 | die("ug! no event found for type %d", type); | 2726 | printf("ug! no event found for type %d\n", type); |
2727 | return; | ||
2728 | } | ||
2704 | 2729 | ||
2705 | pid = parse_common_pid(data); | 2730 | pid = parse_common_pid(data); |
2706 | 2731 | ||
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index a1217a10632f..1b5c847d2c22 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c | |||
@@ -458,12 +458,13 @@ struct record *trace_read_data(int cpu) | |||
458 | return data; | 458 | return data; |
459 | } | 459 | } |
460 | 460 | ||
461 | void trace_report (void) | 461 | void trace_report(void) |
462 | { | 462 | { |
463 | const char *input_file = "trace.info"; | 463 | const char *input_file = "trace.info"; |
464 | char buf[BUFSIZ]; | 464 | char buf[BUFSIZ]; |
465 | char test[] = { 23, 8, 68 }; | 465 | char test[] = { 23, 8, 68 }; |
466 | char *version; | 466 | char *version; |
467 | int show_version = 0; | ||
467 | int show_funcs = 0; | 468 | int show_funcs = 0; |
468 | int show_printk = 0; | 469 | int show_printk = 0; |
469 | 470 | ||
@@ -480,7 +481,8 @@ void trace_report (void) | |||
480 | die("not a trace file (missing tracing)"); | 481 | die("not a trace file (missing tracing)"); |
481 | 482 | ||
482 | version = read_string(); | 483 | version = read_string(); |
483 | printf("version = %s\n", version); | 484 | if (show_version) |
485 | printf("version = %s\n", version); | ||
484 | free(version); | 486 | free(version); |
485 | 487 | ||
486 | read_or_die(buf, 1); | 488 | read_or_die(buf, 1); |
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 420294a5773e..d35ebf1e29ff 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
@@ -234,6 +234,11 @@ extern int header_page_data_offset; | |||
234 | extern int header_page_data_size; | 234 | extern int header_page_data_size; |
235 | 235 | ||
236 | int parse_header_page(char *buf, unsigned long size); | 236 | int parse_header_page(char *buf, unsigned long size); |
237 | int trace_parse_common_type(void *data); | ||
238 | struct event *trace_find_event(int id); | ||
239 | unsigned long long | ||
240 | raw_field_value(struct event *event, const char *name, void *data); | ||
241 | void *raw_field_ptr(struct event *event, const char *name, void *data); | ||
237 | 242 | ||
238 | void read_tracing_data(struct perf_counter_attr *pattrs, int nb_counters); | 243 | void read_tracing_data(struct perf_counter_attr *pattrs, int nb_counters); |
239 | 244 | ||