diff options
author | Chris Phlipot <cphlipot0@gmail.com> | 2016-04-28 04:19:07 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-05-06 12:00:43 -0400 |
commit | 451db12617bc6ff1bb8ed456ed4f257594134255 (patch) | |
tree | c15426a9f15c17bad7f1d43700eb059e5e946fcd /tools | |
parent | 9919a65ec532799544dfdfd6df6f994b74c12b42 (diff) |
perf tools: Refactor code to move call path handling out of thread-stack
Move the call path handling code out of thread-stack.c and
thread-stack.h to allow other components that are not part of
thread-stack to create call paths.
Summary:
- Create call-path.c and call-path.h and add them to the build.
- Move all call path related code out of thread-stack.c and thread-stack.h
and into call-path.c and call-path.h.
- A small subset of structures and functions are now visible through
call-path.h, which is required for thread-stack.c to continue to
compile.
This change is a prerequisite for subsequent patches in this change set
and by itself contains no user-visible changes.
Signed-off-by: Chris Phlipot <cphlipot0@gmail.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1461831551-12213-3-git-send-email-cphlipot0@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/Build | 1 | ||||
-rw-r--r-- | tools/perf/util/call-path.c | 122 | ||||
-rw-r--r-- | tools/perf/util/call-path.h | 77 | ||||
-rw-r--r-- | tools/perf/util/db-export.c | 1 | ||||
-rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 1 | ||||
-rw-r--r-- | tools/perf/util/thread-stack.c | 126 | ||||
-rw-r--r-- | tools/perf/util/thread-stack.h | 25 |
7 files changed, 204 insertions, 149 deletions
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 90229a88f969..027bb2b89d7f 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -74,6 +74,7 @@ libperf-y += srcline.o | |||
74 | libperf-y += data.o | 74 | libperf-y += data.o |
75 | libperf-y += tsc.o | 75 | libperf-y += tsc.o |
76 | libperf-y += cloexec.o | 76 | libperf-y += cloexec.o |
77 | libperf-y += call-path.o | ||
77 | libperf-y += thread-stack.o | 78 | libperf-y += thread-stack.o |
78 | libperf-$(CONFIG_AUXTRACE) += auxtrace.o | 79 | libperf-$(CONFIG_AUXTRACE) += auxtrace.o |
79 | libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/ | 80 | libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/ |
diff --git a/tools/perf/util/call-path.c b/tools/perf/util/call-path.c new file mode 100644 index 000000000000..904a17052e38 --- /dev/null +++ b/tools/perf/util/call-path.c | |||
@@ -0,0 +1,122 @@ | |||
1 | /* | ||
2 | * call-path.h: Manipulate a tree data structure containing function call paths | ||
3 | * Copyright (c) 2014, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/rbtree.h> | ||
17 | #include <linux/list.h> | ||
18 | |||
19 | #include "util.h" | ||
20 | #include "call-path.h" | ||
21 | |||
22 | static void call_path__init(struct call_path *cp, struct call_path *parent, | ||
23 | struct symbol *sym, u64 ip, bool in_kernel) | ||
24 | { | ||
25 | cp->parent = parent; | ||
26 | cp->sym = sym; | ||
27 | cp->ip = sym ? 0 : ip; | ||
28 | cp->db_id = 0; | ||
29 | cp->in_kernel = in_kernel; | ||
30 | RB_CLEAR_NODE(&cp->rb_node); | ||
31 | cp->children = RB_ROOT; | ||
32 | } | ||
33 | |||
34 | struct call_path_root *call_path_root__new(void) | ||
35 | { | ||
36 | struct call_path_root *cpr; | ||
37 | |||
38 | cpr = zalloc(sizeof(struct call_path_root)); | ||
39 | if (!cpr) | ||
40 | return NULL; | ||
41 | call_path__init(&cpr->call_path, NULL, NULL, 0, false); | ||
42 | INIT_LIST_HEAD(&cpr->blocks); | ||
43 | return cpr; | ||
44 | } | ||
45 | |||
46 | void call_path_root__free(struct call_path_root *cpr) | ||
47 | { | ||
48 | struct call_path_block *pos, *n; | ||
49 | |||
50 | list_for_each_entry_safe(pos, n, &cpr->blocks, node) { | ||
51 | list_del(&pos->node); | ||
52 | free(pos); | ||
53 | } | ||
54 | free(cpr); | ||
55 | } | ||
56 | |||
57 | static struct call_path *call_path__new(struct call_path_root *cpr, | ||
58 | struct call_path *parent, | ||
59 | struct symbol *sym, u64 ip, | ||
60 | bool in_kernel) | ||
61 | { | ||
62 | struct call_path_block *cpb; | ||
63 | struct call_path *cp; | ||
64 | size_t n; | ||
65 | |||
66 | if (cpr->next < cpr->sz) { | ||
67 | cpb = list_last_entry(&cpr->blocks, struct call_path_block, | ||
68 | node); | ||
69 | } else { | ||
70 | cpb = zalloc(sizeof(struct call_path_block)); | ||
71 | if (!cpb) | ||
72 | return NULL; | ||
73 | list_add_tail(&cpb->node, &cpr->blocks); | ||
74 | cpr->sz += CALL_PATH_BLOCK_SIZE; | ||
75 | } | ||
76 | |||
77 | n = cpr->next++ & CALL_PATH_BLOCK_MASK; | ||
78 | cp = &cpb->cp[n]; | ||
79 | |||
80 | call_path__init(cp, parent, sym, ip, in_kernel); | ||
81 | |||
82 | return cp; | ||
83 | } | ||
84 | |||
85 | struct call_path *call_path__findnew(struct call_path_root *cpr, | ||
86 | struct call_path *parent, | ||
87 | struct symbol *sym, u64 ip, u64 ks) | ||
88 | { | ||
89 | struct rb_node **p; | ||
90 | struct rb_node *node_parent = NULL; | ||
91 | struct call_path *cp; | ||
92 | bool in_kernel = ip >= ks; | ||
93 | |||
94 | if (sym) | ||
95 | ip = 0; | ||
96 | |||
97 | if (!parent) | ||
98 | return call_path__new(cpr, parent, sym, ip, in_kernel); | ||
99 | |||
100 | p = &parent->children.rb_node; | ||
101 | while (*p != NULL) { | ||
102 | node_parent = *p; | ||
103 | cp = rb_entry(node_parent, struct call_path, rb_node); | ||
104 | |||
105 | if (cp->sym == sym && cp->ip == ip) | ||
106 | return cp; | ||
107 | |||
108 | if (sym < cp->sym || (sym == cp->sym && ip < cp->ip)) | ||
109 | p = &(*p)->rb_left; | ||
110 | else | ||
111 | p = &(*p)->rb_right; | ||
112 | } | ||
113 | |||
114 | cp = call_path__new(cpr, parent, sym, ip, in_kernel); | ||
115 | if (!cp) | ||
116 | return NULL; | ||
117 | |||
118 | rb_link_node(&cp->rb_node, node_parent, p); | ||
119 | rb_insert_color(&cp->rb_node, &parent->children); | ||
120 | |||
121 | return cp; | ||
122 | } | ||
diff --git a/tools/perf/util/call-path.h b/tools/perf/util/call-path.h new file mode 100644 index 000000000000..477f6d03b659 --- /dev/null +++ b/tools/perf/util/call-path.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * call-path.h: Manipulate a tree data structure containing function call paths | ||
3 | * Copyright (c) 2014, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #ifndef __PERF_CALL_PATH_H | ||
17 | #define __PERF_CALL_PATH_H | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | |||
21 | #include <linux/types.h> | ||
22 | #include <linux/rbtree.h> | ||
23 | |||
24 | /** | ||
25 | * struct call_path - node in list of calls leading to a function call. | ||
26 | * @parent: call path to the parent function call | ||
27 | * @sym: symbol of function called | ||
28 | * @ip: only if sym is null, the ip of the function | ||
29 | * @db_id: id used for db-export | ||
30 | * @in_kernel: whether function is a in the kernel | ||
31 | * @rb_node: node in parent's tree of called functions | ||
32 | * @children: tree of call paths of functions called | ||
33 | * | ||
34 | * In combination with the call_return structure, the call_path structure | ||
35 | * defines a context-sensitve call-graph. | ||
36 | */ | ||
37 | struct call_path { | ||
38 | struct call_path *parent; | ||
39 | struct symbol *sym; | ||
40 | u64 ip; | ||
41 | u64 db_id; | ||
42 | bool in_kernel; | ||
43 | struct rb_node rb_node; | ||
44 | struct rb_root children; | ||
45 | }; | ||
46 | |||
47 | #define CALL_PATH_BLOCK_SHIFT 8 | ||
48 | #define CALL_PATH_BLOCK_SIZE (1 << CALL_PATH_BLOCK_SHIFT) | ||
49 | #define CALL_PATH_BLOCK_MASK (CALL_PATH_BLOCK_SIZE - 1) | ||
50 | |||
51 | struct call_path_block { | ||
52 | struct call_path cp[CALL_PATH_BLOCK_SIZE]; | ||
53 | struct list_head node; | ||
54 | }; | ||
55 | |||
56 | /** | ||
57 | * struct call_path_root - root of all call paths. | ||
58 | * @call_path: root call path | ||
59 | * @blocks: list of blocks to store call paths | ||
60 | * @next: next free space | ||
61 | * @sz: number of spaces | ||
62 | */ | ||
63 | struct call_path_root { | ||
64 | struct call_path call_path; | ||
65 | struct list_head blocks; | ||
66 | size_t next; | ||
67 | size_t sz; | ||
68 | }; | ||
69 | |||
70 | struct call_path_root *call_path_root__new(void); | ||
71 | void call_path_root__free(struct call_path_root *cpr); | ||
72 | |||
73 | struct call_path *call_path__findnew(struct call_path_root *cpr, | ||
74 | struct call_path *parent, | ||
75 | struct symbol *sym, u64 ip, u64 ks); | ||
76 | |||
77 | #endif | ||
diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index 049438d51b9a..4fc607c130b8 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "event.h" | 23 | #include "event.h" |
24 | #include "util.h" | 24 | #include "util.h" |
25 | #include "thread-stack.h" | 25 | #include "thread-stack.h" |
26 | #include "call-path.h" | ||
26 | #include "db-export.h" | 27 | #include "db-export.h" |
27 | 28 | ||
28 | struct deferred_export { | 29 | struct deferred_export { |
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 525eb49e7ba6..7bb859202249 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -41,6 +41,7 @@ | |||
41 | #include "../thread-stack.h" | 41 | #include "../thread-stack.h" |
42 | #include "../trace-event.h" | 42 | #include "../trace-event.h" |
43 | #include "../machine.h" | 43 | #include "../machine.h" |
44 | #include "../call-path.h" | ||
44 | #include "thread_map.h" | 45 | #include "thread_map.h" |
45 | #include "cpumap.h" | 46 | #include "cpumap.h" |
46 | #include "stat.h" | 47 | #include "stat.h" |
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c index 679688e70ae7..fc419a59c88b 100644 --- a/tools/perf/util/thread-stack.c +++ b/tools/perf/util/thread-stack.c | |||
@@ -22,31 +22,9 @@ | |||
22 | #include "debug.h" | 22 | #include "debug.h" |
23 | #include "symbol.h" | 23 | #include "symbol.h" |
24 | #include "comm.h" | 24 | #include "comm.h" |
25 | #include "call-path.h" | ||
25 | #include "thread-stack.h" | 26 | #include "thread-stack.h" |
26 | 27 | ||
27 | #define CALL_PATH_BLOCK_SHIFT 8 | ||
28 | #define CALL_PATH_BLOCK_SIZE (1 << CALL_PATH_BLOCK_SHIFT) | ||
29 | #define CALL_PATH_BLOCK_MASK (CALL_PATH_BLOCK_SIZE - 1) | ||
30 | |||
31 | struct call_path_block { | ||
32 | struct call_path cp[CALL_PATH_BLOCK_SIZE]; | ||
33 | struct list_head node; | ||
34 | }; | ||
35 | |||
36 | /** | ||
37 | * struct call_path_root - root of all call paths. | ||
38 | * @call_path: root call path | ||
39 | * @blocks: list of blocks to store call paths | ||
40 | * @next: next free space | ||
41 | * @sz: number of spaces | ||
42 | */ | ||
43 | struct call_path_root { | ||
44 | struct call_path call_path; | ||
45 | struct list_head blocks; | ||
46 | size_t next; | ||
47 | size_t sz; | ||
48 | }; | ||
49 | |||
50 | /** | 28 | /** |
51 | * struct call_return_processor - provides a call-back to consume call-return | 29 | * struct call_return_processor - provides a call-back to consume call-return |
52 | * information. | 30 | * information. |
@@ -335,108 +313,6 @@ void thread_stack__sample(struct thread *thread, struct ip_callchain *chain, | |||
335 | chain->ips[i] = thread->ts->stack[thread->ts->cnt - i].ret_addr; | 313 | chain->ips[i] = thread->ts->stack[thread->ts->cnt - i].ret_addr; |
336 | } | 314 | } |
337 | 315 | ||
338 | static void call_path__init(struct call_path *cp, struct call_path *parent, | ||
339 | struct symbol *sym, u64 ip, bool in_kernel) | ||
340 | { | ||
341 | cp->parent = parent; | ||
342 | cp->sym = sym; | ||
343 | cp->ip = sym ? 0 : ip; | ||
344 | cp->db_id = 0; | ||
345 | cp->in_kernel = in_kernel; | ||
346 | RB_CLEAR_NODE(&cp->rb_node); | ||
347 | cp->children = RB_ROOT; | ||
348 | } | ||
349 | |||
350 | static struct call_path_root *call_path_root__new(void) | ||
351 | { | ||
352 | struct call_path_root *cpr; | ||
353 | |||
354 | cpr = zalloc(sizeof(struct call_path_root)); | ||
355 | if (!cpr) | ||
356 | return NULL; | ||
357 | call_path__init(&cpr->call_path, NULL, NULL, 0, false); | ||
358 | INIT_LIST_HEAD(&cpr->blocks); | ||
359 | return cpr; | ||
360 | } | ||
361 | |||
362 | static void call_path_root__free(struct call_path_root *cpr) | ||
363 | { | ||
364 | struct call_path_block *pos, *n; | ||
365 | |||
366 | list_for_each_entry_safe(pos, n, &cpr->blocks, node) { | ||
367 | list_del(&pos->node); | ||
368 | free(pos); | ||
369 | } | ||
370 | free(cpr); | ||
371 | } | ||
372 | |||
373 | static struct call_path *call_path__new(struct call_path_root *cpr, | ||
374 | struct call_path *parent, | ||
375 | struct symbol *sym, u64 ip, | ||
376 | bool in_kernel) | ||
377 | { | ||
378 | struct call_path_block *cpb; | ||
379 | struct call_path *cp; | ||
380 | size_t n; | ||
381 | |||
382 | if (cpr->next < cpr->sz) { | ||
383 | cpb = list_last_entry(&cpr->blocks, struct call_path_block, | ||
384 | node); | ||
385 | } else { | ||
386 | cpb = zalloc(sizeof(struct call_path_block)); | ||
387 | if (!cpb) | ||
388 | return NULL; | ||
389 | list_add_tail(&cpb->node, &cpr->blocks); | ||
390 | cpr->sz += CALL_PATH_BLOCK_SIZE; | ||
391 | } | ||
392 | |||
393 | n = cpr->next++ & CALL_PATH_BLOCK_MASK; | ||
394 | cp = &cpb->cp[n]; | ||
395 | |||
396 | call_path__init(cp, parent, sym, ip, in_kernel); | ||
397 | |||
398 | return cp; | ||
399 | } | ||
400 | |||
401 | static struct call_path *call_path__findnew(struct call_path_root *cpr, | ||
402 | struct call_path *parent, | ||
403 | struct symbol *sym, u64 ip, u64 ks) | ||
404 | { | ||
405 | struct rb_node **p; | ||
406 | struct rb_node *node_parent = NULL; | ||
407 | struct call_path *cp; | ||
408 | bool in_kernel = ip >= ks; | ||
409 | |||
410 | if (sym) | ||
411 | ip = 0; | ||
412 | |||
413 | if (!parent) | ||
414 | return call_path__new(cpr, parent, sym, ip, in_kernel); | ||
415 | |||
416 | p = &parent->children.rb_node; | ||
417 | while (*p != NULL) { | ||
418 | node_parent = *p; | ||
419 | cp = rb_entry(node_parent, struct call_path, rb_node); | ||
420 | |||
421 | if (cp->sym == sym && cp->ip == ip) | ||
422 | return cp; | ||
423 | |||
424 | if (sym < cp->sym || (sym == cp->sym && ip < cp->ip)) | ||
425 | p = &(*p)->rb_left; | ||
426 | else | ||
427 | p = &(*p)->rb_right; | ||
428 | } | ||
429 | |||
430 | cp = call_path__new(cpr, parent, sym, ip, in_kernel); | ||
431 | if (!cp) | ||
432 | return NULL; | ||
433 | |||
434 | rb_link_node(&cp->rb_node, node_parent, p); | ||
435 | rb_insert_color(&cp->rb_node, &parent->children); | ||
436 | |||
437 | return cp; | ||
438 | } | ||
439 | |||
440 | struct call_return_processor * | 316 | struct call_return_processor * |
441 | call_return_processor__new(int (*process)(struct call_return *cr, void *data), | 317 | call_return_processor__new(int (*process)(struct call_return *cr, void *data), |
442 | void *data) | 318 | void *data) |
diff --git a/tools/perf/util/thread-stack.h b/tools/perf/util/thread-stack.h index e1528f1374c3..ec9beddfdbab 100644 --- a/tools/perf/util/thread-stack.h +++ b/tools/perf/util/thread-stack.h | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | 20 | ||
21 | #include <linux/types.h> | 21 | #include <linux/types.h> |
22 | #include <linux/rbtree.h> | ||
23 | 22 | ||
24 | struct thread; | 23 | struct thread; |
25 | struct comm; | 24 | struct comm; |
@@ -30,6 +29,7 @@ struct call_return_processor; | |||
30 | struct comm; | 29 | struct comm; |
31 | struct perf_sample; | 30 | struct perf_sample; |
32 | struct addr_location; | 31 | struct addr_location; |
32 | struct call_path; | ||
33 | 33 | ||
34 | /* | 34 | /* |
35 | * Call/Return flags. | 35 | * Call/Return flags. |
@@ -68,29 +68,6 @@ struct call_return { | |||
68 | u32 flags; | 68 | u32 flags; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | /** | ||
72 | * struct call_path - node in list of calls leading to a function call. | ||
73 | * @parent: call path to the parent function call | ||
74 | * @sym: symbol of function called | ||
75 | * @ip: only if sym is null, the ip of the function | ||
76 | * @db_id: id used for db-export | ||
77 | * @in_kernel: whether function is a in the kernel | ||
78 | * @rb_node: node in parent's tree of called functions | ||
79 | * @children: tree of call paths of functions called | ||
80 | * | ||
81 | * In combination with the call_return structure, the call_path structure | ||
82 | * defines a context-sensitve call-graph. | ||
83 | */ | ||
84 | struct call_path { | ||
85 | struct call_path *parent; | ||
86 | struct symbol *sym; | ||
87 | u64 ip; | ||
88 | u64 db_id; | ||
89 | bool in_kernel; | ||
90 | struct rb_node rb_node; | ||
91 | struct rb_root children; | ||
92 | }; | ||
93 | |||
94 | int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip, | 71 | int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip, |
95 | u64 to_ip, u16 insn_len, u64 trace_nr); | 72 | u64 to_ip, u16 insn_len, u64 trace_nr); |
96 | void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr); | 73 | void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr); |