perf-probe updates
Subsystems (2)
cover perf-probe updates
Hi,
Here are bugfixes and updates for perf-probe and kprobe-tracer. I've fixed some minor bugs and added --list option and simple probe naming.
TODO:
- Support build-id checking.
- Support --del option to remove probes.
- Support --line option to show which lines user can probe.
- Support lazy string matching.
Thank you,
---
Masami Hiramatsu (9):
perf probe: Simplify event naming
perf probe: Add --list option for listing current probe events perf probe: Add argv_split() from lib/argv_split.c
perf probe: Move probe event utility functions to probe-event.c perf probe: Fix probe array index for multiple probe point perf probe: Fix argv array size in probe parser
perf probe: Fix to add probe-finder.h without libdwarf perf probe: Fix to change a debugging message from pr_info to pr_debug
trace_kprobes: Fix a memory leak bug and check kstrdup return value
kernel/trace/trace_kprobe.c | 26 ++ tools/perf/Makefile | 4 tools/perf/builtin-probe.c | 236 ++------------------ tools/perf/util/probe-event.c | 484 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/probe-event.h | 18 ++ tools/perf/util/string.c | 101 +++++++++ tools/perf/util/string.h | 2 7 files changed, 647 insertions(+), 224 deletions(-) create mode 100644 tools/perf/util/probe-event.c create mode 100644 tools/perf/util/probe-event.h
Signature · 6 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
PATCH 1/9 trace_kprobes: Fix a memory leak bug and check kstrdup return value
Fix a memory leak case in create_trace_probe(). When an argument is too long (> MAX_ARGSTR_LEN), it just jumps to error path. In that case tp->args[i].name is not released.
This also fixes a bug to check kstrdup()'s return value.
---
kernel/trace/trace_kprobe.c | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 deletions(-)
kernel/trace/trace_kprobe.c +19 -7
@@ -483,7 +483,8 @@ static int parse_probe_vars(char *arg, struct fetch_func *ff, int is_return)return ret; } -static int parse_probe_arg (char *arg,struct fetch_func *ff,int is_return) +/* Recursive argument parser */ +static int __parse_probe_arg (char *arg,struct fetch_func *ff,int is_return) {int ret =0 ;unsigned long param;
@@ -543,7 +544,7 @@ static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)if (!id)return -ENOMEM ; id->offset = offset; - ret =parse_probe_arg (arg, &id->orig, is_return); + ret =__parse_probe_arg (arg, &id->orig, is_return);if (ret)kfree (id);else {
@@ -560,6 +561,16 @@ static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)return ret; } +/* String length checking wrapper */ +static int parse_probe_arg (char *arg,struct fetch_func *ff,int is_return) +{ +if (strlen (arg) >MAX_ARGSTR_LEN ) { +pr_info ("Argument is too long.: %s\n" , arg); +return -ENOSPC ; + } +return __parse_probe_arg (arg, ff, is_return); +} +/* Return 1 if name is reserved or already used by another argument */ static int conflict_field_name (const char *name,struct probe_arg *args,int narg)
@@ -698,13 +709,14 @@ static int create_trace_probe(int argc, char **argv) } tp->args[i].name =kstrdup (argv[i],GFP_KERNEL ); - -/* Parse fetch argument */ -if (strlen (arg) >MAX_ARGSTR_LEN ) { -pr_info ("Argument%d(%s) is too long.\n" , i, arg); - ret = -ENOSPC ; +if (!tp->args[i].name) { +pr_info ("Failed to allocate argument%d name '%s'.\n" , + i, argv[i]); + ret = -ENOMEM ; goto error; } + +/* Parse fetch argument */ ret =parse_probe_arg (arg, &tp->args[i].fetch, is_return);if (ret) {pr_info ("Parse error at argument%d. (%d)\n" , i, ret);
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] trace_kprobes: Fix a memory leak bug and check kstrdup() return value
Commit-ID: ba8665d7dd95eb6093ee06f8f624b6acb1e73206 Gitweb: http://git.kernel.org/tip/ba8665d7dd95eb6093ee06f8f624b6acb1e73206 Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:19:20 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:19:59 +0100
trace_kprobes: Fix a memory leak bug and check kstrdup() return value
Fix a memory leak case in create_trace_probe(). When an argument is too long (> MAX_ARGSTR_LEN), it just jumps to error path. In that case tp->args[i].name is not released.
This also fixes a bug to check kstrdup()'s return value.
LKML-Reference: <20091201001919.10235.56455.stgit@harusame>
--- kernel/trace/trace_kprobe.c | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 deletions(-)
kernel/trace/trace_kprobe.c +19 -7
@@ -483,7 +483,8 @@ static int parse_probe_vars(char *arg, struct fetch_func *ff, int is_return)return ret; } -static int parse_probe_arg (char *arg,struct fetch_func *ff,int is_return) +/* Recursive argument parser */ +static int __parse_probe_arg (char *arg,struct fetch_func *ff,int is_return) {int ret =0 ;unsigned long param;
@@ -543,7 +544,7 @@ static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)if (!id)return -ENOMEM ; id->offset = offset; - ret =parse_probe_arg (arg, &id->orig, is_return); + ret =__parse_probe_arg (arg, &id->orig, is_return);if (ret)kfree (id);else {
@@ -560,6 +561,16 @@ static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)return ret; } +/* String length checking wrapper */ +static int parse_probe_arg (char *arg,struct fetch_func *ff,int is_return) +{ +if (strlen (arg) >MAX_ARGSTR_LEN ) { +pr_info ("Argument is too long.: %s\n" , arg); +return -ENOSPC ; + } +return __parse_probe_arg (arg, ff, is_return); +} +/* Return 1 if name is reserved or already used by another argument */ static int conflict_field_name (const char *name,struct probe_arg *args,int narg)
@@ -698,13 +709,14 @@ static int create_trace_probe(int argc, char **argv) } tp->args[i].name =kstrdup (argv[i],GFP_KERNEL ); - -/* Parse fetch argument */ -if (strlen (arg) >MAX_ARGSTR_LEN ) { -pr_info ("Argument%d(%s) is too long.\n" , i, arg); - ret = -ENOSPC ; +if (!tp->args[i].name) { +pr_info ("Failed to allocate argument%d name '%s'.\n" , + i, argv[i]); + ret = -ENOMEM ; goto error; } + +/* Parse fetch argument */ ret =parse_probe_arg (arg, &tp->args[i].fetch, is_return);if (ret) {pr_info ("Parse error at argument%d. (%d)\n" , i, ret);
PATCH 2/9 perf probe: Fix to change a debugging message from pr_info to pr_debug
In reply to Masami HiramatsuChange annoying debug-info using notice from pr_info() to pr_debug(), since the message always printed when user adds a probe point which requires debug-info.
---
tools/perf/builtin-probe.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-probe.c +1 -1
@@ -351,7 +351,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)#ifdef NO_LIBDWARF semantic_error ("Debuginfo-analysis is not supported" );#else /* !NO_LIBDWARF */ -pr_info ("Some probes require debuginfo.\n" ); +pr_debug ("Some probes require debuginfo.\n" );if (session.vmlinux) fd =open (session.vmlinux,O_RDONLY );
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Change a debugging message from pr_info to pr_debug
Commit-ID: f41b1e43c41e99c39a2222578a7806032c045c79 Gitweb: http://git.kernel.org/tip/f41b1e43c41e99c39a2222578a7806032c045c79 Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:19:27 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:00 +0100
perf probe: Change a debugging message from pr_info to pr_debug
Change annoying debug-info using notice from pr_info() to pr_debug(), since the message always printed when user adds a probe point which requires debug-info.
LKML-Reference: <20091201001927.10235.63645.stgit@harusame>
--- tools/perf/builtin-probe.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-probe.c +1 -1
@@ -351,7 +351,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)#ifdef NO_LIBDWARF semantic_error ("Debuginfo-analysis is not supported" );#else /* !NO_LIBDWARF */ -pr_info ("Some probes require debuginfo.\n" ); +pr_debug ("Some probes require debuginfo.\n" );if (session.vmlinux) fd =open (session.vmlinux,O_RDONLY );
PATCH 3/9 perf probe: Fix to add probe-finder.h without libdwarf
In reply to Masami HiramatsuAdd probe-finder.h as LIB_H without libdwarf, because that header is included even if no libdwarf.
---
tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/Makefile +1 -1
@@ -369,6 +369,7 @@ LIB_H += util/sort.h LIB_H += util/hist.h LIB_H += util/thread.h LIB_H += util/data_map.h +LIB_H += util/probe-finder.h LIB_OBJS += util/abspath.o LIB_OBJS += util/alias.o
@@ -485,7 +486,6 @@ ifneq ($(shell sh -c "(echo '\#include <libdwarf/dwarf.h>'; echo '\#include <lib BASIC_CFLAGS += -DNO_LIBDWARF else EXTLIBS += -lelf -ldwarf - LIB_H += util/probe-finder.h LIB_OBJS += util/probe-finder.o endif
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Add probe-finder.h without libdwarf
Commit-ID: 57d250df7deb3e1742fbf3cc3230119731109552 Gitweb: http://git.kernel.org/tip/57d250df7deb3e1742fbf3cc3230119731109552 Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:19:34 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:00 +0100
perf probe: Add probe-finder.h without libdwarf
Add probe-finder.h as LIB_H without libdwarf, because that header is included even if no libdwarf.
LKML-Reference: <20091201001934.10235.44656.stgit@harusame>
--- tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/Makefile +1 -1
@@ -369,6 +369,7 @@ LIB_H += util/sort.h LIB_H += util/hist.h LIB_H += util/thread.h LIB_H += util/data_map.h +LIB_H += util/probe-finder.h LIB_OBJS += util/abspath.o LIB_OBJS += util/alias.o
@@ -485,7 +486,6 @@ ifneq ($(shell sh -c "(echo '\#include <libdwarf/dwarf.h>'; echo '\#include <lib BASIC_CFLAGS += -DNO_LIBDWARF else EXTLIBS += -lelf -ldwarf - LIB_H += util/probe-finder.h LIB_OBJS += util/probe-finder.o endif
PATCH 4/9 perf probe: Fix argv array size in probe parser
In reply to Masami HiramatsuSince the syntax had been changed, probe definition needs parameters less than MAX_PROBE_ARGS + 1 (probe-point + arguments).
---
tools/perf/builtin-probe.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
tools/perf/builtin-probe.c +7 -4
@@ -151,7 +151,7 @@ static void parse_probe_point(char *arg, struct probe_point *pp)/* Parse an event definition. Note that any error must die. */ static void parse_probe_event (const char *str) { -char *argv[MAX_PROBE_ARGS +2 ];/* Event + probe + args */ +char *argv[MAX_PROBE_ARGS +1 ];/* probe + args */ int argc, i;struct probe_point *pp = &session.probes[session.nr_probe];
@@ -169,6 +169,9 @@ static void parse_probe_event(const char *str)/* Add an argument */ if (*str !='\0' ) {const char *s = str; +/* Check the limit number of arguments */ +if (argc ==MAX_PROBE_ARGS +1 ) +semantic_error ("Too many arguments" );/* Skip the argument */ while (!isspace (*str) && *str !='\0' )
@@ -178,9 +181,9 @@ static void parse_probe_event(const char *str) argv[argc] =strndup (s, str - s);if (argv[argc] ==NULL )die ("strndup" ); -if (++argc ==MAX_PROBE_ARGS ) -semantic_error ("Too many arguments" ); -pr_debug ("argv[%d]=%s\n" , argc, argv[argc -1 ]); +pr_debug ("argv[%d]=%s\n" , argc, argv[argc]); + argc++; + } }while (*str !='\0' );if (!argc)
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Fix argv array size in probe parser
Commit-ID: 74ca4c0ece52a2d19dae1bcbfc24fcfc5facfeb4 Gitweb: http://git.kernel.org/tip/74ca4c0ece52a2d19dae1bcbfc24fcfc5facfeb4 Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:19:43 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:01 +0100
perf probe: Fix argv array size in probe parser
Since the syntax has been changed, probe definition needs parameters less than MAX_PROBE_ARGS + 1 (probe-point + arguments).
LKML-Reference: <20091201001943.10235.80367.stgit@harusame>
--- tools/perf/builtin-probe.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
tools/perf/builtin-probe.c +7 -4
@@ -151,7 +151,7 @@ static void parse_probe_point(char *arg, struct probe_point *pp)/* Parse an event definition. Note that any error must die. */ static void parse_probe_event (const char *str) { -char *argv[MAX_PROBE_ARGS +2 ];/* Event + probe + args */ +char *argv[MAX_PROBE_ARGS +1 ];/* probe + args */ int argc, i;struct probe_point *pp = &session.probes[session.nr_probe];
@@ -169,6 +169,9 @@ static void parse_probe_event(const char *str)/* Add an argument */ if (*str !='\0' ) {const char *s = str; +/* Check the limit number of arguments */ +if (argc ==MAX_PROBE_ARGS +1 ) +semantic_error ("Too many arguments" );/* Skip the argument */ while (!isspace (*str) && *str !='\0' )
@@ -178,9 +181,9 @@ static void parse_probe_event(const char *str) argv[argc] =strndup (s, str - s);if (argv[argc] ==NULL )die ("strndup" ); -if (++argc ==MAX_PROBE_ARGS ) -semantic_error ("Too many arguments" ); -pr_debug ("argv[%d]=%s\n" , argc, argv[argc -1 ]); +pr_debug ("argv[%d]=%s\n" , argc, argv[argc]); + argc++; + } }while (*str !='\0' );if (!argc)
PATCH 5/9 perf probe: Fix probe array index for multiple probe point
In reply to Masami HiramatsuFix the index of formatted probe array for multiple probe point, which should be probes[i] instead of probes[0].
---
tools/perf/builtin-probe.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-probe.c +1 -1
@@ -428,7 +428,7 @@ end_dwarf: pp->retprobe ?'r' :'p' ,PERFPROBE_GROUP , pp->function, pp->offset, i, - pp->probes[0]); + pp->probes[i]);write_new_event (fd, buf); } }
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Fix probe array index for multiple probe points
Commit-ID: 934b1f5fd0c9a2ddde5a4487695c126243d9a42b Gitweb: http://git.kernel.org/tip/934b1f5fd0c9a2ddde5a4487695c126243d9a42b Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:19:51 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:01 +0100
perf probe: Fix probe array index for multiple probe points
Fix the index of formatted probe array for multiple probe points, which should be probes[i] instead of probes[0].
LKML-Reference: <20091201001950.10235.54781.stgit@harusame>
--- tools/perf/builtin-probe.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-probe.c +1 -1
@@ -428,7 +428,7 @@ end_dwarf: pp->retprobe ?'r' :'p' ,PERFPROBE_GROUP , pp->function, pp->offset, i, - pp->probes[0]); + pp->probes[i]);write_new_event (fd, buf); } }
PATCH 6/9 perf probe: Move probe event utility functions to probe-event.c
In reply to Masami HiramatsuSplit probe event (kprobe-events and perf probe events) utility functions from builtin-probe.c to probe-event.c.
---
tools/perf/Makefile | 2 tools/perf/builtin-probe.c | 227 +--------------------------------- tools/perf/util/probe-event.c | 273 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/probe-event.h | 10 ++ 4 files changed, 294 insertions(+), 218 deletions(-) create mode 100644 tools/perf/util/probe-event.c create mode 100644 tools/perf/util/probe-event.h
tools/perf/Makefile +2 -0
@@ -370,6 +370,7 @@ LIB_H += util/hist.h LIB_H += util/thread.h LIB_H += util/data_map.h LIB_H += util/probe-finder.h +LIB_H += util/probe-event.h LIB_OBJS += util/abspath.o LIB_OBJS += util/alias.o
@@ -412,6 +413,7 @@ LIB_OBJS += util/svghelper.o LIB_OBJS += util/sort.o LIB_OBJS += util/hist.o LIB_OBJS += util/data_map.o +LIB_OBJS += util/probe-event.o BUILTIN_OBJS += builtin-annotate.o
tools/perf/builtin-probe.c +9 -218
285 lines not on this page · raw message
tools/perf/util/probe-event.c new file +273 -0
273 lines not on this page · raw message
tools/perf/util/probe-event.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef _PROBE_EVENT_H +#define _PROBE_EVENT_H + +#include "probe-finder.h" + +extern int parse_perf_probe_event (const char *str,struct probe_point *pp); +extern int synthesize_trace_kprobe_event (struct probe_point *pp); +extern void add_trace_kprobe_events (struct probe_point *probes,int nr_probes); + +#endif /*_PROBE_EVENT_H */
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Move probe event utility functions to probe-event.c
Commit-ID: 50656eec82684d03add0f4f4b4875a20bd8f9755 Gitweb: http://git.kernel.org/tip/50656eec82684d03add0f4f4b4875a20bd8f9755 Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:19:58 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:01 +0100
perf probe: Move probe event utility functions to probe-event.c
Split probe event (kprobe-events and perf probe events) utility functions from builtin-probe.c to probe-event.c.
LKML-Reference: <20091201001958.10235.90243.stgit@harusame>
--- tools/perf/Makefile | 2 + tools/perf/builtin-probe.c | 227 ++-------------------------------- tools/perf/util/probe-event.c | 273 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/probe-event.h | 10 ++ 4 files changed, 294 insertions(+), 218 deletions(-)
tools/perf/Makefile +2 -0
@@ -370,6 +370,7 @@ LIB_H += util/hist.h LIB_H += util/thread.h LIB_H += util/data_map.h LIB_H += util/probe-finder.h +LIB_H += util/probe-event.h LIB_OBJS += util/abspath.o LIB_OBJS += util/alias.o
@@ -412,6 +413,7 @@ LIB_OBJS += util/svghelper.o LIB_OBJS += util/sort.o LIB_OBJS += util/hist.o LIB_OBJS += util/data_map.o +LIB_OBJS += util/probe-event.o BUILTIN_OBJS += builtin-annotate.o
tools/perf/builtin-probe.c +9 -218
285 lines not on this page · raw message
tools/perf/util/probe-event.c new file +273 -0
273 lines not on this page · raw message
tools/perf/util/probe-event.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef _PROBE_EVENT_H +#define _PROBE_EVENT_H + +#include "probe-finder.h" + +extern int parse_perf_probe_event (const char *str,struct probe_point *pp); +extern int synthesize_trace_kprobe_event (struct probe_point *pp); +extern void add_trace_kprobe_events (struct probe_point *probes,int nr_probes); + +#endif /*_PROBE_EVENT_H */
PATCH 7/9 perf probe: Add argv_split() from lib/argv_split.c
In reply to Masami HiramatsuAdd argv_split() ported from lib/argv_split.c to string.c and use it in util/probe-event.c.
---
tools/perf/util/probe-event.c | 55 ++++++---------------- tools/perf/util/string.c | 101 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/string.h | 2 + 3 files changed, 118 insertions(+), 40 deletions(-)
tools/perf/util/probe-event.c +15 -40
@@ -32,6 +32,7 @@#undef _GNU_SOURCE#include "event.h" +#include "string.h" #include "debug.h" #include "parse-events.h" /* For debugfs_path */ #include "probe-event.h"
@@ -132,62 +133,36 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)/* Parse perf-probe event definition */ int parse_perf_probe_event (const char *str,struct probe_point *pp) { -char *argv[MAX_PROBE_ARGS +1 ];/* probe + args */ +char **argv;int argc, i, need_dwarf =0 ; -/* Separate arguments, similar to argv_split */ - argc =0 ; -do { -/* Skip separators */ -while (isspace (*str)) - str++; - -/* Add an argument */ -if (*str !='\0' ) { -const char *s = str; -/* Check the limit number of arguments */ -if (argc ==MAX_PROBE_ARGS +1 ) -semantic_error ("Too many arguments" ); - -/* Skip the argument */ -while (!isspace (*str) && *str !='\0' ) - str++; - -/* Duplicate the argument */ - argv[argc] =strndup (s, str - s); -if (argv[argc] ==NULL ) -die ("strndup" ); -pr_debug ("argv[%d]=%s\n" , argc, argv[argc]); - argc++; - } - }while (*str !='\0' ); -if (!argc) -semantic_error ("An empty argument." ); + argv =argv_split (str, &argc); +if (!argv) +die ("argv_split failed." ); +if (argc >MAX_PROBE_ARGS +1 ) +semantic_error ("Too many arguments" );/* Parse probe point */ parse_perf_probe_probepoint (argv[0 ], pp); -free (argv[0 ]);if (pp->file || pp->line) need_dwarf =1 ; -/* Copy arguments */ +/* Copy arguments and ensure return probe has no C argument */ pp->nr_args = argc -1 ; -if (pp->nr_args >0 ) { - pp->args = (char **)malloc (sizeof (char *) * pp->nr_args); -if (!pp->args) -die ("malloc" ); -memcpy (pp->args, &argv[1 ],sizeof (char *) * pp->nr_args); - } - -/* Ensure return probe has no C argument */ -for (i =0 ; i < pp->nr_args; i++) + pp->args =zalloc (sizeof (char *) * pp->nr_args); +for (i =0 ; i < pp->nr_args; i++) { + pp->args[i] =strdup (argv[i +1 ]); +if (!pp->args[i]) +die ("Failed to copy argument." );if (is_c_varname (pp->args[i])) {if (pp->retprobe)semantic_error ("You can't specify local" " variable for kretprobe" ); need_dwarf =1 ; } + } +argv_free (argv);return need_dwarf; }
tools/perf/util/string.c +101 -0
104 lines not on this page · raw message
tools/perf/util/string.h +2 -0
@@ -6,6 +6,8 @@int hex2u64 (const char *ptr,u64 *val);char *strxfrchar (char *s,char from,char to);s64 perf_atoll (const char *str); +char **argv_split (const char *str,int *argcp); +void argv_free (char **argv);#define _STR (x) #x#define STR (x) _STR(x)
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Add argv_split() from lib/argv_split.c
Commit-ID: e1c01d61a98703fcc80d15b8068ec36d5a215f7e Gitweb: http://git.kernel.org/tip/e1c01d61a98703fcc80d15b8068ec36d5a215f7e Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:20:05 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:02 +0100
perf probe: Add argv_split() from lib/argv_split.c
Add argv_split() ported from lib/argv_split.c to string.c and use it in util/probe-event.c.
LKML-Reference: <20091201002005.10235.55602.stgit@harusame>
--- tools/perf/util/probe-event.c | 55 ++++++---------------- tools/perf/util/string.c | 101 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/string.h | 2 + 3 files changed, 118 insertions(+), 40 deletions(-)
tools/perf/util/probe-event.c +15 -40
@@ -32,6 +32,7 @@#undef _GNU_SOURCE#include "event.h" +#include "string.h" #include "debug.h" #include "parse-events.h" /* For debugfs_path */ #include "probe-event.h"
@@ -132,62 +133,36 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)/* Parse perf-probe event definition */ int parse_perf_probe_event (const char *str,struct probe_point *pp) { -char *argv[MAX_PROBE_ARGS +1 ];/* probe + args */ +char **argv;int argc, i, need_dwarf =0 ; -/* Separate arguments, similar to argv_split */ - argc =0 ; -do { -/* Skip separators */ -while (isspace (*str)) - str++; - -/* Add an argument */ -if (*str !='\0' ) { -const char *s = str; -/* Check the limit number of arguments */ -if (argc ==MAX_PROBE_ARGS +1 ) -semantic_error ("Too many arguments" ); - -/* Skip the argument */ -while (!isspace (*str) && *str !='\0' ) - str++; - -/* Duplicate the argument */ - argv[argc] =strndup (s, str - s); -if (argv[argc] ==NULL ) -die ("strndup" ); -pr_debug ("argv[%d]=%s\n" , argc, argv[argc]); - argc++; - } - }while (*str !='\0' ); -if (!argc) -semantic_error ("An empty argument." ); + argv =argv_split (str, &argc); +if (!argv) +die ("argv_split failed." ); +if (argc >MAX_PROBE_ARGS +1 ) +semantic_error ("Too many arguments" );/* Parse probe point */ parse_perf_probe_probepoint (argv[0 ], pp); -free (argv[0 ]);if (pp->file || pp->line) need_dwarf =1 ; -/* Copy arguments */ +/* Copy arguments and ensure return probe has no C argument */ pp->nr_args = argc -1 ; -if (pp->nr_args >0 ) { - pp->args = (char **)malloc (sizeof (char *) * pp->nr_args); -if (!pp->args) -die ("malloc" ); -memcpy (pp->args, &argv[1 ],sizeof (char *) * pp->nr_args); - } - -/* Ensure return probe has no C argument */ -for (i =0 ; i < pp->nr_args; i++) + pp->args =zalloc (sizeof (char *) * pp->nr_args); +for (i =0 ; i < pp->nr_args; i++) { + pp->args[i] =strdup (argv[i +1 ]); +if (!pp->args[i]) +die ("Failed to copy argument." );if (is_c_varname (pp->args[i])) {if (pp->retprobe)semantic_error ("You can't specify local" " variable for kretprobe" ); need_dwarf =1 ; } + } +argv_free (argv);return need_dwarf; }
tools/perf/util/string.c +101 -0
104 lines not on this page · raw message
tools/perf/util/string.h +2 -0
@@ -6,6 +6,8 @@int hex2u64 (const char *ptr,u64 *val);char *strxfrchar (char *s,char from,char to);s64 perf_atoll (const char *str); +char **argv_split (const char *str,int *argcp); +void argv_free (char **argv);#define _STR (x) #x#define STR (x) _STR(x)
Re: [tip:perf/core] perf probe: Add argv_split() from lib/argv_split.c
Hi Masami,
tip-bot for Masami Hiramatsu wrote:
...
Quoted 85 lines
tools/perf/util/string.c +77
-0@@ -127,3 +127,104 @@ out_err: out:return length; } + +/* +* Helper function for splitting a string into an argv-like array. +* originaly copied from lib/argv_split.c +*/ +static const char *skip_sep (const char *cp) +{ +while (*cp &&isspace (*cp)) + cp++; + +return cp; +} + +static const char *skip_arg (const char *cp) +{ +while (*cp && !isspace (*cp)) + cp++; + +return cp; +} + +static int count_argc (const char *str) +{ +int count =0 ; + +while (*str) { + str =skip_sep (str); +if (*str) { + count++; + str =skip_arg (str); + } + } + +return count; +} + +/** +* argv_free - free an argv +* @argv - the argument vector to be freed +* +* Frees an argv and the strings it points to. +*/ +void argv_free (char **argv) +{ +char **p; +for (p = argv; *p; p++) +free (*p); + +free (argv); +} + +/** +* argv_split - split a string at whitespace, returning an argv +* @str: the string to be split +* @argcp: returned argument count +* +* Returns an array of pointers to strings which are split out from +* @str. This is performed by strictly splitting on white-space; no +* quote processing is performed. Multiple whitespace characters are +* considered to be a single argument separator. The returned array +* is always NULL-terminated. Returns NULL on memory allocation +* failure. +*/ +char **argv_split (const char *str,int *argcp) +{ +int argc =count_argc (str); +char **argv =zalloc (sizeof (*argv) * (argc+1 )); +char **argvp; + +if (argv ==NULL ) + goto out; + +if (argcp) + *argcp = argc; + + argvp = argv; +
tools/perf/util/string.c out_err: · line 216
Quoted 10 lines
tools/perf/util/string.c +10
-0+while (*str) { + str =skip_sep (str); + +if (*str) { +const char *p = str; +char *t; + + str =skip_arg (str); + + t =strndup (p, str-p);
When I compiled "perf", I encountered following error:
CC util/string.o
cc1: warnings being treated as errorsutil/string.c: In function 'argv_split':util/string.c:216: warning: implicit declaration of function 'strndup' util/string.c:216: warning: incompatible implicit declaration of built-in function 'strndup'
make: *** [util/string.o] Error 1
Do we need to define _GNU_SOURCE in the head? Or maybe I used rather old glibc version.
tools/perf/util/string.c +3 -0
@@ -1,5 +1,8 @@ +#define _GNU_SOURCE#include <string.h> #include <stdlib.h> + +#undef _GNU_SOURCE#include "string.h" #include "util.h"
Frederic Weisbecker
Acked-byRe: [tip:perf/core] perf probe: Add argv_split() from lib/argv_split.c
Quoted 18 lines · Wang Liming
When I compiled "perf", I encountered following error:
CC
util/string.o
cc1: warnings being treated as errorsutil/string.c: In function 'argv_split':util/string.c:216: warning: implicit declaration of function 'strndup'util/string.c:216: warning: incompatible implicit declaration of built-in function 'strndup'
make: *** [util/string.o] Error 1Do we need to define
_GNU_SOURCEin the head? Or maybe I used rather old glibc version.tools/perf/util/string.c +0
-0
tools/perf/util/string.c line 7
Quoted 7 lines
tools/perf/util/string.c +3
-0@@ -1,5 +1,8 @@ +#define _GNU_SOURCE#include <string.h> #include <stdlib.h> + +#undef _GNU_SOURCE#include "string.h" #include "util.h"
Right, strndup is a GNU extension.
Could you please resend this patch with your signed-off-by and a proper changelog?
Thanks!
PATCH 8/9 perf probe: Add --list option for listing current probe events
In reply to Masami HiramatsuAdd --list option for listing currently defined probe events in the kernel. This shows events in below format;
[group:event] <perf-probe probe-definition>
e.g.
[probe:schedule_0] schedule+30 cpu
Note that source file/line information is not supported yet. So even if you added a probe by line, it will be shown in <symbol+offset>.
---
tools/perf/builtin-probe.c | 12 ++ tools/perf/util/probe-event.c | 231 ++++++++++++++++++++++++++++++++++++++--- tools/perf/util/probe-event.h | 5 + 3 files changed, 230 insertions(+), 18 deletions(-)
tools/perf/builtin-probe.c +11 -1
@@ -62,6 +62,8 @@ static struct {struct probe_point probes[MAX_PROBES ]; } session; +static bool listing; +/* Parse an event definition. Note that any error must die. */ static void parse_probe_event (const char *str) {
@@ -119,6 +121,7 @@ static int open_default_vmlinux(void)static const char *const probe_usage[] = {"perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]" ,"perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]" , +"perf probe --list" ,NULL };
@@ -129,6 +132,7 @@ static const struct option options[] = {OPT_STRING ('k' ,"vmlinux" , &session.vmlinux,"file" ,"vmlinux/module pathname" ), #endif +OPT_BOOLEAN ('l' ,"list" , &listing,"list up current probes" ), OPT_CALLBACK('a', "add", NULL, #ifdef NO_LIBDWARF "FUNC[+OFFS|%return] [ARG ...]",
@@ -164,9 +168,15 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)for (i =0 ; i < argc; i++)parse_probe_event (argv[i]); -if (session.nr_probe ==0 ) +if ((session.nr_probe ==0 && !listing) || + (session.nr_probe !=0 && listing))usage_with_options (probe_usage, options); +if (listing) { +show_perf_probe_events (); +return 0 ; + } + if (session.need_dwarf)#ifdef NO_LIBDWARF die ("Debuginfo-analysis is not supported" );
tools/perf/util/probe-event.c +214 -17
279 lines not on this page · raw message
tools/perf/util/probe-event.h +5 -0
@@ -2,9 +2,14 @@#define _PROBE_EVENT_H#include "probe-finder.h" +#include "strlist.h" extern int parse_perf_probe_event (const char *str,struct probe_point *pp); +extern int synthesize_perf_probe_event (struct probe_point *pp); +extern void parse_trace_kprobe_event (const char *str,char **group, +char **event,struct probe_point *pp);extern int synthesize_trace_kprobe_event (struct probe_point *pp);extern void add_trace_kprobe_events (struct probe_point *probes,int nr_probes); +extern void show_perf_probe_events (void );#endif /*_PROBE_EVENT_H */
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Add --list option for listing current probe events
Commit-ID: 4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33a Gitweb: http://git.kernel.org/tip/4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33a Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:20:17 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:02 +0100
perf probe: Add --list option for listing current probe events
Add --list option for listing currently defined probe events in the kernel. This shows events in below format;
[group:event] <perf-probe probe-definition>
for example:
[probe:schedule_0] schedule+30 cpu
Note that source file/line information is not supported yet. So even if you added a probe by line, it will be shown in <symbol+offset>.
LKML-Reference: <20091201002017.10235.76575.stgit@harusame>
--- tools/perf/builtin-probe.c | 12 ++- tools/perf/util/probe-event.c | 231 ++++++++++++++++++++++++++++++++++++++--- tools/perf/util/probe-event.h | 5 + 3 files changed, 230 insertions(+), 18 deletions(-)
tools/perf/builtin-probe.c +11 -1
@@ -62,6 +62,8 @@ static struct {struct probe_point probes[MAX_PROBES ]; } session; +static bool listing; +/* Parse an event definition. Note that any error must die. */ static void parse_probe_event (const char *str) {
@@ -119,6 +121,7 @@ static int open_default_vmlinux(void)static const char *const probe_usage[] = {"perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]" ,"perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]" , +"perf probe --list" ,NULL };
@@ -129,6 +132,7 @@ static const struct option options[] = {OPT_STRING ('k' ,"vmlinux" , &session.vmlinux,"file" ,"vmlinux/module pathname" ), #endif +OPT_BOOLEAN ('l' ,"list" , &listing,"list up current probes" ), OPT_CALLBACK('a', "add", NULL, #ifdef NO_LIBDWARF "FUNC[+OFFS|%return] [ARG ...]",
@@ -164,9 +168,15 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)for (i =0 ; i < argc; i++)parse_probe_event (argv[i]); -if (session.nr_probe ==0 ) +if ((session.nr_probe ==0 && !listing) || + (session.nr_probe !=0 && listing))usage_with_options (probe_usage, options); +if (listing) { +show_perf_probe_events (); +return 0 ; + } + if (session.need_dwarf)#ifdef NO_LIBDWARF die ("Debuginfo-analysis is not supported" );
tools/perf/util/probe-event.c +214 -17
279 lines not on this page · raw message
tools/perf/util/probe-event.h +5 -0
@@ -2,9 +2,14 @@#define _PROBE_EVENT_H#include "probe-finder.h" +#include "strlist.h" extern int parse_perf_probe_event (const char *str,struct probe_point *pp); +extern int synthesize_perf_probe_event (struct probe_point *pp); +extern void parse_trace_kprobe_event (const char *str,char **group, +char **event,struct probe_point *pp);extern int synthesize_trace_kprobe_event (struct probe_point *pp);extern void add_trace_kprobe_events (struct probe_point *probes,int nr_probes); +extern void show_perf_probe_events (void );#endif /*_PROBE_EVENT_H */
Re: [tip:perf/core] perf probe: Add --list option for listing current probe events
Hi Masami,
Quoted 21 lines · tip-bot for Masami Hiramatsu
Commit-ID: 4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33a Gitweb: http://git.kernel.org/tip/4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33a Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:20:17 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:02 +0100perf probe: Add --list option for listing current probe events
Add --list option for listing currently defined probe events in the kernel. This shows events in below format;
[group:event] <perf-probe probe-definition>
for example:
[probe:schedule_0] schedule+30 cpu
Note that source file/line information is not supported yet. So even if you added a probe by line, it will be shown in <symbol+offset>.
...
Review
Quoted 4 lines
(quoted diff) +4
-0+ + /* Scan event and group name. */ + ret = sscanf(argv[0], "%c:%m[^/ \t]/%m[^ \t]", + &pr, group, event);
"%m" are typos?
Review
Quoted 11 lines
(quoted diff) +11
-0+ if (ret != 3) + semantic_error("Failed to parse event name: %s", argv[0]); + pr_debug("Group:%s Event:%s probe:%c\n", *group, *event, pr); + + if (!pp) + goto end; + + pp->retprobe = (pr == 'r'); + + /* Scan function name and offset */ + ret = sscanf(argv[1], "%m[^+]+%d", &pp->function, &pp->offset);
the same error? fix attached below.
--
tools/perf/util/probe-event.c +3 -3
@@ -199,8 +199,8 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,semantic_error ("Too less arguments." );/* Scan event and group name. */ - ret =sscanf (argv[0 ],"%c:%m[^/ \t]/%m[^ \t]" , - &pr, group, event); + ret =sscanf (argv[0 ],"%c:%s[^/ \t]/%s[^ \t]" , + &pr, *group, *event);if (ret !=3 )semantic_error ("Failed to parse event name: %s" , argv[0 ]);pr_debug ("Group:%s Event:%s probe:%c\n" , *group, *event, pr);
@@ -211,7 +211,7 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event, pp->retprobe = (pr =='r' );/* Scan function name and offset */ - ret =sscanf (argv[1 ],"%m[^+]+%d" , &pp->function, &pp->offset); + ret =sscanf (argv[1 ],"%s[^+]+%d" , pp->function, &pp->offset);if (ret ==1 ) pp->offset =0 ;
Re: [tip:perf/core] perf probe: Add --list option for listing current probe events
Quoted 25 lines · Wang Liming
Hi Masami,
Quoted 15 lines · tip-bot for Masami Hiramatsu
Commit-ID:
4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33aGitweb:
http://git.kernel.org/tip/4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33aAuthor: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:20:17 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:02 +0100perf probe: Add --list option for listing current probe events
Add --list option for listing currently defined probe events in the kernel. This shows events in below format;
[group:event] <perf-probe probe-definition>
Quoted 7 lines
for example:
[probe:schedule_0] schedule+30 cpu
Note that source file/line information is not supported yet. So even if you added a probe by line, it will be shown in <symbol+offset>.
Quoted 6 lines
...
Review
Quoted 4 lines
(quoted diff) +4
-0+ + /* Scan event and group name. */ + ret = sscanf(argv[0], "%c:%m[^/ \t]/%m[^ \t]", + &pr, group, event);"%m" are typos?
No, %m is glibc extension of sscanf modifier, which allocate memory for scanned string in sscanf. You can see "man sscanf" if your glibc is not so old (hopefully..). Please refer below;
http://www.kernel.org/doc/man-pages/online/pages/man3/scanf.3.html#NOTES
Anyway, thank you for reviewing!
Quoted 44 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+ if (ret != 3) + semantic_error("Failed to parse event name: %s", argv[0]); + pr_debug("Group:%s Event:%s probe:%c\n", *group, *event, pr); + + if (!pp) + goto end; + + pp->retprobe = (pr == 'r'); + + /* Scan function name and offset */ + ret = sscanf(argv[1], "%m[^+]+%d", &pp->function, &pp->offset);the same error? fix attached below.
tools/perf/util/probe-event.c +2
-2@@ -199,8 +199,8 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,semantic_error ("Too less arguments." );/* Scan event and group name. */ - ret =sscanf (argv[0 ],"%c:%m[^/ \t]/%m[^ \t]" , - &pr, group, event); + ret =sscanf (argv[0 ],"%c:%s[^/ \t]/%s[^ \t]" , + &pr, *group, *event);if (ret !=3 )semantic_error ("Failed to parse event name: %s" , argv[0 ]);pr_debug("Group:%s Event:%s probe:%c\n", *group, *event, pr);tools/perf/util/probe-event.c +1
-1@@ -211,7 +211,7 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event, pp->retprobe = (pr =='r' );/* Scan function name and offset */ - ret =sscanf (argv[1 ],"%m[^+]+%d" , &pp->function, &pp->offset); + ret =sscanf (argv[1 ],"%s[^+]+%d" , pp->function, &pp->offset);if (ret ==1 ) pp->offset =0 ;
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Re: [tip:perf/core] perf probe: Add --list option for listing current probe events
Quoted 30 lines · Masami Hiramatsu
Quoted 29 lines · Wang Liming
Hi Masami,
Quoted 21 lines · tip-bot for Masami Hiramatsu
Commit-ID: 4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33a Gitweb: http://git.kernel.org/tip/4de189fe6e5ad8241f6f8709d2e2ba4c3aeae33a Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:20:17 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:02 +0100perf probe: Add --list option for listing current probe events
Add --list option for listing currently defined probe events in the kernel. This shows events in below format;
[group:event] <perf-probe probe-definition>
for example:
[probe:schedule_0] schedule+30 cpu
Note that source file/line information is not supported yet. So even if you added a probe by line, it will be shown in <symbol+offset>.
...
Quoted 4 lines
(quoted diff) +4
-0+ + /* Scan event and group name. */ + ret = sscanf(argv[0], "%c:%m[^/ \t]/%m[^ \t]", + &pr, group, event);
Quoted 7 lines
Quoted 1 line
"%m" are typos?
No, %m is glibc extension of sscanf modifier, which allocate memory for scanned string in sscanf. You can see "man sscanf" if your glibc is not so old (hopefully..). Please refer below;
http://www.kernel.org/doc/man-pages/online/pages/man3/scanf.3.html#NOTES
Yes, my glibc is old so that "perf" can't be built. I'm using ubuntu 8.04.
Thanks a lot.
Quoted 48 lines
Anyway, thank you for reviewing!
Quoted 44 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+ if (ret != 3) + semantic_error("Failed to parse event name: %s", argv[0]); + pr_debug("Group:%s Event:%s probe:%c\n", *group, *event, pr); + + if (!pp) + goto end; + + pp->retprobe = (pr == 'r'); + + /* Scan function name and offset */ + ret = sscanf(argv[1], "%m[^+]+%d", &pp->function, &pp->offset);the same error? fix attached below.
tools/perf/util/probe-event.c +2
-2@@ -199,8 +199,8 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,semantic_error ("Too less arguments." );/* Scan event and group name. */ - ret =sscanf (argv[0 ],"%c:%m[^/ \t]/%m[^ \t]" , - &pr, group, event); + ret =sscanf (argv[0 ],"%c:%s[^/ \t]/%s[^ \t]" , + &pr, *group, *event);if (ret !=3 )semantic_error ("Failed to parse event name: %s" , argv[0 ]);pr_debug("Group:%s Event:%s probe:%c\n", *group, *event, pr);tools/perf/util/probe-event.c +1
-1@@ -211,7 +211,7 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event, pp->retprobe = (pr =='r' );/* Scan function name and offset */ - ret =sscanf (argv[1 ],"%m[^+]+%d" , &pp->function, &pp->offset); + ret =sscanf (argv[1 ],"%s[^+]+%d" , pp->function, &pp->offset);if (ret ==1 ) pp->offset =0 ;
Re: [tip:perf/core] perf probe: Add --list option for listing current probe events
Quoted 3 lines · Wang Liming
Yes, my glibc is old so that "perf" can't be built. I'm using ubuntu 8.04.
Thanks a lot.
What is your glibc version?
%m appears to be supported since 2.7
But if possible we would like perf to be buildable on most boxes. May be should we use %a instead there.
odd gcc versions will whine because of the confusion with the %a for floating point things but that can be worked around with (float *) casts (sigh). Well, since we also have strict aliasing checks, we'll actually need:
scanf("%a", (float *)(void *)str);
We do that in util/trace-event-parse.c
Re: [tip:perf/core] perf probe: Add --list option for listing current probe events
Quoted 9 lines · Frederic Weisbecker
Quoted 3 lines · Wang Liming
Yes, my glibc is old so that "perf" can't be built. I'm using ubuntu 8.04.
Thanks a lot.
What is your glibc version?
%m appears to be supported since 2.7
I'm using ubuntu 8.04, and glibc version seems to be 2.7.
$dpkg -l |grep libc|less
ii libc6 2.7-10ubuntu4
GNU C Library: Shared libraries
ii libc6-dev 2.7-10ubuntu4
GNU C Library: Development Libraries and Header
$gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Quoted 3 lines
But if possible we would like perf to be buildable on most boxes. May be should we use %a instead there.
I think so. We couldn't assume that all users use the latest glibc.
Liming Wang
Quoted 10 lines
odd gcc versions will whine because of the confusion with the %a for floating point things but that can be worked around with (float *) casts (sigh). Well, since we also have strict aliasing checks, we'll actually need:
scanf("%a", (float *)(void *)str);We do that in
util/trace-event-parse.c
Re: [tip:perf/core] perf probe: Add --list option for listing current probe events
In reply to Frederic WeisbeckerQuoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Wang Liming
Yes, my glibc is old so that "perf" can't be built. I'm using ubuntu 8.04.
Thanks a lot.
Quoted 5 lines
What is your glibc version?
%m appears to be supported since 2.7But if possible we would like perf to be buildable on most boxes. May be should we use %a instead there.
Definitely so.
Wang, mind sending a patch for that?
Thanks,
Ingo
PATCH 1/1 perf tools: replace %m with %a in sscanf
Not all glibc support %m and it results in a compile error if %m not supported. Replace it with %a and (float *) casts.
--- tools/perf/util/probe-event.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/probe-event.c +3 -3
@@ -199,8 +199,8 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,semantic_error ("Too less arguments." );/* Scan event and group name. */ - ret =sscanf (argv[0 ],"%c:%m[^/ \t]/%m[^ \t]" , - &pr, group, event); + ret =sscanf (argv[0 ],"%c:%a[^/ \t]/%a[^ \t]" , + &pr, (float *)(void *)group, (float *)(void *)event);if (ret !=3 )semantic_error ("Failed to parse event name: %s" , argv[0 ]);pr_debug ("Group:%s Event:%s probe:%c\n" , *group, *event, pr);
@@ -211,7 +211,7 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event, pp->retprobe = (pr =='r' );/* Scan function name and offset */ - ret =sscanf (argv[1 ],"%m[^+]+%d" , &pp->function, &pp->offset); + ret =sscanf (argv[1 ],"%a[^+]+%d" , (float *)(void *)&pp->function, &pp->offset);if (ret ==1 ) pp->offset =0 ;
Signature · 1 line
1.6.0.3
[tip:perf/core] perf tools: Replace %m with %a in sscanf
Commit-ID: 93aaa45a6ad3f983180223601fc663cc551ad499 Gitweb: http://git.kernel.org/tip/93aaa45a6ad3f983180223601fc663cc551ad499 Author: Liming Wang <[email protected]> AuthorDate: Wed, 2 Dec 2009 16:42:54 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 2 Dec 2009 10:12:16 +0100
perf tools: Replace %m with %a in sscanf
Not all glibc support %m and it results in a compile error if %m not supported. Replace it with %a and (float *) casts.
LKML-Reference: <[email protected]>
--- tools/perf/util/probe-event.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/probe-event.c +3 -3
@@ -199,8 +199,8 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,semantic_error ("Too less arguments." );/* Scan event and group name. */ - ret =sscanf (argv[0 ],"%c:%m[^/ \t]/%m[^ \t]" , - &pr, group, event); + ret =sscanf (argv[0 ],"%c:%a[^/ \t]/%a[^ \t]" , + &pr, (float *)(void *)group, (float *)(void *)event);if (ret !=3 )semantic_error ("Failed to parse event name: %s" , argv[0 ]);pr_debug ("Group:%s Event:%s probe:%c\n" , *group, *event, pr);
@@ -211,7 +211,7 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event, pp->retprobe = (pr =='r' );/* Scan function name and offset */ - ret =sscanf (argv[1 ],"%m[^+]+%d" , &pp->function, &pp->offset); + ret =sscanf (argv[1 ],"%a[^+]+%d" , (float *)(void *)&pp->function, &pp->offset);if (ret ==1 ) pp->offset =0 ;
Re: [PATCH] perf tools: replace %m with %a in sscanf
In reply to Liming WangQuoted 14 lines · Liming Wang
Not all glibc support %m and it results in a compile error if %m not supported. Replace it with %a and (float *) casts.
Signed-off-by Liming Wang<[email protected]>--- tools/perf/util/probe-event.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)tools/perf/util/probe-event.c +0
-0
tools/perf/util/probe-event.c void parse_trace_kprobe_event(const char *str, char **group, char **event, · line 203
Quoted 7 lines
tools/perf/util/probe-event.c +2
-2@@ -199,8 +199,8 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,semantic_error ("Too less arguments." );/* Scan event and group name. */ - ret =sscanf (argv[0 ],"%c:%m[^/ \t]/%m[^ \t]" , - &pr, group, event); + ret =sscanf (argv[0 ],"%c:%a[^/ \t]/%a[^ \t]" , + &pr, (float *)(void *)group, (float *)(void *)event);
Hmm, the code itself is OK for me, but I think we need a comment why we cast (void *) to (float *)...
Thank you,
Quoted 12 lines
tools/perf/util/probe-event.c +1
-1if (ret !=3 )semantic_error ("Failed to parse event name: %s" , argv[0 ]);pr_debug ("Group:%s Event:%s probe:%c\n" , *group, *event, pr);@@ -211,7 +211,7 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event, pp->retprobe = (pr =='r' );/* Scan function name and offset */ - ret =sscanf (argv[1 ],"%m[^+]+%d" ,&pp->function,&pp->offset); + ret =sscanf (argv[1 ],"%a[^+]+%d" , (float *)(void *)&pp->function,&pp->offset);if (ret ==1 ) pp->offset =0 ;
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
PATCH 9/9 perf probe: Simplify event naming
In reply to Masami HiramatsuSimplify event naming as <symbol>_<seqnum>. Each event name is globally unique (group name is not checked). So, if there is schedule_0, next probe event on schedule() will be schedule_1.
---
tools/perf/util/probe-event.c | 67 ++++++++++++++++++++++++++++++++--------- tools/perf/util/probe-event.h | 3 ++ 2 files changed, 56 insertions(+), 14 deletions(-)
tools/perf/util/probe-event.c +53 -14
@@ -403,6 +403,29 @@ void show_perf_probe_events(void)strlist__delete (rawlist); } +/* Get current perf-probe event names */ +static struct strlist *get_perf_event_names (int fd) +{ +unsigned int i; +char *group, *event; +struct strlist *sl, *rawlist; +struct str_node *ent; + + rawlist =get_trace_kprobe_event_rawlist (fd); + + sl =strlist__new (false,NULL ); +for (i =0 ; i <strlist__nr_entries (rawlist); i++) { + ent =strlist__entry (rawlist, i); +parse_trace_kprobe_event (ent->s, &group, &event,NULL ); +strlist__add (sl, event); +free (group); + } + +strlist__delete (rawlist); + +return sl; +} +static int write_trace_kprobe_event (int fd,const char *buf) {int ret;
@@ -416,30 +439,46 @@ static int write_trace_kprobe_event(int fd, const char *buf)return ret; } +static void get_new_event_name (char *buf,size_t len,const char *base, +struct strlist *namelist) +{ +int i, ret; +for (i =0 ; i <MAX_EVENT_INDEX ; i++) { + ret =e_snprintf (buf, len,"%s_%d" , base, i); +if (ret <0 ) +die ("snprintf() failed: %s" ,strerror (-ret)); +if (!strlist__has_entry (namelist, buf)) +break ; + } +if (i ==MAX_EVENT_INDEX ) +die ("Too many events are on the same function." ); +} +void add_trace_kprobe_events (struct probe_point *probes,int nr_probes) {int i, j, fd;struct probe_point *pp;char buf[MAX_CMDLEN ]; +char event[64 ]; +struct strlist *namelist; - fd =open_kprobe_events (O_WRONLY ,O_APPEND ); + fd =open_kprobe_events (O_RDWR ,O_APPEND ); +/* Get current event names */ + namelist =get_perf_event_names (fd);for (j =0 ; j < nr_probes; j++) { pp = probes + j; -if (pp->found ==1 ) { -snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x %s\n" , - pp->retprobe ?'r' :'p' ,PERFPROBE_GROUP , - pp->function, pp->offset, pp->probes[0 ]); +for (i =0 ; i < pp->found; i++) { +/* Get an unused new event name */ +get_new_event_name (event,64 , pp->function, namelist); +snprintf (buf,MAX_CMDLEN ,"%c:%s/%s %s\n" , + pp->retprobe ?'r' :'p' , +PERFPROBE_GROUP , event, + pp->probes[i]);write_trace_kprobe_event (fd, buf); - }else -for (i =0 ; i < pp->found; i++) { -snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x_%d %s\n" , - pp->retprobe ?'r' :'p' , -PERFPROBE_GROUP , - pp->function, pp->offset, i, - pp->probes[i]); -write_trace_kprobe_event (fd, buf); - } +/* Add added event name to namelist */ +strlist__add (namelist, event); + } }close (fd); }
tools/perf/util/probe-event.h +3 -0
@@ -12,4 +12,7 @@ extern int synthesize_trace_kprobe_event(struct probe_point *pp);extern void add_trace_kprobe_events (struct probe_point *probes,int nr_probes);extern void show_perf_probe_events (void ); +/* Maximum index number of event-name postfix */ +#define MAX_EVENT_INDEX 1024 +#endif /*_PROBE_EVENT_H */
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Simplify event naming
Commit-ID: b498ce1f2753b9724b2fc05d2057f7d1490cfa93 Gitweb: http://git.kernel.org/tip/b498ce1f2753b9724b2fc05d2057f7d1490cfa93 Author: Masami Hiramatsu <[email protected]> AuthorDate: Mon, 30 Nov 2009 19:20:25 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 1 Dec 2009 08:20:03 +0100
perf probe: Simplify event naming
Simplify event naming as <symbol>_<seqnum>. Each event name is globally unique (group name is not checked). So, if there is schedule_0, next probe event on schedule() will be schedule_1.
LKML-Reference: <20091201002024.10235.2353.stgit@harusame>
--- tools/perf/util/probe-event.c | 67 ++++++++++++++++++++++++++++++++-------- tools/perf/util/probe-event.h | 3 ++ 2 files changed, 56 insertions(+), 14 deletions(-)
tools/perf/util/probe-event.c +53 -14
@@ -403,6 +403,29 @@ void show_perf_probe_events(void)strlist__delete (rawlist); } +/* Get current perf-probe event names */ +static struct strlist *get_perf_event_names (int fd) +{ +unsigned int i; +char *group, *event; +struct strlist *sl, *rawlist; +struct str_node *ent; + + rawlist =get_trace_kprobe_event_rawlist (fd); + + sl =strlist__new (false,NULL ); +for (i =0 ; i <strlist__nr_entries (rawlist); i++) { + ent =strlist__entry (rawlist, i); +parse_trace_kprobe_event (ent->s, &group, &event,NULL ); +strlist__add (sl, event); +free (group); + } + +strlist__delete (rawlist); + +return sl; +} +static int write_trace_kprobe_event (int fd,const char *buf) {int ret;
@@ -416,30 +439,46 @@ static int write_trace_kprobe_event(int fd, const char *buf)return ret; } +static void get_new_event_name (char *buf,size_t len,const char *base, +struct strlist *namelist) +{ +int i, ret; +for (i =0 ; i <MAX_EVENT_INDEX ; i++) { + ret =e_snprintf (buf, len,"%s_%d" , base, i); +if (ret <0 ) +die ("snprintf() failed: %s" ,strerror (-ret)); +if (!strlist__has_entry (namelist, buf)) +break ; + } +if (i ==MAX_EVENT_INDEX ) +die ("Too many events are on the same function." ); +} +void add_trace_kprobe_events (struct probe_point *probes,int nr_probes) {int i, j, fd;struct probe_point *pp;char buf[MAX_CMDLEN ]; +char event[64 ]; +struct strlist *namelist; - fd =open_kprobe_events (O_WRONLY ,O_APPEND ); + fd =open_kprobe_events (O_RDWR ,O_APPEND ); +/* Get current event names */ + namelist =get_perf_event_names (fd);for (j =0 ; j < nr_probes; j++) { pp = probes + j; -if (pp->found ==1 ) { -snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x %s\n" , - pp->retprobe ?'r' :'p' ,PERFPROBE_GROUP , - pp->function, pp->offset, pp->probes[0 ]); +for (i =0 ; i < pp->found; i++) { +/* Get an unused new event name */ +get_new_event_name (event,64 , pp->function, namelist); +snprintf (buf,MAX_CMDLEN ,"%c:%s/%s %s\n" , + pp->retprobe ?'r' :'p' , +PERFPROBE_GROUP , event, + pp->probes[i]);write_trace_kprobe_event (fd, buf); - }else -for (i =0 ; i < pp->found; i++) { -snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x_%d %s\n" , - pp->retprobe ?'r' :'p' , -PERFPROBE_GROUP , - pp->function, pp->offset, i, - pp->probes[i]); -write_trace_kprobe_event (fd, buf); - } +/* Add added event name to namelist */ +strlist__add (namelist, event); + } }close (fd); }
tools/perf/util/probe-event.h +3 -0
@@ -12,4 +12,7 @@ extern int synthesize_trace_kprobe_event(struct probe_point *pp);extern void add_trace_kprobe_events (struct probe_point *probes,int nr_probes);extern void show_perf_probe_events (void ); +/* Maximum index number of event-name postfix */ +#define MAX_EVENT_INDEX 1024 +#endif /*_PROBE_EVENT_H */
Ingo Molnar
AppliedQuoted 4 lines · Masami Hiramatsu
Hi,
Here are bugfixes and updates for perf-probe and kprobe-tracer. I've fixed some minor bugs and added --list option and simple probe naming.
Applied, thanks Masami!
Quoted 5 lines
TODO:
- Support build-id checking.
- Support --del option to remove probes.
- Support --line option to show which lines user can probe.
- Support lazy string matching.
ok, cool!
One other small detail i noticed wrt. probe naming. Right now if we insert a single probe into a function it gets named schedule_0:
# perf probe schedule Could not open vmlinux/module file. Try to use symbols. Added new event: p:probe/schedule_0 schedule+0
the next one gets named schedule_1, schedule_2, etc.
It would be nice to special-case the first one and name it 'schedule'. Most of the time people insert a single probe into a function, so the _0 postfix is extra and in most cases unnecessary typing for them.
Another small detail is that i dont think we should emit this line:
Could not open vmlinux/module file. Try to use symbols.
when we can create a probe successfully - it's just unnecessary noise, the user does not care how we pulled it off, as long as we were able to get a reliable symbol address and the insertion worked fine.
A third detail is this line:
Added new event: p:probe/schedule_0 schedule+0
If that is pasted to perf stat directly it wont work because the syntax is probe:schedule_0. So i'd suggest to print something like:
Added new event: probe/schedule_0 (on schedule+0)
Perhaps even print another line:
You can now use it on all perf tools, such as:
perf probe -e probe/schedule_0 -a sleep 1
perf record -e probe/schedule_0 -a sleep 1
... to show people how to make use of it.
Thanks,
Ingo
Quoted 25 lines · Ingo Molnar
Quoted 4 lines · Masami Hiramatsu
Hi,
Here are bugfixes and updates for perf-probe and kprobe-tracer. I've fixed some minor bugs and added --list option and simple probe naming.
Applied, thanks Masami!
Quoted 5 lines
TODO:
- Support build-id checking.
- Support --del option to remove probes.
- Support --line option to show which lines user can probe.
- Support lazy string matching.ok, cool!
One other small detail i noticed wrt. probe naming. Right now if we insert a single probe into a function it gets named
schedule_0:# perf probe schedule Could not open vmlinux/module file. Try to use symbols. Added new event: p:probe/schedule_0 schedule+0
Quoted 5 lines
the next one gets named
schedule_1,schedule_2, etc.It would be nice to special-case the first one and name it 'schedule'. Most of the time people insert a single probe into a function, so the _0 postfix is extra and in most cases unnecessary typing for them.
Sure, that's reasonable.
Quoted 8 lines
Another small detail is that i dont think we should emit this line:
Could not open vmlinux/module file. Try to use symbols.
when we can create a probe successfully - it's just unnecessary noise, the user does not care how we pulled it off, as long as we were able to get a reliable symbol address and the insertion worked fine.
OK, I'll make it a debug message.
Quoted 8 lines
A third detail is this line:
Added new event: p:probe/schedule_0 schedule+0
If that is pasted to perf stat directly it wont work because the syntax is probe:schedule_0. So i'd suggest to print something like:
Added new event: probe/schedule_0 (on schedule+0)
Sure, perf always use ':' for event group separator, so
Added new event: probe:schedule (on schedule+0 [with ...(args)])
Quoted 7 lines
Perhaps even print another line:
You can now use it on all perf tools, such as:
perf probe -e probe/schedule_0 -a sleep 1
perf record -e probe/schedule_0 -a sleep 1
OK.
Thank you for good advice!
Quoted 6 lines
... to show people how to make use of it.
Thanks,
Ingo
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]