diff options
author | Jiri Olsa <jolsa@redhat.com> | 2013-12-03 08:09:32 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-12-04 13:32:00 -0500 |
commit | 07a180a0bfea7029b8cf84a7d8e856539e5c69f5 (patch) | |
tree | c0823773a5b6ec94e51f033ae4b672ef49726a51 | |
parent | 83e815ee1c6b5fdb570374404ab44b24c1325ccb (diff) |
tools lib traceevent: Add function plugin
Backporting function plugin.
Backported from Steven Rostedt's trace-cmd repo (HEAD 0f2c2fb):
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git
This plugin adds function and parent function fields resolving for
ftrace:function tracepoint event.
The diff of 'perf script' output generated by old and new code:
(data was generated by 'perf record -e ftrace:function ls')
--- script.function.old
+++ script.function.new
- ls 10781 [001] 32667.291379: ftrace:function: ffffffff811adb80 <-- ffffffff811afc48
- ls 10781 [001] 32667.291379: ftrace:function: ffffffff811b35d0 <-- ffffffff811adb9b
- ls 10781 [001] 32667.291380: ftrace:function: ffffffff811b3520 <-- ffffffff811b35e8
- ls 10781 [001] 32667.291380: ftrace:function: ffffffff811b2720 <-- ffffffff811b3549
- ls 10781 [001] 32667.291381: ftrace:function: ffffffff81297e10 <-- ffffffff811b356c
- ls 10781 [001] 32667.291381: ftrace:function: ffffffff81298f40 <-- ffffffff81297e2c
- ls 10781 [001] 32667.291382: ftrace:function: ffffffff81076160 <-- ffffffff811afbf0
- ls 10781 [001] 32667.291383: ftrace:function: ffffffff811c3eb0 <-- ffffffff811afbfc
- ls 10781 [001] 32667.291383: ftrace:function: ffffffff8164e100 <-- ffffffff811c3ed8
- ls 10781 [001] 32667.291384: ftrace:function: ffffffff811a5d10 <-- ffffffff811c3f53
- ls 10781 [001] 32667.291384: ftrace:function: ffffffff811e8e70 <-- ffffffff811a5d58
- ls 10781 [001] 32667.291385: ftrace:function: ffffffff811f38e0 <-- ffffffff811a5d63
- ls 10781 [001] 32667.291385: ftrace:function: ffffffff811a9ff0 <-- ffffffff811a5d6b
- ls 10781 [001] 32667.291386: ftrace:function: ffffffff811a9fa0 <-- ffffffff811aa015
- ls 10781 [001] 32667.291387: ftrace:function: ffffffff810851c0 <-- ffffffff811aa053
- ls 10781 [001] 32667.291387: ftrace:function: ffffffff81090e00 <-- ffffffff81085211
+ ls 10781 [001] 32667.291379: ftrace:function: would_dump <-- setup_new_exec
+ ls 10781 [001] 32667.291379: ftrace:function: inode_permission <-- would_dump
+ ls 10781 [001] 32667.291380: ftrace:function: __inode_permission <-- inode_permission
+ ls 10781 [001] 32667.291380: ftrace:function: generic_permission <-- __inode_permission
+ ls 10781 [001] 32667.291381: ftrace:function: security_inode_permission <-- __inode_permission
+ ls 10781 [001] 32667.291381: ftrace:function: cap_inode_permission <-- security_inode_permission
+ ls 10781 [001] 32667.291382: ftrace:function: flush_signal_handlers <-- setup_new_exec
+ ls 10781 [001] 32667.291383: ftrace:function: do_close_on_exec <-- setup_new_exec
+ ls 10781 [001] 32667.291383: ftrace:function: _raw_spin_lock <-- do_close_on_exec
+ ls 10781 [001] 32667.291384: ftrace:function: filp_close <-- do_close_on_exec
+ ls 10781 [001] 32667.291384: ftrace:function: dnotify_flush <-- filp_close
+ ls 10781 [001] 32667.291385: ftrace:function: locks_remove_posix <-- filp_close
+ ls 10781 [001] 32667.291385: ftrace:function: fput <-- filp_close
+ ls 10781 [001] 32667.291386: ftrace:function: file_sb_list_del <-- fput
+ ls 10781 [001] 32667.291387: ftrace:function: task_work_add <-- fput
+ ls 10781 [001] 32667.291387: ftrace:function: kick_process <-- task_work_add
Removing options support as it's not backported yet.
Currently this plugin supports 2 options:
'parent' to display parent function
'indent' to show function call indents
Enabling both of them by default.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386076182-14484-19-git-send-email-jolsa@redhat.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/lib/traceevent/Makefile | 1 | ||||
-rw-r--r-- | tools/lib/traceevent/plugin_function.c | 151 |
2 files changed, 152 insertions, 0 deletions
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile index 1c319a8cf1b0..21f9b8fa5e43 100644 --- a/tools/lib/traceevent/Makefile +++ b/tools/lib/traceevent/Makefile | |||
@@ -218,6 +218,7 @@ PLUGIN_OBJS += plugin_kmem.o | |||
218 | PLUGIN_OBJS += plugin_kvm.o | 218 | PLUGIN_OBJS += plugin_kvm.o |
219 | PLUGIN_OBJS += plugin_mac80211.o | 219 | PLUGIN_OBJS += plugin_mac80211.o |
220 | PLUGIN_OBJS += plugin_sched_switch.o | 220 | PLUGIN_OBJS += plugin_sched_switch.o |
221 | PLUGIN_OBJS += plugin_function.o | ||
221 | 222 | ||
222 | PLUGINS := $(PLUGIN_OBJS:.o=.so) | 223 | PLUGINS := $(PLUGIN_OBJS:.o=.so) |
223 | 224 | ||
diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c new file mode 100644 index 000000000000..8deb22e69361 --- /dev/null +++ b/tools/lib/traceevent/plugin_function.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | ||
3 | * | ||
4 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; | ||
8 | * version 2.1 of the License (not later!) | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this program; if not, see <http://www.gnu.org/licenses> | ||
17 | * | ||
18 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
19 | */ | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | |||
24 | #include "event-parse.h" | ||
25 | #include "event-utils.h" | ||
26 | |||
27 | static struct func_stack { | ||
28 | int index; | ||
29 | int size; | ||
30 | char **stack; | ||
31 | } *fstack; | ||
32 | |||
33 | static int cpus = -1; | ||
34 | |||
35 | #define STK_BLK 10 | ||
36 | |||
37 | static void add_child(struct func_stack *stack, const char *child, int pos) | ||
38 | { | ||
39 | int i; | ||
40 | |||
41 | if (!child) | ||
42 | return; | ||
43 | |||
44 | if (pos < stack->size) | ||
45 | free(stack->stack[pos]); | ||
46 | else { | ||
47 | if (!stack->stack) | ||
48 | stack->stack = malloc_or_die(sizeof(char *) * STK_BLK); | ||
49 | else | ||
50 | stack->stack = realloc(stack->stack, sizeof(char *) * | ||
51 | (stack->size + STK_BLK)); | ||
52 | for (i = stack->size; i < stack->size + STK_BLK; i++) | ||
53 | stack->stack[i] = NULL; | ||
54 | stack->size += STK_BLK; | ||
55 | } | ||
56 | |||
57 | stack->stack[pos] = strdup(child); | ||
58 | } | ||
59 | |||
60 | static int get_index(const char *parent, const char *child, int cpu) | ||
61 | { | ||
62 | int i; | ||
63 | |||
64 | if (cpu < 0) | ||
65 | return 0; | ||
66 | |||
67 | if (cpu > cpus) { | ||
68 | if (fstack) | ||
69 | fstack = realloc(fstack, sizeof(*fstack) * (cpu + 1)); | ||
70 | else | ||
71 | fstack = malloc_or_die(sizeof(*fstack) * (cpu + 1)); | ||
72 | |||
73 | /* Account for holes in the cpu count */ | ||
74 | for (i = cpus + 1; i <= cpu; i++) | ||
75 | memset(&fstack[i], 0, sizeof(fstack[i])); | ||
76 | cpus = cpu; | ||
77 | } | ||
78 | |||
79 | for (i = 0; i < fstack[cpu].size && fstack[cpu].stack[i]; i++) { | ||
80 | if (strcmp(parent, fstack[cpu].stack[i]) == 0) { | ||
81 | add_child(&fstack[cpu], child, i+1); | ||
82 | return i; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | /* Not found */ | ||
87 | add_child(&fstack[cpu], parent, 0); | ||
88 | add_child(&fstack[cpu], child, 1); | ||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static int function_handler(struct trace_seq *s, struct pevent_record *record, | ||
93 | struct event_format *event, void *context) | ||
94 | { | ||
95 | struct pevent *pevent = event->pevent; | ||
96 | unsigned long long function; | ||
97 | unsigned long long pfunction; | ||
98 | const char *func; | ||
99 | const char *parent; | ||
100 | int i, index; | ||
101 | |||
102 | if (pevent_get_field_val(s, event, "ip", record, &function, 1)) | ||
103 | return trace_seq_putc(s, '!'); | ||
104 | |||
105 | func = pevent_find_function(pevent, function); | ||
106 | |||
107 | if (pevent_get_field_val(s, event, "parent_ip", record, &pfunction, 1)) | ||
108 | return trace_seq_putc(s, '!'); | ||
109 | |||
110 | parent = pevent_find_function(pevent, pfunction); | ||
111 | |||
112 | index = get_index(parent, func, record->cpu); | ||
113 | |||
114 | for (i = 0; i < index; i++) | ||
115 | trace_seq_printf(s, " "); | ||
116 | |||
117 | if (func) | ||
118 | trace_seq_printf(s, "%s", func); | ||
119 | else | ||
120 | trace_seq_printf(s, "0x%llx", function); | ||
121 | |||
122 | trace_seq_printf(s, " <-- "); | ||
123 | if (parent) | ||
124 | trace_seq_printf(s, "%s", parent); | ||
125 | else | ||
126 | trace_seq_printf(s, "0x%llx", pfunction); | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | int PEVENT_PLUGIN_LOADER(struct pevent *pevent) | ||
132 | { | ||
133 | pevent_register_event_handler(pevent, -1, "ftrace", "function", | ||
134 | function_handler, NULL); | ||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | void PEVENT_PLUGIN_UNLOADER(void) | ||
139 | { | ||
140 | int i, x; | ||
141 | |||
142 | for (i = 0; i <= cpus; i++) { | ||
143 | for (x = 0; x < fstack[i].size && fstack[i].stack[x]; x++) | ||
144 | free(fstack[i].stack[x]); | ||
145 | free(fstack[i].stack); | ||
146 | } | ||
147 | |||
148 | free(fstack); | ||
149 | fstack = NULL; | ||
150 | cpus = -1; | ||
151 | } | ||