From: Namhyung Kim <namhyung@kernel.org>
To: Jiri Olsa <jolsa@redhat.com>
Cc: linux-kernel@vger.kernel.org,
Corey Ashford <cjashfor@linux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
David Ahern <dsahern@gmail.com>
Subject: Re: [PATCH 10/22] tools lib traceevent: Add function plugin
Date: Sat, 23 Nov 2013 00:03:51 +0900 [thread overview]
Message-ID: <1385132631.1747.68.camel@leonhard> (raw)
In-Reply-To: <1385031680-9014-11-git-send-email-jolsa@redhat.com>
2013-11-21 (목), 12:01 +0100, Jiri Olsa:
> 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.
[SNIP]
> +static struct func_stack {
> + int index;
It seems not used anywhere.
> + int size;
> + char **stack;
> +} *fstack;
> +
> +static int cpus = -1;
> +
> +#define STK_BLK 10
> +
> +static void add_child(struct func_stack *stack, const char *child, int pos)
> +{
> + int i;
> +
> + if (!child)
> + return;
> +
> + if (pos < stack->size)
> + free(stack->stack[pos]);
> + else {
> + if (!stack->stack)
> + stack->stack = malloc_or_die(sizeof(char *) * STK_BLK);
Please do not use this function.
> + else
> + stack->stack = realloc(stack->stack, sizeof(char *) *
> + (stack->size + STK_BLK));
It seems you need to use a local variable to check return value.
> + for (i = stack->size; i < stack->size + STK_BLK; i++)
> + stack->stack[i] = NULL;
> + stack->size += STK_BLK;
> + }
> +
> + stack->stack[pos] = strdup(child);
> +}
> +
> +static int get_index(const char *parent, const char *child, int cpu)
It seems this function does not only to get index but also to add
function stack. So how about renaming it to something like
add_and_get_index()?
> +{
> + int i;
> +
> + if (cpu < 0)
> + return 0;
> +
> + if (cpu > cpus) {
> + if (fstack)
> + fstack = realloc(fstack, sizeof(*fstack) * (cpu + 1));
> + else
> + fstack = malloc_or_die(sizeof(*fstack) * (cpu + 1));
It seems it has same problem as above function.
> +
> + /* Account for holes in the cpu count */
> + for (i = cpus + 1; i <= cpu; i++)
> + memset(&fstack[i], 0, sizeof(fstack[i]));
> + cpus = cpu;
> + }
> +
> + for (i = 0; i < fstack[cpu].size && fstack[cpu].stack[i]; i++) {
> + if (strcmp(parent, fstack[cpu].stack[i]) == 0) {
> + add_child(&fstack[cpu], child, i+1);
> + return i;
> + }
> + }
> +
> + /* Not found */
> + add_child(&fstack[cpu], parent, 0);
> + add_child(&fstack[cpu], child, 1);
> + return 0;
> +}
> +
> +static int function_handler(struct trace_seq *s, struct pevent_record *record,
> + struct event_format *event, void *context)
> +{
> + struct pevent *pevent = event->pevent;
> + unsigned long long function;
> + unsigned long long pfunction;
> + const char *func;
> + const char *parent;
> + int i, index;
> +
> + if (pevent_get_field_val(s, event, "ip", record, &function, 1))
> + return trace_seq_putc(s, '!');
> +
> + func = pevent_find_function(pevent, function);
> +
> + if (pevent_get_field_val(s, event, "parent_ip", record, &pfunction, 1))
> + return trace_seq_putc(s, '!');
> +
> + parent = pevent_find_function(pevent, pfunction);
> +
> + index = get_index(parent, func, record->cpu);
> +
> + for (i = 0; i < index; i++)
> + trace_seq_printf(s, " ");
What about this?
trace_seq_printf(s, "%*s", index*3, "");
Thanks,
Namhyung
> +
> + if (func)
> + trace_seq_printf(s, "%s", func);
> + else
> + trace_seq_printf(s, "0x%llx", function);
> +
> + trace_seq_printf(s, " <-- ");
> + if (parent)
> + trace_seq_printf(s, "%s", parent);
> + else
> + trace_seq_printf(s, "0x%llx", pfunction);
> +
> + return 0;
> +}
> +
> +int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
> +{
> + pevent_register_event_handler(pevent, -1, "ftrace", "function",
> + function_handler, NULL);
> + return 0;
> +}
> +
> +void PEVENT_PLUGIN_UNLOADER(void)
> +{
> + int i, x;
> +
> + for (i = 0; i <= cpus; i++) {
> + for (x = 0; x < fstack[i].size && fstack[i].stack[x]; x++)
> + free(fstack[i].stack[x]);
> + free(fstack[i].stack);
> + }
> +
> + free(fstack);
> + fstack = NULL;
> + cpus = -1;
> +}
next prev parent reply other threads:[~2013-11-22 15:04 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 11:00 [PATCH 00/22] perf tools: Add traceevent plugins support Jiri Olsa
2013-11-21 11:00 ` [PATCH 01/22] tools lib traceevent: Add plugin support Jiri Olsa
2013-11-21 11:58 ` Steven Rostedt
2013-11-22 14:17 ` Namhyung Kim
2013-11-23 8:12 ` Steven Rostedt
2013-11-25 7:33 ` Namhyung Kim
2013-11-25 9:30 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 02/22] tools lib traceevent: Add plugin build support Jiri Olsa
2013-11-21 11:01 ` [PATCH 03/22] tools lib traceevent: Add traceevent_host_bigendian function Jiri Olsa
2013-11-22 14:22 ` Namhyung Kim
2013-11-23 8:27 ` Steven Rostedt
2013-11-25 7:24 ` Namhyung Kim
2013-11-25 9:33 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 04/22] tools lib traceevent: Add jbd2 plugin Jiri Olsa
2013-11-21 13:09 ` Steven Rostedt
2013-11-22 14:27 ` Namhyung Kim
2013-11-23 8:52 ` Steven Rostedt
2013-11-25 7:38 ` Namhyung Kim
2013-11-25 9:46 ` Jiri Olsa
2013-11-25 10:03 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 05/22] tools lib traceevent: Add hrtimer plugin Jiri Olsa
2013-11-21 13:10 ` Steven Rostedt
2013-11-22 14:33 ` Namhyung Kim
2013-11-23 8:59 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 06/22] tools lib traceevent: Add kmem plugin Jiri Olsa
2013-11-21 13:14 ` Steven Rostedt
2013-11-22 14:38 ` Namhyung Kim
2013-11-23 9:06 ` Steven Rostedt
2013-11-25 7:43 ` Namhyung Kim
2013-11-21 11:01 ` [PATCH 07/22] tools lib traceevent: Add kvm plugin Jiri Olsa
2013-11-21 13:15 ` Steven Rostedt
2013-11-22 14:45 ` Namhyung Kim
2013-11-23 9:15 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 08/22] tools lib traceevent: Add mac80211 plugin Jiri Olsa
2013-11-21 11:01 ` [PATCH 09/22] tools lib traceevent: Add sched_switch plugin Jiri Olsa
2013-11-21 13:18 ` Steven Rostedt
[not found] ` <1385132034.1747.58.camel@leonhard>
2013-11-23 9:16 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 10/22] tools lib traceevent: Add function plugin Jiri Olsa
2013-11-21 13:20 ` Steven Rostedt
2013-11-22 15:03 ` Namhyung Kim [this message]
2013-11-23 9:22 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 11/22] tools lib traceevent: Add xen plugin Jiri Olsa
2013-11-22 15:06 ` Namhyung Kim
2013-11-25 13:38 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 12/22] tools lib traceevent: Add scsi plugin Jiri Olsa
2013-11-22 15:24 ` Namhyung Kim
2013-11-23 9:25 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 13/22] tools lib traceevent: Add cfg80211 plugin Jiri Olsa
2013-11-22 15:16 ` Namhyung Kim
2013-11-23 9:27 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 14/22] tools lib traceevent: Update kvm plugin with is_writable_pte helper Jiri Olsa
2013-11-22 15:19 ` Namhyung Kim
2013-11-23 9:28 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 15/22] tools lib traceevent: Change pevent_parse_event to return event format Jiri Olsa
2013-11-21 13:28 ` Steven Rostedt
2013-11-21 13:42 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 16/22] tools lib traceevent: Harmonize the install messages in lib-traceevent Jiri Olsa
2013-11-21 11:01 ` [PATCH 17/22] perf tools: Add build and install plugins targets Jiri Olsa
2013-11-22 15:27 ` Namhyung Kim
2013-11-25 14:51 ` Jiri Olsa
2013-11-27 8:13 ` Namhyung Kim
2013-11-21 11:01 ` [PATCH 18/22] perf tools: Add udis86 disassembler feature check Jiri Olsa
2013-11-22 15:38 ` Namhyung Kim
2013-11-25 15:02 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 19/22] perf tools: Add filename__read_str util function Jiri Olsa
2013-11-22 15:43 ` Namhyung Kim
2013-11-25 15:17 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 20/22] perf tools: Add trace-event object Jiri Olsa
2013-11-21 11:01 ` [PATCH 21/22] perf tools: Add trace-event global object for tracepoint interface Jiri Olsa
2013-11-22 15:47 ` Namhyung Kim
2013-11-25 16:03 ` Jiri Olsa
2013-11-27 13:46 ` Namhyung Kim
2013-11-27 15:10 ` Jiri Olsa
2013-11-27 15:27 ` Jiri Olsa
2013-11-27 15:49 ` Namhyung Kim
2013-11-21 11:01 ` [PATCH 22/22] perf tools: Overload pr_stat traceevent print function Jiri Olsa
2013-11-22 15:50 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385132631.1747.68.camel@leonhard \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.