~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/lib/traceevent/plugin_function.c

Version: ~ [ linux-4.20-rc2 ] ~ [ linux-4.19.1 ] ~ [ linux-4.18.18 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.80 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.136 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.163 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.125 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.60 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.31.14 ] ~ [ linux-2.6.30.10 ] ~ [ linux-2.6.29.6 ] ~ [ linux-2.6.28.10 ] ~ [ linux-2.6.27.62 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 #include "trace-seq.h"
 27 
 28 static struct func_stack {
 29         int size;
 30         char **stack;
 31 } *fstack;
 32 
 33 static int cpus = -1;
 34 
 35 #define STK_BLK 10
 36 
 37 struct tep_plugin_option plugin_options[] =
 38 {
 39         {
 40                 .name = "parent",
 41                 .plugin_alias = "ftrace",
 42                 .description =
 43                 "Print parent of functions for function events",
 44         },
 45         {
 46                 .name = "indent",
 47                 .plugin_alias = "ftrace",
 48                 .description =
 49                 "Try to show function call indents, based on parents",
 50                 .set = 1,
 51         },
 52         {
 53                 .name = NULL,
 54         }
 55 };
 56 
 57 static struct tep_plugin_option *ftrace_parent = &plugin_options[0];
 58 static struct tep_plugin_option *ftrace_indent = &plugin_options[1];
 59 
 60 static void add_child(struct func_stack *stack, const char *child, int pos)
 61 {
 62         int i;
 63 
 64         if (!child)
 65                 return;
 66 
 67         if (pos < stack->size)
 68                 free(stack->stack[pos]);
 69         else {
 70                 char **ptr;
 71 
 72                 ptr = realloc(stack->stack, sizeof(char *) *
 73                               (stack->size + STK_BLK));
 74                 if (!ptr) {
 75                         warning("could not allocate plugin memory\n");
 76                         return;
 77                 }
 78 
 79                 stack->stack = ptr;
 80 
 81                 for (i = stack->size; i < stack->size + STK_BLK; i++)
 82                         stack->stack[i] = NULL;
 83                 stack->size += STK_BLK;
 84         }
 85 
 86         stack->stack[pos] = strdup(child);
 87 }
 88 
 89 static int add_and_get_index(const char *parent, const char *child, int cpu)
 90 {
 91         int i;
 92 
 93         if (cpu < 0)
 94                 return 0;
 95 
 96         if (cpu > cpus) {
 97                 struct func_stack *ptr;
 98 
 99                 ptr = realloc(fstack, sizeof(*fstack) * (cpu + 1));
100                 if (!ptr) {
101                         warning("could not allocate plugin memory\n");
102                         return 0;
103                 }
104 
105                 fstack = ptr;
106 
107                 /* Account for holes in the cpu count */
108                 for (i = cpus + 1; i <= cpu; i++)
109                         memset(&fstack[i], 0, sizeof(fstack[i]));
110                 cpus = cpu;
111         }
112 
113         for (i = 0; i < fstack[cpu].size && fstack[cpu].stack[i]; i++) {
114                 if (strcmp(parent, fstack[cpu].stack[i]) == 0) {
115                         add_child(&fstack[cpu], child, i+1);
116                         return i;
117                 }
118         }
119 
120         /* Not found */
121         add_child(&fstack[cpu], parent, 0);
122         add_child(&fstack[cpu], child, 1);
123         return 0;
124 }
125 
126 static int function_handler(struct trace_seq *s, struct tep_record *record,
127                             struct tep_event_format *event, void *context)
128 {
129         struct tep_handle *pevent = event->pevent;
130         unsigned long long function;
131         unsigned long long pfunction;
132         const char *func;
133         const char *parent;
134         int index = 0;
135 
136         if (tep_get_field_val(s, event, "ip", record, &function, 1))
137                 return trace_seq_putc(s, '!');
138 
139         func = tep_find_function(pevent, function);
140 
141         if (tep_get_field_val(s, event, "parent_ip", record, &pfunction, 1))
142                 return trace_seq_putc(s, '!');
143 
144         parent = tep_find_function(pevent, pfunction);
145 
146         if (parent && ftrace_indent->set)
147                 index = add_and_get_index(parent, func, record->cpu);
148 
149         trace_seq_printf(s, "%*s", index*3, "");
150 
151         if (func)
152                 trace_seq_printf(s, "%s", func);
153         else
154                 trace_seq_printf(s, "0x%llx", function);
155 
156         if (ftrace_parent->set) {
157                 trace_seq_printf(s, " <-- ");
158                 if (parent)
159                         trace_seq_printf(s, "%s", parent);
160                 else
161                         trace_seq_printf(s, "0x%llx", pfunction);
162         }
163 
164         return 0;
165 }
166 
167 int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
168 {
169         tep_register_event_handler(pevent, -1, "ftrace", "function",
170                                    function_handler, NULL);
171 
172         tep_plugin_add_options("ftrace", plugin_options);
173 
174         return 0;
175 }
176 
177 void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
178 {
179         int i, x;
180 
181         tep_unregister_event_handler(pevent, -1, "ftrace", "function",
182                                      function_handler, NULL);
183 
184         for (i = 0; i <= cpus; i++) {
185                 for (x = 0; x < fstack[i].size && fstack[i].stack[x]; x++)
186                         free(fstack[i].stack[x]);
187                 free(fstack[i].stack);
188         }
189 
190         tep_plugin_remove_options(plugin_options);
191 
192         free(fstack);
193         fstack = NULL;
194         cpus = -1;
195 }
196 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp