perf probe: Split add_perf_probe_events()
Namhyung Kim
maintainerPATCH v2 1/5 perf probe: Split add_perf_probe_events()
The add_perf_probe_events() does 3 things:
1. convert all perf events to trace events
2. add all trace events to kernel
3. cleanup all trace events
But sometimes we need to do something with the trace events. So split the funtion into three, so that it can access intermediate trace events via struct __event_package if needed.
--- tools/perf/util/probe-event.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)
tools/perf/util/probe-event.c +35 -4
@@ -2765,9 +2765,10 @@ struct __event_package {int ntevs; }; -int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +static int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs, +struct __event_package **ppkgs) { -int i, j, ret; +int i, ret;struct __event_package *pkgs; ret =0 ;
@@ -2792,12 +2793,21 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs) ret =convert_to_probe_trace_events (pkgs[i].pev, &pkgs[i].tevs);if (ret <0 ) - goto end; +return ret; pkgs[i].ntevs = ret; }/* This just release blacklist only if allocated */ kprobe_blacklist__release (); + *ppkgs = pkgs; + +return 0 ; +} + +static int apply_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, ret =0 ; +/* Loop 2: add all events */ for (i =0 ; i < npevs; i++) { ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
@@ -2806,7 +2816,16 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)if (ret <0 )break ; } -end: +return ret; +} + +static void cleanup_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, j; + +if (pkgs ==NULL ) +return ; +/* Loop 3: cleanup and free trace events */ for (i =0 ; i < npevs; i++) {for (j =0 ; j < pkgs[i].ntevs; j++)
@@ -2815,6 +2834,18 @@ end: }free (pkgs);exit_symbol_maps (); +} + +int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +{ +int ret; +struct __event_package *pkgs =NULL ; + + ret =convert_perf_probe_events (pevs, npevs, &pkgs); +if (ret ==0 ) + ret =apply_perf_probe_events (pkgs, npevs); + +cleanup_perf_probe_events (pkgs, npevs);return ret; }
Signature · 1 line
2.5.0
Namhyung Kim
maintainerPATCH v2 2/5 perf probe: Attach trace_probe_event with perf_probe_event
From: Wang Nan <[email protected]>
This patch drops struct __event_package structure. Instead, it adds trace_probe_event into 'struct perf_probe_event'.
trace_probe_event information gives further patches a chance to access actual probe points and actual arguments. Using them, perf probe can get whole list of added probes and print them at once.
Other users like upcoming bpf_loader will be able to attach one bpf program to different probing points of an inline functions (which has multiple probing points) and glob functions. Moreover, by reading arguments information, bpf code for reading those arguments can be generated.
--- tools/perf/util/probe-event.c | 57 +++++++++++++------------------------------ tools/perf/util/probe-event.h | 5 ++++ 2 files changed, 22 insertions(+), 40 deletions(-)
tools/perf/util/probe-event.c +17 -40
@@ -2759,59 +2759,39 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,return find_probe_trace_events_from_map (pev, tevs); } -struct __event_package { -struct perf_probe_event *pev; -struct probe_trace_event *tevs; -int ntevs; -}; - -static int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs, -struct __event_package **ppkgs) +int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int i, ret; -struct __event_package *pkgs; - - ret =0 ; - pkgs =zalloc (sizeof (struct __event_package ) * npevs); - -if (pkgs ==NULL ) -return -ENOMEM ; ret =init_symbol_maps (pevs->uprobes); -if (ret <0 ) { -free (pkgs); +if (ret <0 )return ret; - }/* Loop 1: convert all events */ for (i =0 ; i < npevs; i++) { - pkgs[i].pev = &pevs[i];/* Init kprobe blacklist if needed */ -if (!pkgs[i].pev->uprobes) +if (!pevs[i].uprobes)kprobe_blacklist__init ();/* Convert with or without debuginfo */ - ret =convert_to_probe_trace_events (pkgs[i].pev, - &pkgs[i].tevs); + ret =convert_to_probe_trace_events (&pevs[i], &pevs[i].tevs);if (ret <0 )return ret; - pkgs[i].ntevs = ret; + pevs[i].ntevs = ret; }/* This just release blacklist only if allocated */ kprobe_blacklist__release (); - *ppkgs = pkgs; -return 0 ; } -static int apply_perf_probe_events (struct __event_package *pkgs,int npevs) +int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int i, ret =0 ;/* Loop 2: add all events */ for (i =0 ; i < npevs; i++) { - ret =__add_probe_trace_events (pkgs[i].pev, pkgs[i].tevs, - pkgs[i].ntevs, + ret =__add_probe_trace_events (&pevs[i], pevs[i].tevs, + pevs[i].ntevs, probe_conf.force_add);if (ret <0 )break ;
@@ -2819,33 +2799,30 @@ static int apply_perf_probe_events(struct __event_package *pkgs, int npevs)return ret; } -static void cleanup_perf_probe_events (struct __event_package *pkgs,int npevs) +void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int i, j; -if (pkgs ==NULL ) -return ; -/* Loop 3: cleanup and free trace events */ for (i =0 ; i < npevs; i++) { -for (j =0 ; j < pkgs[i].ntevs; j++) -clear_probe_trace_event (&pkgs[i].tevs[j]); -zfree (&pkgs[i].tevs); +for (j =0 ; j < pevs[i].ntevs; j++) +clear_probe_trace_event (&pevs[i].tevs[j]); +zfree (&pevs[i].tevs); + pevs[i].ntevs =0 ; } -free (pkgs); +exit_symbol_maps (); }int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int ret; -struct __event_package *pkgs =NULL ; - ret =convert_perf_probe_events (pevs, npevs, &pkgs); + ret =convert_perf_probe_events (pevs, npevs);if (ret ==0 ) - ret =apply_perf_probe_events (pkgs, npevs); + ret =apply_perf_probe_events (pevs, npevs); -cleanup_perf_probe_events (pkgs, npevs); +cleanup_perf_probe_events (pevs, npevs);return ret; }
tools/perf/util/probe-event.h +5 -0
@@ -87,6 +87,8 @@ struct perf_probe_event {bool uprobes;/* Uprobe event flag */ char *target;/* Target binary */ struct perf_probe_arg *args;/* Arguments */ +struct probe_trace_event *tevs; +int ntevs; };/* Line range */
@@ -138,6 +140,9 @@ extern void line_range__clear(struct line_range *lr);extern int line_range__init (struct line_range *lr);extern int add_perf_probe_events (struct perf_probe_event *pevs,int npevs); +extern int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs); +extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs); +extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int del_perf_probe_events (struct strfilter *filter);extern int show_perf_probe_events (struct strfilter *filter); extern int show_line_range(struct line_range *lr, const char *module,
Signature · 1 line
2.5.0
tip-bot for Wang Nan
merge bot[tip:perf/core] perf probe: Link trace_probe_event into perf_probe_event
perf probe: Link trace_probe_event into perf_probe_event
Commit-ID: 12fae5ef6dc6031ffcf4dffc6be5a16080e7dd7d Gitweb: http://git.kernel.org/tip/12fae5ef6dc6031ffcf4dffc6be5a16080e7dd7d Author: Wang Nan <[email protected]> AuthorDate: Fri, 4 Sep 2015 21:16:00 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 4 Sep 2015 12:34:23 -0300
perf probe: Link trace_probe_event into perf_probe_event
This patch drops struct __event_package structure. Instead, it adds a 'struct trace_probe_event' pointer to 'struct perf_probe_event'.
The trace_probe_event information gives further patches a chance to access actual probe points and actual arguments.
Using them, 'perf probe' can get the whole list of added probes and print them at once.
Other users like the upcoming bpf_loader will be able to attach one bpf program to different probing points of an inline function (which has multiple probing points) and glob functions.
Moreover, by reading the arguments information, bpf code for reading those arguments can be generated.
--- tools/perf/util/probe-event.c | 57 +++++++++++++------------------------------ tools/perf/util/probe-event.h | 5 ++++ 2 files changed, 22 insertions(+), 40 deletions(-)
tools/perf/util/probe-event.c +17 -40
@@ -2759,59 +2759,39 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,return find_probe_trace_events_from_map (pev, tevs); } -struct __event_package { -struct perf_probe_event *pev; -struct probe_trace_event *tevs; -int ntevs; -}; - -static int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs, -struct __event_package **ppkgs) +int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int i, ret; -struct __event_package *pkgs; - - ret =0 ; - pkgs =zalloc (sizeof (struct __event_package ) * npevs); - -if (pkgs ==NULL ) -return -ENOMEM ; ret =init_symbol_maps (pevs->uprobes); -if (ret <0 ) { -free (pkgs); +if (ret <0 )return ret; - }/* Loop 1: convert all events */ for (i =0 ; i < npevs; i++) { - pkgs[i].pev = &pevs[i];/* Init kprobe blacklist if needed */ -if (!pkgs[i].pev->uprobes) +if (!pevs[i].uprobes)kprobe_blacklist__init ();/* Convert with or without debuginfo */ - ret =convert_to_probe_trace_events (pkgs[i].pev, - &pkgs[i].tevs); + ret =convert_to_probe_trace_events (&pevs[i], &pevs[i].tevs);if (ret <0 )return ret; - pkgs[i].ntevs = ret; + pevs[i].ntevs = ret; }/* This just release blacklist only if allocated */ kprobe_blacklist__release (); - *ppkgs = pkgs; -return 0 ; } -static int apply_perf_probe_events (struct __event_package *pkgs,int npevs) +int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int i, ret =0 ;/* Loop 2: add all events */ for (i =0 ; i < npevs; i++) { - ret =__add_probe_trace_events (pkgs[i].pev, pkgs[i].tevs, - pkgs[i].ntevs, + ret =__add_probe_trace_events (&pevs[i], pevs[i].tevs, + pevs[i].ntevs, probe_conf.force_add);if (ret <0 )break ;
@@ -2819,33 +2799,30 @@ static int apply_perf_probe_events(struct __event_package *pkgs, int npevs)return ret; } -static void cleanup_perf_probe_events (struct __event_package *pkgs,int npevs) +void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int i, j; -if (pkgs ==NULL ) -return ; -/* Loop 3: cleanup and free trace events */ for (i =0 ; i < npevs; i++) { -for (j =0 ; j < pkgs[i].ntevs; j++) -clear_probe_trace_event (&pkgs[i].tevs[j]); -zfree (&pkgs[i].tevs); +for (j =0 ; j < pevs[i].ntevs; j++) +clear_probe_trace_event (&pevs[i].tevs[j]); +zfree (&pevs[i].tevs); + pevs[i].ntevs =0 ; } -free (pkgs); +exit_symbol_maps (); }int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) {int ret; -struct __event_package *pkgs =NULL ; - ret =convert_perf_probe_events (pevs, npevs, &pkgs); + ret =convert_perf_probe_events (pevs, npevs);if (ret ==0 ) - ret =apply_perf_probe_events (pkgs, npevs); + ret =apply_perf_probe_events (pevs, npevs); -cleanup_perf_probe_events (pkgs, npevs); +cleanup_perf_probe_events (pevs, npevs);return ret; }
tools/perf/util/probe-event.h +5 -0
@@ -87,6 +87,8 @@ struct perf_probe_event {bool uprobes;/* Uprobe event flag */ char *target;/* Target binary */ struct perf_probe_arg *args;/* Arguments */ +struct probe_trace_event *tevs; +int ntevs; };/* Line range */
@@ -138,6 +140,9 @@ extern void line_range__clear(struct line_range *lr);extern int line_range__init (struct line_range *lr);extern int add_perf_probe_events (struct perf_probe_event *pevs,int npevs); +extern int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs); +extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs); +extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int del_perf_probe_events (struct strfilter *filter);extern int show_perf_probe_events (struct strfilter *filter); extern int show_line_range(struct line_range *lr, const char *module,
Namhyung Kim
maintainerPATCH v2 3/5 perf probe: Move print logic into cmd_probe()
In reply to Namhyung KimShowing actual trace event when adding perf events is only needed in perf probe command. But the add functionality itself can be used by other places. So move the printing code into the cmd_probe().
Also it combines the output if more than one event is added.
Before:
$ sudo perf probe -a do_fork -a do_exit Added new event: probe:do_fork (on do_fork)
You can now use it in all perf tools, such as:
perf record -e probe:do_fork -aR sleep 1
Added new events:
probe:do_exit (on do_exit)
probe:do_exit_1 (on do_exit)
You can now use it in all perf tools, such as:
perf record -e probe:do_exit_1 -aR sleep 1
After:
$ sudo perf probe -a do_fork -a do_exit Added new events: probe:do_fork (on do_fork) probe:do_exit (on do_exit) probe:do_exit_1 (on do_exit)
You can now use it in all perf tools, such as:
perf record -e probe:do_exit_1 -aR sleep 1
--- tools/perf/builtin-probe.c | 48 ++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-event.c | 22 +++----------------- tools/perf/util/probe-event.h | 3 +++ 3 files changed, 53 insertions(+), 20 deletions(-)
tools/perf/builtin-probe.c +47 -1
@@ -311,6 +311,52 @@ static void pr_err_with_code(const char *msg, int err)pr_err ("\n" ); } +static int perf_add_probe_events (struct perf_probe_event *pevs,int npevs) +{ +int ret; +int i, k; +const char *event =NULL , *group =NULL ; + + ret =convert_perf_probe_events (pevs, npevs); +if (ret <0 ) + goto out_cleanup; + + ret =apply_perf_probe_events (pevs, npevs); +if (ret <0 ) + goto out_cleanup; + +for (i = k =0 ; i < npevs; i++) + k += pevs[i].ntevs; + +pr_info ("Added new event%s\n" , (k >1 ) ?"s:" :":" ); +for (i =0 ; i < npevs; i++) { +struct perf_probe_event *pev = &pevs[i]; + +for (k =0 ; k < pev->ntevs; k++) { +struct probe_trace_event *tev = &pev->tevs[k]; + +/* We use tev's name for showing new events */ +show_perf_probe_event (tev->group, tev->event, pev, + tev->point.module, false); + +/* Save the last valid name */ + event = tev->event; + group = tev->group; + } + } + +/* Note that it is possible to skip all events because of blacklist */ +if (event) { +/* Show how to use the event. */ +pr_info ("\nYou can now use it in all perf tools, such as:\n\n" ); +pr_info ("\tperf record -e %s:%s -aR sleep 1\n\n" , group, event); + } + +out_cleanup: +cleanup_perf_probe_events (pevs, npevs); +return ret; +} +static int __cmd_probe (int argc,const char **argv,const char *prefix__maybe_unused ) {
@@ -496,7 +542,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)usage_with_options (probe_usage, options); } - ret =add_perf_probe_events (params.events, params.nevents); + ret =perf_add_probe_events (params.events, params.nevents);if (ret <0 ) {pr_err_with_code (" Error: Failed to add events." , ret);return ret;
tools/perf/util/probe-event.c +3 -19
@@ -2180,9 +2180,9 @@ out: }/* Show an event */ -static int show_perf_probe_event (const char *group,const char *event, -struct perf_probe_event *pev, -const char *module,bool use_stdout) +int show_perf_probe_event (const char *group,const char *event, +struct perf_probe_event *pev, +const char *module,bool use_stdout) {struct strbuf buf =STRBUF_INIT ;int ret;
@@ -2399,7 +2399,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, {int i, fd, ret;struct probe_trace_event *tev =NULL ; -const char *event =NULL , *group =NULL ;struct strlist *namelist; fd =probe_file__open (PF_FL_RW | (pev->uprobes ?PF_FL_UPROBE :0 ));
@@ -2415,7 +2414,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, } ret =0 ; -pr_info ("Added new event%s\n" , (ntevs >1 ) ?"s:" :":" );for (i =0 ; i < ntevs; i++) { tev = &tevs[i];/* Skip if the symbol is out of .text or blacklisted */
@@ -2432,13 +2430,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,if (ret <0 )break ; -/* We use tev's name for showing new events */ -show_perf_probe_event (tev->group, tev->event, pev, - tev->point.module, false); -/* Save the last valid name */ - event = tev->event; - group = tev->group; -/* * Probes after the first probe which comes from same * user input are always allowed to add suffix, because
@@ -2450,13 +2441,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,if (ret == -EINVAL && pev->uprobes)warn_uprobe_event_compat (tev); -/* Note that it is possible to skip all events because of blacklist */ -if (ret >=0 && event) { -/* Show how to use the event. */ -pr_info ("\nYou can now use it in all perf tools, such as:\n\n" ); -pr_info ("\tperf record -e %s:%s -aR sleep 1\n\n" , group, event); - } -strlist__delete (namelist); close_out:close (fd);
tools/perf/util/probe-event.h +3 -0
@@ -144,6 +144,9 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int del_perf_probe_events (struct strfilter *filter); +extern int show_perf_probe_event (const char *group,const char *event, +struct perf_probe_event *pev, +const char *module,bool use_stdout);extern int show_perf_probe_events (struct strfilter *filter);extern int show_line_range (struct line_range *lr,const char *module,bool user);
Signature · 1 line
2.5.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf probe: Move print logic into cmd_probe()
perf probe: Move print logic into cmd_probe()
Commit-ID: b02137cc6550c1fa28e9a7c943a79fe6e4c4378d Gitweb: http://git.kernel.org/tip/b02137cc6550c1fa28e9a7c943a79fe6e4c4378d Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 4 Sep 2015 21:16:01 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 4 Sep 2015 12:37:17 -0300
perf probe: Move print logic into cmd_probe()
Showing actual trace event when adding perf events is only needed in perf probe command. But the add functionality itself can be used by other places. So move the printing code into the cmd_probe().
Also it combines the output if more than one event is added.
Before:
$ sudo perf probe -a do_fork -a do_exit Added new event: probe:do_fork (on do_fork)
You can now use it in all perf tools, such as:
perf record -e probe:do_fork -aR sleep 1
Added new events:
probe:do_exit (on do_exit)
probe:do_exit_1 (on do_exit)
You can now use it in all perf tools, such as:
perf record -e probe:do_exit_1 -aR sleep 1
After:
$ sudo perf probe -a do_fork -a do_exit Added new events: probe:do_fork (on do_fork) probe:do_exit (on do_exit) probe:do_exit_1 (on do_exit)
You can now use it in all perf tools, such as:
perf record -e probe:do_exit_1 -aR sleep 1
--- tools/perf/builtin-probe.c | 48 ++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-event.c | 22 +++----------------- tools/perf/util/probe-event.h | 3 +++ 3 files changed, 53 insertions(+), 20 deletions(-)
tools/perf/builtin-probe.c +47 -1
@@ -311,6 +311,52 @@ static void pr_err_with_code(const char *msg, int err)pr_err ("\n" ); } +static int perf_add_probe_events (struct perf_probe_event *pevs,int npevs) +{ +int ret; +int i, k; +const char *event =NULL , *group =NULL ; + + ret =convert_perf_probe_events (pevs, npevs); +if (ret <0 ) + goto out_cleanup; + + ret =apply_perf_probe_events (pevs, npevs); +if (ret <0 ) + goto out_cleanup; + +for (i = k =0 ; i < npevs; i++) + k += pevs[i].ntevs; + +pr_info ("Added new event%s\n" , (k >1 ) ?"s:" :":" ); +for (i =0 ; i < npevs; i++) { +struct perf_probe_event *pev = &pevs[i]; + +for (k =0 ; k < pev->ntevs; k++) { +struct probe_trace_event *tev = &pev->tevs[k]; + +/* We use tev's name for showing new events */ +show_perf_probe_event (tev->group, tev->event, pev, + tev->point.module, false); + +/* Save the last valid name */ + event = tev->event; + group = tev->group; + } + } + +/* Note that it is possible to skip all events because of blacklist */ +if (event) { +/* Show how to use the event. */ +pr_info ("\nYou can now use it in all perf tools, such as:\n\n" ); +pr_info ("\tperf record -e %s:%s -aR sleep 1\n\n" , group, event); + } + +out_cleanup: +cleanup_perf_probe_events (pevs, npevs); +return ret; +} +static int __cmd_probe (int argc,const char **argv,const char *prefix__maybe_unused ) {
@@ -496,7 +542,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)usage_with_options (probe_usage, options); } - ret =add_perf_probe_events (params.events, params.nevents); + ret =perf_add_probe_events (params.events, params.nevents);if (ret <0 ) {pr_err_with_code (" Error: Failed to add events." , ret);return ret;
tools/perf/util/probe-event.c +3 -19
@@ -2180,9 +2180,9 @@ out: }/* Show an event */ -static int show_perf_probe_event (const char *group,const char *event, -struct perf_probe_event *pev, -const char *module,bool use_stdout) +int show_perf_probe_event (const char *group,const char *event, +struct perf_probe_event *pev, +const char *module,bool use_stdout) {struct strbuf buf =STRBUF_INIT ;int ret;
@@ -2399,7 +2399,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, {int i, fd, ret;struct probe_trace_event *tev =NULL ; -const char *event =NULL , *group =NULL ;struct strlist *namelist; fd =probe_file__open (PF_FL_RW | (pev->uprobes ?PF_FL_UPROBE :0 ));
@@ -2415,7 +2414,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, } ret =0 ; -pr_info ("Added new event%s\n" , (ntevs >1 ) ?"s:" :":" );for (i =0 ; i < ntevs; i++) { tev = &tevs[i];/* Skip if the symbol is out of .text or blacklisted */
@@ -2432,13 +2430,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,if (ret <0 )break ; -/* We use tev's name for showing new events */ -show_perf_probe_event (tev->group, tev->event, pev, - tev->point.module, false); -/* Save the last valid name */ - event = tev->event; - group = tev->group; -/* * Probes after the first probe which comes from same * user input are always allowed to add suffix, because
@@ -2450,13 +2441,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,if (ret == -EINVAL && pev->uprobes)warn_uprobe_event_compat (tev); -/* Note that it is possible to skip all events because of blacklist */ -if (ret >=0 && event) { -/* Show how to use the event. */ -pr_info ("\nYou can now use it in all perf tools, such as:\n\n" ); -pr_info ("\tperf record -e %s:%s -aR sleep 1\n\n" , group, event); - } -strlist__delete (namelist); close_out:close (fd);
tools/perf/util/probe-event.h +3 -0
@@ -144,6 +144,9 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int del_perf_probe_events (struct strfilter *filter); +extern int show_perf_probe_event (const char *group,const char *event, +struct perf_probe_event *pev, +const char *module,bool use_stdout);extern int show_perf_probe_events (struct strfilter *filter);extern int show_line_range (struct line_range *lr,const char *module,bool user);
Namhyung Kim
maintainerPATCH v2 4/5 perf probe: Split del_perf_probe_events()
In reply to Namhyung KimThe del_perf_probe_events() does 2 things:
1. find existing events which match to filter
2. delete such trace events from kernel
But sometimes we need to do something with the trace events. So split the funtion into two, so that it can access intermediate trace events name using strlist if needed.
--- tools/perf/util/probe-file.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-)
tools/perf/util/probe-file.c +36 -4
@@ -275,7 +275,8 @@ error:return ret; } -int probe_file__del_events (int fd,struct strfilter *filter) +static int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist) {struct strlist *namelist;struct str_node *ent;
@@ -290,12 +291,43 @@ int probe_file__del_events(int fd, struct strfilter *filter) p =strchr (ent->s,':' );if ((p &&strfilter__compare (filter, p +1 )) ||strfilter__compare (filter, ent->s)) { - ret =__del_trace_probe_event (fd, ent); -if (ret <0 ) -break ; +strlist__add (plist, ent->s); + ret =0 ; } }strlist__delete (namelist);return ret; } + +static int probe_file__del_strlist (int fd,struct strlist *namelist) +{ +int ret =0 ; +struct str_node *ent; + +strlist__for_each (ent, namelist) { + ret =__del_trace_probe_event (fd, ent); +if (ret <0 ) +break ; + } +return ret; +} + +int probe_file__del_events (int fd,struct strfilter *filter) +{ +struct strlist *namelist; +int ret; + + namelist =strlist__new (NULL ,NULL ); +if (!namelist) +return -ENOMEM ; + + ret =probe_file__get_events (fd, filter, namelist); +if (ret <0 ) +return ret; + + ret =probe_file__del_strlist (fd, namelist); +strlist__delete (namelist); + +return ret; +}
Signature · 1 line
2.5.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf probe: Split del_perf_probe_events()
perf probe: Split del_perf_probe_events()
Commit-ID: e7895e422e4da63daedacad0a2ed1a5a6b502d66 Gitweb: http://git.kernel.org/tip/e7895e422e4da63daedacad0a2ed1a5a6b502d66 Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 4 Sep 2015 21:16:02 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 4 Sep 2015 12:43:19 -0300
perf probe: Split del_perf_probe_events()
The del_perf_probe_events() does 2 things:
1. find existing events which match to filter
2. delete such trace events from kernel
But sometimes we need to do something with the trace events. So split the funtion into two, so that it can access intermediate trace events name using strlist if needed.
--- tools/perf/util/probe-file.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-)
tools/perf/util/probe-file.c +36 -4
@@ -275,7 +275,8 @@ error:return ret; } -int probe_file__del_events (int fd,struct strfilter *filter) +static int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist) {struct strlist *namelist;struct str_node *ent;
@@ -290,12 +291,43 @@ int probe_file__del_events(int fd, struct strfilter *filter) p =strchr (ent->s,':' );if ((p &&strfilter__compare (filter, p +1 )) ||strfilter__compare (filter, ent->s)) { - ret =__del_trace_probe_event (fd, ent); -if (ret <0 ) -break ; +strlist__add (plist, ent->s); + ret =0 ; } }strlist__delete (namelist);return ret; } + +static int probe_file__del_strlist (int fd,struct strlist *namelist) +{ +int ret =0 ; +struct str_node *ent; + +strlist__for_each (ent, namelist) { + ret =__del_trace_probe_event (fd, ent); +if (ret <0 ) +break ; + } +return ret; +} + +int probe_file__del_events (int fd,struct strfilter *filter) +{ +struct strlist *namelist; +int ret; + + namelist =strlist__new (NULL ,NULL ); +if (!namelist) +return -ENOMEM ; + + ret =probe_file__get_events (fd, filter, namelist); +if (ret <0 ) +return ret; + + ret =probe_file__del_strlist (fd, namelist); +strlist__delete (namelist); + +return ret; +}
Namhyung Kim
maintainerPATCH v2 5/5 perf probe: Print deleted events in cmd_probe()
In reply to Namhyung KimShowing actual trace event when deleteing perf events is only needed in perf probe command. But the add functionality itself can be used by other places. So move the printing code into the cmd_probe().
The output is not changed.
--- tools/perf/builtin-probe.c | 62 ++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-event.c | 5 ---- tools/perf/util/probe-event.h | 1 + tools/perf/util/probe-file.c | 7 +++-- tools/perf/util/probe-file.h | 4 +++ 5 files changed, 69 insertions(+), 10 deletions(-)
tools/perf/builtin-probe.c +61 -1
@@ -41,6 +41,7 @@#include "util/parse-options.h" #include "util/probe-finder.h" #include "util/probe-event.h" +#include "util/probe-file.h" #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"#define DEFAULT_FUNC_FILTER "!_*"
@@ -357,6 +358,65 @@ out_cleanup:return ret; } +static int perf_del_probe_events (struct strfilter *filter) +{ +int ret, ret2, ufd =-1 , kfd =-1 ; +char *str =strfilter__string (filter); +struct strlist *klist =NULL , *ulist =NULL ; +struct str_node *ent; + +if (!str) +return -EINVAL ; + +pr_debug ("Delete filter: \'%s\'\n" , str); + +/* Get current event names */ + ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW ); +if (ret <0 ) + goto out; + + klist =strlist__new (NULL ,NULL ); +if (!klist) +return -ENOMEM ; + + ret =probe_file__get_events (kfd, filter, klist); +if (ret ==0 ) { +strlist__for_each (ent, klist) +pr_info ("Removed event: %s\n" , ent->s); + + ret =probe_file__del_strlist (kfd, klist); +if (ret <0 ) + goto error; + } + + ret2 =probe_file__get_events (ufd, filter, ulist); +if (ret2 ==0 ) { +strlist__for_each (ent, ulist) +pr_info ("Removed event: %s\n" , ent->s); + + ret2 =probe_file__del_strlist (ufd, ulist); +if (ret2 <0 ) + goto error; + } + +if (ret == -ENOENT && ret2 == -ENOENT ) +pr_debug ("\"%s\" does not hit any event.\n" , str); +/* Note that this is silently ignored */ + ret =0 ; + +error: +if (kfd >=0 ) +close (kfd); +if (ufd >=0 ) +close (ufd); +out: +strlist__delete (klist); +strlist__delete (ulist); +free (str); + +return ret; +} +static int __cmd_probe (int argc,const char **argv,const char *prefix__maybe_unused ) {
@@ -529,7 +589,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)return ret;#endif case 'd' : - ret =del_perf_probe_events (params.filter); + ret =perf_del_probe_events (params.filter);if (ret <0 ) {pr_err_with_code (" Error: Failed to delete events." , ret);return ret;
tools/perf/util/probe-event.c +0 -5
@@ -2819,8 +2819,6 @@ int del_perf_probe_events(struct strfilter *filter)if (!str)return -EINVAL ; -pr_debug ("Delete filter: \'%s\'\n" , str); -/* Get current event names */ ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW );if (ret <0 )
@@ -2835,9 +2833,6 @@ int del_perf_probe_events(struct strfilter *filter) ret = ret2; goto error; } -if (ret == -ENOENT && ret2 == -ENOENT ) -pr_debug ("\"%s\" does not hit any event.\n" , str); -/* Note that this is silently ignored */ ret =0 ; error:
tools/perf/util/probe-event.h +1 -0
@@ -144,6 +144,7 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int del_perf_probe_events (struct strfilter *filter); +extern int show_perf_probe_event (const char *group,const char *event,struct perf_probe_event *pev,const char *module,bool use_stdout);
tools/perf/util/probe-file.c +3 -4
@@ -267,7 +267,6 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) goto error; } -pr_info ("Removed event: %s\n" , ent->s);return 0 ; error: pr_warning("Failed to delete event: %s\n",
@@ -275,8 +274,8 @@ error:return ret; } -static int probe_file__get_events (int fd,struct strfilter *filter, -struct strlist *plist) +int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist) {struct strlist *namelist;struct str_node *ent;
@@ -300,7 +299,7 @@ static int probe_file__get_events(int fd, struct strfilter *filter,return ret; } -static int probe_file__del_strlist (int fd,struct strlist *namelist) +int probe_file__del_strlist (int fd,struct strlist *namelist) {int ret =0 ;struct str_node *ent;
tools/perf/util/probe-file.h +4 -0
@@ -14,5 +14,9 @@ struct strlist *probe_file__get_namelist(int fd);struct strlist *probe_file__get_rawlist (int fd);int probe_file__add_event (int fd,struct probe_trace_event *tev);int probe_file__del_events (int fd,struct strfilter *filter); +int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist); +int probe_file__del_strlist (int fd,struct strlist *namelist); +#endif
Signature · 1 line
2.5.0
RE: [PATCH v2 5/5] perf probe: Print deleted events in cmd_probe()
Quoted 8 lines
From: Namhyung Kim [mailto:[email protected]] On Behalf Of Namhyung Kim
Showing actual trace event when deleteing perf events is only needed in perf probe command. But the add functionality itself can be used by other places. So move the printing code into the
cmd_probe().The output is not changed.
Looks good to me :)
Thanks!
Quoted 179 lines
Cc Masami Hiramatsu <[email protected]>Signed-off-by Namhyung Kim <[email protected]>---
tools/perf/builtin-probe.c | 62 ++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-event.c | 5 ---- tools/perf/util/probe-event.h | 1 + tools/perf/util/probe-file.c | 7 +++-- tools/perf/util/probe-file.h | 4 +++ 5 files changed, 69 insertions(+), 10 deletions(-)tools/perf/builtin-probe.c +60
-0@@ -41,6 +41,7 @@#include "util/parse-options.h" #include "util/probe-finder.h" #include "util/probe-event.h" +#include "util/probe-file.h" #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"#define DEFAULT_FUNC_FILTER "!_*"@@ -357,6 +358,65 @@ out_cleanup:return ret; } +static int perf_del_probe_events (struct strfilter *filter) +{ +int ret, ret2, ufd =-1 , kfd =-1 ; +char *str =strfilter__string (filter); +struct strlist *klist =NULL , *ulist =NULL ; +struct str_node *ent; + +if (!str) +return -EINVAL ; + +pr_debug ("Delete filter: \'%s\'\n" , str); + +/* Get current event names */ + ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW ); +if (ret <0 ) + goto out; + + klist =strlist__new (NULL ,NULL ); +if (!klist) +return -ENOMEM ; + + ret =probe_file__get_events (kfd, filter, klist); +if (ret ==0 ) { +strlist__for_each (ent, klist) +pr_info ("Removed event: %s\n" , ent->s); + + ret =probe_file__del_strlist (kfd, klist); +if (ret <0 ) + goto error; + } + + ret2 =probe_file__get_events (ufd, filter, ulist); +if (ret2 ==0 ) { +strlist__for_each (ent, ulist) +pr_info ("Removed event: %s\n" , ent->s); + + ret2 =probe_file__del_strlist (ufd, ulist); +if (ret2 <0 ) + goto error; + } + +if (ret == -ENOENT && ret2 == -ENOENT ) +pr_debug ("\"%s\" does not hit any event.\n" , str); +/* Note that this is silently ignored */ + ret =0 ; + +error: +if (kfd >=0 ) +close (kfd); +if (ufd >=0 ) +close (ufd); +out: +strlist__delete (klist); +strlist__delete (ulist); +free (str); + +return ret; +} +static int
__cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused){tools/perf/builtin-probe.c +1
-1@@ -529,7 +589,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)return ret;#endif case 'd' : - ret =del_perf_probe_events (params.filter); + ret =perf_del_probe_events (params.filter);if (ret <0 ) {pr_err_with_code (" Error: Failed to delete events." , ret);return ret;tools/perf/util/probe-event.c +0
-5@@ -2819,8 +2819,6 @@ int del_perf_probe_events(struct strfilter *filter)if (!str)return -EINVAL ; -pr_debug ("Delete filter: \'%s\'\n" , str); -/* Get current event names */ ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW );if (ret <0 )@@ -2835,9 +2833,6 @@ int del_perf_probe_events(struct strfilter *filter) ret = ret2; goto error; } -if (ret == -ENOENT && ret2 == -ENOENT ) -pr_debug ("\"%s\" does not hit any event.\n" , str); -/* Note that this is silently ignored */ ret =0 ;error:
tools/perf/util/probe-event.h +1
-0@@ -144,6 +144,7 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int del_perf_probe_events (struct strfilter *filter); +extern int show_perf_probe_event (const char *group,const char *event,struct perf_probe_event *pev,const char *module,bool use_stdout);tools/perf/util/probe-file.c +0
-1@@ -267,7 +267,6 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) goto error; } -pr_info ("Removed event: %s\n" , ent->s);return 0 ;error:
pr_warning("Failed to delete event: %s\n",tools/perf/util/probe-file.c +3
-3@@ -275,8 +274,8 @@ error:return ret; } -static int probe_file__get_events (int fd,struct strfilter *filter, -struct strlist *plist) +int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist) {struct strlist *namelist;struct str_node *ent;@@ -300,7 +299,7 @@ static int probe_file__get_events(int fd, struct strfilter *filter,return ret; } -static int probe_file__del_strlist (int fd,struct strlist *namelist) +int probe_file__del_strlist (int fd,struct strlist *namelist) {int ret =0 ;struct str_node *ent;tools/perf/util/probe-file.h +4
-1@@ -14,5 +14,9 @@ struct strlist *probe_file__get_namelist(int fd);struct strlist *probe_file__get_rawlist (int fd);int probe_file__add_event (int fd,struct probe_trace_event *tev);int probe_file__del_events (int fd,struct strfilter *filter); +int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist); +int probe_file__del_strlist (int fd,struct strlist *namelist); +#endif --
Quoted 1 line
2.5.0
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf probe: Print deleted events in cmd_probe()
In reply to Namhyung Kimperf probe: Print deleted events in cmd_probe()
Commit-ID: e607f1426b584f2bd3f688a2d416baf963251e7a Gitweb: http://git.kernel.org/tip/e607f1426b584f2bd3f688a2d416baf963251e7a Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 4 Sep 2015 21:16:03 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 4 Sep 2015 12:43:44 -0300
perf probe: Print deleted events in cmd_probe()
Showing actual trace event when deleteing perf events is only needed in perf probe command. But the add functionality itself can be used by other places. So move the printing code into the cmd_probe().
The output is not changed.
--- tools/perf/builtin-probe.c | 62 ++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-event.c | 5 ---- tools/perf/util/probe-event.h | 1 + tools/perf/util/probe-file.c | 7 +++-- tools/perf/util/probe-file.h | 4 +++ 5 files changed, 69 insertions(+), 10 deletions(-)
tools/perf/builtin-probe.c +61 -1
@@ -41,6 +41,7 @@#include "util/parse-options.h" #include "util/probe-finder.h" #include "util/probe-event.h" +#include "util/probe-file.h" #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"#define DEFAULT_FUNC_FILTER "!_*"
@@ -357,6 +358,65 @@ out_cleanup:return ret; } +static int perf_del_probe_events (struct strfilter *filter) +{ +int ret, ret2, ufd =-1 , kfd =-1 ; +char *str =strfilter__string (filter); +struct strlist *klist =NULL , *ulist =NULL ; +struct str_node *ent; + +if (!str) +return -EINVAL ; + +pr_debug ("Delete filter: \'%s\'\n" , str); + +/* Get current event names */ + ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW ); +if (ret <0 ) + goto out; + + klist =strlist__new (NULL ,NULL ); +if (!klist) +return -ENOMEM ; + + ret =probe_file__get_events (kfd, filter, klist); +if (ret ==0 ) { +strlist__for_each (ent, klist) +pr_info ("Removed event: %s\n" , ent->s); + + ret =probe_file__del_strlist (kfd, klist); +if (ret <0 ) + goto error; + } + + ret2 =probe_file__get_events (ufd, filter, ulist); +if (ret2 ==0 ) { +strlist__for_each (ent, ulist) +pr_info ("Removed event: %s\n" , ent->s); + + ret2 =probe_file__del_strlist (ufd, ulist); +if (ret2 <0 ) + goto error; + } + +if (ret == -ENOENT && ret2 == -ENOENT ) +pr_debug ("\"%s\" does not hit any event.\n" , str); +/* Note that this is silently ignored */ + ret =0 ; + +error: +if (kfd >=0 ) +close (kfd); +if (ufd >=0 ) +close (ufd); +out: +strlist__delete (klist); +strlist__delete (ulist); +free (str); + +return ret; +} +static int __cmd_probe (int argc,const char **argv,const char *prefix__maybe_unused ) {
@@ -529,7 +589,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)return ret;#endif case 'd' : - ret =del_perf_probe_events (params.filter); + ret =perf_del_probe_events (params.filter);if (ret <0 ) {pr_err_with_code (" Error: Failed to delete events." , ret);return ret;
tools/perf/util/probe-event.c +0 -5
@@ -2819,8 +2819,6 @@ int del_perf_probe_events(struct strfilter *filter)if (!str)return -EINVAL ; -pr_debug ("Delete filter: \'%s\'\n" , str); -/* Get current event names */ ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW );if (ret <0 )
@@ -2835,9 +2833,6 @@ int del_perf_probe_events(struct strfilter *filter) ret = ret2; goto error; } -if (ret == -ENOENT && ret2 == -ENOENT ) -pr_debug ("\"%s\" does not hit any event.\n" , str); -/* Note that this is silently ignored */ ret =0 ; error:
tools/perf/util/probe-event.h +1 -0
@@ -144,6 +144,7 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int del_perf_probe_events (struct strfilter *filter); +extern int show_perf_probe_event (const char *group,const char *event,struct perf_probe_event *pev,const char *module,bool use_stdout);
tools/perf/util/probe-file.c +3 -4
@@ -267,7 +267,6 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) goto error; } -pr_info ("Removed event: %s\n" , ent->s);return 0 ; error: pr_warning("Failed to delete event: %s\n",
@@ -275,8 +274,8 @@ error:return ret; } -static int probe_file__get_events (int fd,struct strfilter *filter, -struct strlist *plist) +int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist) {struct strlist *namelist;struct str_node *ent;
@@ -300,7 +299,7 @@ static int probe_file__get_events(int fd, struct strfilter *filter,return ret; } -static int probe_file__del_strlist (int fd,struct strlist *namelist) +int probe_file__del_strlist (int fd,struct strlist *namelist) {int ret =0 ;struct str_node *ent;
tools/perf/util/probe-file.h +4 -0
@@ -14,5 +14,9 @@ struct strlist *probe_file__get_namelist(int fd);struct strlist *probe_file__get_rawlist (int fd);int probe_file__add_event (int fd,struct probe_trace_event *tev);int probe_file__del_events (int fd,struct strfilter *filter); +int probe_file__get_events (int fd,struct strfilter *filter, +struct strlist *plist); +int probe_file__del_strlist (int fd,struct strlist *namelist); +#endif
Hi Namhyung,
Thanks for this patchset.
Could you plase have a look at patch 5/27 and 6/27 in my newest pull request? These 2 patches utilize new probing API to create probe point and collect probe_trace_events. I'm not very sure I fully understand your design principle, especially the cleanup part, because I can see different functions dealing with cleanup:
cleanup_perf_probe_eventsdel_perf_probe_eventsclear_perf_probe_eventclear_probe_trace_event
But non of them works perfectly for me.
In bpf_prog_priv__clear() function of 6/27, I copied some code from cleanup_perf_probe_events(), because I think when destroying bpf programs, the probe_trace_events should also be cleanuped, but we don't need call exit_symbol_maps() many times, because we are in 'perf record', and not sure whether other parts of perf need symbol maps. Otherwise I think directly calling cleanup_perf_probe_events() sould be better.
You can find patch from:
http://lkml.kernel.org/n/[email protected]
http://lkml.kernel.org/n/[email protected]
Thank you.
Quoted 93 lines · Namhyung Kim
The
add_perf_probe_events()does 3 things:1. convert all perf events to trace events
2. add all trace events to kernel
3. cleanup all trace eventsBut sometimes we need to do something with the trace events. So split the funtion into three, so that it can access intermediate trace events via struct
__event_packageif needed.Acked-by Masami Hiramatsu <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/probe-event.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)tools/perf/util/probe-event.c +35
-4@@ -2765,9 +2765,10 @@ struct __event_package {int ntevs; }; -int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +static int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs, +struct __event_package **ppkgs) { -int i, j, ret; +int i, ret;struct __event_package *pkgs; ret =0 ;@@ -2792,12 +2793,21 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs) ret =convert_to_probe_trace_events (pkgs[i].pev, &pkgs[i].tevs);if (ret <0 ) - goto end; +return ret; pkgs[i].ntevs = ret; }/* This just release blacklist only if allocated */ kprobe_blacklist__release (); + *ppkgs = pkgs; + +return 0 ; +} + +static int apply_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, ret =0 ; +/* Loop 2: add all events */ for (i =0 ; i < npevs; i++) { ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,@@ -2806,7 +2816,16 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)if (ret <0 )break ; } -end: +return ret; +} + +static void cleanup_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, j; + +if (pkgs ==NULL ) +return ; +/* Loop 3: cleanup and free trace events */ for (i =0 ; i < npevs; i++) {for (j =0 ; j < pkgs[i].ntevs; j++)@@ -2815,6 +2834,18 @@ end: }free (pkgs);exit_symbol_maps (); +} + +int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +{ +int ret; +struct __event_package *pkgs =NULL ; + + ret =convert_perf_probe_events (pevs, npevs, &pkgs); +if (ret ==0 ) + ret =apply_perf_probe_events (pkgs, npevs); + +cleanup_perf_probe_events (pkgs, npevs);return ret; }
Namhyung Kim
maintainerQuoted 1 line · Wangnan (F)
Hi Namhyung,
Hi,
I'm off until Wednesday. I'll be able to take a look at it on Thursday.
Thanks,
Namhyung
Quoted 127 lines
Thanks for this patchset.
Could you plase have a look at patch 5/27 and 6/27 in my newest pull request?
These 2 patches utilize new probing API to create probe point and collectprobe_trace_events. I'm not very sure I fully understand your design principle,
especially the cleanup part, because I can see different functions dealing with
cleanup:
cleanup_perf_probe_eventsdel_perf_probe_eventsclear_perf_probe_eventclear_probe_trace_eventBut non of them works perfectly for me.
In
bpf_prog_priv__clear()function of 6/27, I copied some code fromcleanup_perf_probe_events(), because I think when destroying bpf programs, theprobe_trace_eventsshould also be cleanuped, but we don't need callexit_symbol_maps()many times, because we are in 'perf record', and not sure whether other parts of perf need symbol maps. Otherwise I think directly
callingcleanup_perf_probe_events()sould be better.You can find patch from:
http://lkml.kernel.org/n/[email protected]
http://lkml.kernel.org/n/[email protected]
Thank you.
Quoted 89 lines · Namhyung Kim
The
add_perf_probe_events()does 3 things:1. convert all perf events to trace events
2. add all trace events to kernel
3. cleanup all trace eventsBut sometimes we need to do something with the trace events. So split the funtion into three, so that it can access intermediate trace events via struct
__event_packageif needed.Acked-by Masami Hiramatsu <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/probe-event.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)tools/perf/util/probe-event.c +35
-4@@ -2765,9 +2765,10 @@ struct __event_package {int ntevs; }; -int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +static int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs, +struct __event_package **ppkgs) { -int i, j, ret; +int i, ret;struct __event_package *pkgs; ret =0 ;@@ -2792,12 +2793,21 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs) ret =convert_to_probe_trace_events (pkgs[i].pev, &pkgs[i].tevs);if (ret <0 ) - goto end; +return ret; pkgs[i].ntevs = ret; }/* This just release blacklist only if allocated */ kprobe_blacklist__release (); + *ppkgs = pkgs; + +return 0 ; +} + +static int apply_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, ret =0 ; +/* Loop 2: add all events */ for (i =0 ; i < npevs; i++) { ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,@@ -2806,7 +2816,16 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)if (ret <0 )break ; } -end: +return ret; +} + +static void cleanup_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, j; + +if (pkgs ==NULL ) +return ; +/* Loop 3: cleanup and free trace events */ for (i =0 ; i < npevs; i++) {for (j =0 ; j < pkgs[i].ntevs; j++)@@ -2815,6 +2834,18 @@ end: }free (pkgs);exit_symbol_maps (); +} + +int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +{ +int ret; +struct __event_package *pkgs =NULL ; + + ret =convert_perf_probe_events (pevs, npevs, &pkgs); +if (ret ==0 ) + ret =apply_perf_probe_events (pkgs, npevs); + +cleanup_perf_probe_events (pkgs, npevs);return ret; }
Namhyung Kim
maintainerQuoted 1 line · Wangnan (F)
Hi Namhyung,
Hi,
Quoted 12 lines
Thanks for this patchset.
Could you plase have a look at patch 5/27 and 6/27 in my newest pull request?
These 2 patches utilize new probing API to create probe point and collectprobe_trace_events. I'm not very sure I fully understand your design principle,
especially the cleanup part, because I can see different functions dealing with
cleanup:
Quoted 6 lines
cleanup_perf_probe_eventsdel_perf_probe_eventsclear_perf_probe_eventclear_probe_trace_eventBut non of them works perfectly for me.
The cleanup_perf_probe_events() is just to keep the existing logic as long as possible. But I think it needs to call clear_perf_probe_event().
The del_perf_probe_events() uses strfilter, but I think it can be problematic if other instances or users are using similar events at the same time.
So for your case, IMHO it'd better keeping the perf/trace events after probing and reusing the events for unprobing. I'll take a look at it.
Quoted 8 lines
In
bpf_prog_priv__clear()function of 6/27, I copied some code fromcleanup_perf_probe_events(), because I think when destroying bpf programs, theprobe_trace_eventsshould also be cleanuped, but we don't need callexit_symbol_maps()many times, because we are in 'perf record', and not sure whether other parts of perf need symbol maps. Otherwise I think directly
callingcleanup_perf_probe_events()sould be better.
Yeah, I also think exit_symbol_maps() should not be a part of the cleanup. I'll send a patch soon.
Quoted 6 lines
You can find patch from:
Thanks for your work!
Namhyung
Quoted 20 lines
From: Namhyung Kim [mailto:[email protected]] On Behalf Of Namhyung Kim
Quoted 1 line · Wangnan (F)
Hi Namhyung,
Hi,
Quoted 13 lines
Thanks for this patchset.
Could you plase have a look at patch 5/27 and 6/27 in my newest pull request?
These 2 patches utilize new probing API to create probe point and collectprobe_trace_events. I'm not very sure I fully understand your design principle,
especially the cleanup part, because I can see different functions dealing with
cleanup:
cleanup_perf_probe_events
This is for clearing an array of probe events.
Quoted 1 line
Quoted 1 line
del_perf_probe_events
This is not for cleanup, but for removing probes in the kernel.
Quoted 2 lines
Quoted 2 lines
clear_perf_probe_eventclear_probe_trace_event
These are the cleanup each event. Ah, right, since now perf_probe_event has probe_trace_events, clear_perf_probe_event has to call clear_probe_trace_event.
Quoted 10 lines
Quoted 2 lines
But non of them works perfectly for me.
The
cleanup_perf_probe_events()is just to keep the existing logic as long as possible. But I think it needs to callclear_perf_probe_event().The
del_perf_probe_events()uses strfilter, but I think it can be problematic if other instances or users are using similar events at the same time.
Yeah, since perf probe doesn't lock the ftrace, there should be a timing bug, but it can be fixed easily by ignoring -ENOENT. :)
Quoted 13 lines
So for your case, IMHO it'd better keeping the perf/trace events after probing and reusing the events for unprobing. I'll take a look at it.
Quoted 8 lines
In
bpf_prog_priv__clear()function of 6/27, I copied some code fromcleanup_perf_probe_events(), because I think when destroying bpf programs, theprobe_trace_eventsshould also be cleanuped, but we don't need callexit_symbol_maps()many times, because we are in 'perf record', and not sure whether other parts of perf need symbol maps. Otherwise I think directly
callingcleanup_perf_probe_events()sould be better.
Quoted 2 lines
Yeah, I also think
exit_symbol_maps()should not be a part of the cleanup. I'll send a patch soon.
OK.
Thanks! ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Namhyung Kim
maintainerHi Masami,
Quoted 7 lines · 平松雅巳 / HIRAMATU,MASAMI
Quoted 4 lines
From: Namhyung Kim [mailto:[email protected]] On Behalf Of Namhyung Kim The
del_perf_probe_events()uses strfilter, but I think it can be problematic if other instances or users are using similar events at the same time.Yeah, since perf probe doesn't lock the ftrace, there should be a timing bug, but it can be fixed easily by ignoring
-ENOENT. :)
By ignoring -ENOENT? Are you saying that there's a race between two deleters? Yes, of course, but I think that the bug will hit an adder and a deleter especially if automatic probing is used (by eBPF and/or SDT recording).
What about this?
Quoted 1 line
From
45dba35cb0f5fa1b2e78fec8c05faf5e9a1b200eMon Sep 17 00:00:00 2001
From: Namhyung Kim <[email protected]>
Date: Thu, 10 Sep 2015 15:25:28 +0900
Subject: [PATCH] perf probe: Support deleting trace events directly
Currently del_perf_probe_events() deletes events which match to a given filter. But it might have a timing bug when other users also set probes with similar names. So it'd be better deleting our events directly rather than pattern matching.
Since the del_perf_probe_events() has no user at this time, change it to receive perf_probe_event's. It is more consistent to other APIs as well.
--- tools/perf/util/probe-event.c | 30 +++++++++++------------------- tools/perf/util/probe-event.h | 2 +- tools/perf/util/probe-file.c | 24 ++++++++++++++++++++++++ tools/perf/util/probe-file.h | 1 + 4 files changed, 37 insertions(+), 20 deletions(-)
tools/perf/util/probe-event.c +11 -19
@@ -2810,37 +2810,29 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)return ret; } -int del_perf_probe_events (struct strfilter *filter) +int del_perf_probe_events (struct perf_probe_event *pevs,int npevs) { -int ret, ret2, ufd =-1 , kfd =-1 ; -char *str =strfilter__string (filter); +int i, j, ret, ret2; +int ufd =-1 , kfd =-1 ; -if (!str) -return -EINVAL ; - -/* Get current event names */ ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW );if (ret <0 ) - goto out; +return ret; - ret =probe_file__del_events (kfd, filter); -if (ret <0 && ret != -ENOENT ) - goto error; +for (i =0 ; i < npevs; i++) { +int fd = pevs[i].uprobes ? ufd : kfd; - ret2 =probe_file__del_events (ufd, filter); -if (ret2 <0 && ret2 != -ENOENT ) { - ret = ret2; - goto error; +for (j =0 ; j < pevs[i].ntevs; j++) { + ret2 =probe_file__del_trace_event (fd, &pevs[i].tevs[j]); +if (ret ==0 ) + ret = ret2; + } } - ret =0 ; -error:if (kfd >=0 )close (kfd);if (ufd >=0 )close (ufd); -out: -free (str);return ret; }
tools/perf/util/probe-event.h +1 -1
@@ -145,7 +145,7 @@ extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);extern int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs); -extern int del_perf_probe_events (struct strfilter *filter); +extern int del_perf_probe_events (struct perf_probe_event *pevs,int npevs); extern int show_perf_probe_event(const char *group, const char *event, struct perf_probe_event *pev,
tools/perf/util/probe-file.c +24 -0
@@ -319,3 +319,27 @@ int probe_file__del_events(int fd, struct strfilter *filter)return ret; } + +int probe_file__del_trace_event (int fd,struct probe_trace_event *tev) +{ +char buf[128 ]; +int ret; + +/* Convert from perf-probe event to trace-probe event */ + ret =e_snprintf (buf,128 ,"-:%s/%s" , tev->group, tev->event); +if (ret <0 ) + goto error; + +pr_debug ("Writing event: %s\n" , buf); + ret =write (fd, buf,strlen (buf)); +if (ret <0 ) { + ret = -errno; + goto error; + } + +return 0 ; +error: +pr_warning ("Failed to delete event: %s\n" , +strerror_r (-ret, buf,sizeof (buf))); +return ret; +}
tools/perf/util/probe-file.h +1 -0
@@ -17,6 +17,7 @@ int probe_file__del_events(int fd, struct strfilter *filter);int probe_file__get_events (int fd,struct strfilter *filter,struct strlist *plist);int probe_file__del_strlist (int fd,struct strlist *namelist); +int probe_file__del_trace_event (int fd,struct probe_trace_event *tev);#endif
Signature · 1 line
2.5.0
Hi Namhyung,
From: Namhyung Kim [mailto:[email protected]] On Behalf Of Namhyung Kim
Quoted 9 lines
Hi Masami,
Quoted 5 lines · 平松雅巳 / HIRAMATU,MASAMI
Quoted 4 lines
From: Namhyung Kim [mailto:[email protected]] On Behalf Of Namhyung Kim The
del_perf_probe_events()uses strfilter, but I think it can be problematic if other instances or users are using similar events at the same time.
Quoted 7 lines
Quoted 2 lines
Yeah, since perf probe doesn't lock the ftrace, there should be a timing bug, but it can be fixed easily by ignoring
-ENOENT. :)By ignoring
-ENOENT? Are you saying that there's a race between two deleters? Yes, of course, but I think that the bug will hit an adder and a deleter especially if automatic probing is used (by eBPF and/or SDT recording).
So, I don't think we need the automatic event removing. Instead, I'd like to suggest to keep it on the list.
Quoted 1 line
What about this?
Since probe events are identified only by its name, strfilter still works. You can remove specific event without any wildcard.
Thanks,
Quoted 134 lines
From
45dba35cb0f5fa1b2e78fec8c05faf5e9a1b200eMon Sep 17 00:00:00 2001
From: Namhyung Kim <[email protected]>
Date: Thu, 10 Sep 2015 15:25:28 +0900
Subject: [PATCH] perf probe: Support deleting trace events directlyCurrently
del_perf_probe_events()deletes events which match to a given filter. But it might have a timing bug when other users also set probes with similar names. So it'd be better deleting our events directly rather than pattern matching.Since the
del_perf_probe_events()has no user at this time, change it to receive perf_probe_event's. It is more consistent to other APIs as well.Cc Masami Hiramatsu <[email protected]>Cc Wang Nan <[email protected]>Signed-off-by Namhyung Kim <[email protected]>---
tools/perf/util/probe-event.c | 30 +++++++++++------------------- tools/perf/util/probe-event.h | 2 +- tools/perf/util/probe-file.c | 24 ++++++++++++++++++++++++ tools/perf/util/probe-file.h | 1 + 4 files changed, 37 insertions(+), 20 deletions(-)tools/perf/util/probe-event.c +11
-19@@ -2810,37 +2810,29 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)return ret; } -int del_perf_probe_events (struct strfilter *filter) +int del_perf_probe_events (struct perf_probe_event *pevs,int npevs) { -int ret, ret2, ufd =-1 , kfd =-1 ; -char *str =strfilter__string (filter); +int i, j, ret, ret2; +int ufd =-1 , kfd =-1 ; -if (!str) -return -EINVAL ; - -/* Get current event names */ ret =probe_file__open_both (&kfd, &ufd,PF_FL_RW );if (ret <0 ) - goto out; +return ret; - ret =probe_file__del_events (kfd, filter); -if (ret <0 && ret != -ENOENT ) - goto error; +for (i =0 ; i < npevs; i++) { +int fd = pevs[i].uprobes ? ufd : kfd; - ret2 =probe_file__del_events (ufd, filter); -if (ret2 <0 && ret2 != -ENOENT ) { - ret = ret2; - goto error; +for (j =0 ; j < pevs[i].ntevs; j++) { + ret2 =probe_file__del_trace_event (fd, &pevs[i].tevs[j]); +if (ret ==0 ) + ret = ret2; + } } - ret =0 ; -error:if (kfd >=0 )close (kfd);if (ufd >=0 )close (ufd); -out: -free (str);return ret; }tools/perf/util/probe-event.h +1
-1@@ -145,7 +145,7 @@ extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);extern int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern int apply_perf_probe_events (struct perf_probe_event *pevs,int npevs);extern void cleanup_perf_probe_events (struct perf_probe_event *pevs,int npevs); -extern int del_perf_probe_events (struct strfilter *filter); +extern int del_perf_probe_events (struct perf_probe_event *pevs,int npevs); extern int show_perf_probe_event(const char *group, const char *event, struct perf_probe_event *pev,tools/perf/util/probe-file.c +24
-0@@ -319,3 +319,27 @@ int probe_file__del_events(int fd, struct strfilter *filter)return ret; } + +int probe_file__del_trace_event (int fd,struct probe_trace_event *tev) +{ +char buf[128 ]; +int ret; + +/* Convert from perf-probe event to trace-probe event */ + ret =e_snprintf (buf,128 ,"-:%s/%s" , tev->group, tev->event); +if (ret <0 ) + goto error; + +pr_debug ("Writing event: %s\n" , buf); + ret =write (fd, buf,strlen (buf)); +if (ret <0 ) { + ret = -errno; + goto error; + } + +return 0 ; +error: +pr_warning ("Failed to delete event: %s\n" , +strerror_r (-ret, buf,sizeof (buf))); +return ret; +}tools/perf/util/probe-file.h +1
-1@@ -17,6 +17,7 @@ int probe_file__del_events(int fd, struct strfilter *filter);int probe_file__get_events (int fd,struct strfilter *filter,struct strlist *plist);int probe_file__del_strlist (int fd,struct strlist *namelist); +int probe_file__del_trace_event (int fd,struct probe_trace_event *tev);#endif --
Quoted 1 line
2.5.0
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Namhyung Kim
maintainerQuoted 15 lines · 平松雅巳 / HIRAMATU,MASAMI
Hi Namhyung,
From: Namhyung Kim [mailto:[email protected]] On Behalf Of Namhyung Kim
Quoted 12 lines
Hi Masami,
Quoted 7 lines · 平松雅巳 / HIRAMATU,MASAMI
Quoted 4 lines
From: Namhyung Kim [mailto:[email protected]] On Behalf Of Namhyung Kim The
del_perf_probe_events()uses strfilter, but I think it can be problematic if other instances or users are using similar events at the same time.Yeah, since perf probe doesn't lock the ftrace, there should be a timing bug, but it can be fixed easily by ignoring
-ENOENT. :)
Quoted 7 lines
Quoted 4 lines
By ignoring
-ENOENT? Are you saying that there's a race between two deleters? Yes, of course, but I think that the bug will hit an adder and a deleter especially if automatic probing is used (by eBPF and/or SDT recording).So, I don't think we need the automatic event removing. Instead, I'd like to suggest to keep it on the list.
But why? Do you want reuse the probes for next record session?
I think if something is generated automatically, it should be removed automatically..
Thanks,
Namhyung
tip-bot for Namhyung Kim
merge botperf probe: Split add_perf_probe_events()
Commit-ID: 844dffa598b55fca6a83a856214fc0cfc3da24e5 Gitweb: http://git.kernel.org/tip/844dffa598b55fca6a83a856214fc0cfc3da24e5 Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 4 Sep 2015 21:15:59 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 4 Sep 2015 12:33:02 -0300
perf probe: Split add_perf_probe_events()
The add_perf_probe_events() does 3 things:
1. convert all perf events to trace events
2. add all trace events to kernel
3. cleanup all trace events
But sometimes we need to do something with the trace events. So split the funtion into three, so that it can access intermediate trace events via struct __event_package if needed.
--- tools/perf/util/probe-event.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-)
tools/perf/util/probe-event.c +35 -4
@@ -2765,9 +2765,10 @@ struct __event_package {int ntevs; }; -int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +static int convert_perf_probe_events (struct perf_probe_event *pevs,int npevs, +struct __event_package **ppkgs) { -int i, j, ret; +int i, ret;struct __event_package *pkgs; ret =0 ;
@@ -2792,12 +2793,21 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs) ret =convert_to_probe_trace_events (pkgs[i].pev, &pkgs[i].tevs);if (ret <0 ) - goto end; +return ret; pkgs[i].ntevs = ret; }/* This just release blacklist only if allocated */ kprobe_blacklist__release (); + *ppkgs = pkgs; + +return 0 ; +} + +static int apply_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, ret =0 ; +/* Loop 2: add all events */ for (i =0 ; i < npevs; i++) { ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
@@ -2806,7 +2816,16 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)if (ret <0 )break ; } -end: +return ret; +} + +static void cleanup_perf_probe_events (struct __event_package *pkgs,int npevs) +{ +int i, j; + +if (pkgs ==NULL ) +return ; +/* Loop 3: cleanup and free trace events */ for (i =0 ; i < npevs; i++) {for (j =0 ; j < pkgs[i].ntevs; j++)
@@ -2815,6 +2834,18 @@ end: }free (pkgs);exit_symbol_maps (); +} + +int add_perf_probe_events (struct perf_probe_event *pevs,int npevs) +{ +int ret; +struct __event_package *pkgs =NULL ; + + ret =convert_perf_probe_events (pevs, npevs, &pkgs); +if (ret ==0 ) + ret =apply_perf_probe_events (pkgs, npevs); + +cleanup_perf_probe_events (pkgs, npevs);return ret; }