diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | plugin_function.c | 143 |
2 files changed, 144 insertions, 1 deletions
@@ -265,7 +265,7 @@ TCMD_LIB_OBJS = $(PEVENT_LIB_OBJS) trace-util.o trace-input.o trace-ftrace.o \ | |||
265 | trace-output.o trace-record.o | 265 | trace-output.o trace-record.o |
266 | 266 | ||
267 | PLUGIN_OBJS = plugin_hrtimer.o plugin_kmem.o plugin_sched_switch.o \ | 267 | PLUGIN_OBJS = plugin_hrtimer.o plugin_kmem.o plugin_sched_switch.o \ |
268 | plugin_mac80211.o plugin_jbd2.o | 268 | plugin_mac80211.o plugin_jbd2.o plugin_function.o |
269 | 269 | ||
270 | PLUGINS := $(PLUGIN_OBJS:.o=.so) | 270 | PLUGINS := $(PLUGIN_OBJS:.o=.so) |
271 | 271 | ||
diff --git a/plugin_function.c b/plugin_function.c new file mode 100644 index 0000000..9ee0eaa --- /dev/null +++ b/plugin_function.c | |||
@@ -0,0 +1,143 @@ | |||
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, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
20 | */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | #include "parse-events.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 record *record, | ||
93 | struct event_format *event, void *context) | ||
94 | { | ||
95 | struct pevent *pevent = event->pevent; | ||
96 | unsigned long long function; | ||
97 | const char *func; | ||
98 | const char *parent; | ||
99 | int i, index; | ||
100 | |||
101 | if (pevent_get_field_val(s, event, "ip", record, &function, 1)) | ||
102 | return trace_seq_putc(s, '!'); | ||
103 | |||
104 | func = pevent_find_function(pevent, function); | ||
105 | |||
106 | if (pevent_get_field_val(s, event, "parent_ip", record, &function, 1)) | ||
107 | return trace_seq_putc(s, '!'); | ||
108 | |||
109 | parent = pevent_find_function(pevent, function); | ||
110 | |||
111 | index = get_index(parent, func, record->cpu); | ||
112 | |||
113 | for (i = 0; i < index; i++) | ||
114 | trace_seq_printf(s, " "); | ||
115 | |||
116 | if (func) | ||
117 | trace_seq_printf(s, "%s", func); | ||
118 | else | ||
119 | trace_seq_printf(s, "0x%llx", function); | ||
120 | |||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | int PEVENT_PLUGIN_LOADER(struct pevent *pevent) | ||
125 | { | ||
126 | pevent_register_event_handler(pevent, -1, "ftrace", "function", | ||
127 | function_handler, NULL); | ||
128 | |||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | void PEVENT_PLUGIN_UNLOADER(void) | ||
133 | { | ||
134 | int i, x; | ||
135 | |||
136 | for (i = 0; i <= cpus; i++) { | ||
137 | for (x = 0; x < fstack[i].size && fstack[i].stack[x]; x++) | ||
138 | free(fstack[i].stack[x]); | ||
139 | free(fstack[i].stack); | ||
140 | } | ||
141 | |||
142 | free(fstack); | ||
143 | } | ||