aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>2016-04-26 10:25:41 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-04-26 12:15:01 -0400
commit63a29613d7c69f17b6a3266bfc338986698b2546 (patch)
tree203ab2ee056aa24e076baeea55a59d2f4d8d8283 /tools
parent073e5fca53d30ffe9e2fc637a001c78b2cdca7dd (diff)
perf probe: Fix offline module name missmatch issue
Perf can add a probe on kernel module which has not been loaded yet. The current implementation finds the module name from path. But if the filename is different from the actual module name then perf fails to register a probe while loading module because of mismatch in the names. For example, samples/kobject/kobject-example.ko is loaded as kobject_example. Before applying patch: $ sudo ./perf probe -m /linux/samples/kobject/kobject-example.ko foo_show Added new event: probe:foo_show (on foo_show in kobject-example) You can now use it in all perf tools, such as: perf record -e probe:foo_show -aR sleep 1 $ cat /sys/kernel/debug/tracing/kprobe_events p:probe/foo_show kobject-example:foo_show $ insmod kobject-example.ko $ lsmod Module Size Used by kobject_example 16384 0 Generate read to /sys/kernel/kobject_example/foo while recording data with below command $ sudo ./perf record -e probe:foo_show -a [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.093 MB perf.data ] $./perf report --stdio -F overhead,comm,dso,sym Error: The perf.data.old file has no samples! After applying patch: $ sudo ./perf probe -m /linux/samples/kobject/kobject-example.ko foo_show Added new event: probe:foo_show (on foo_show in kobject_example) You can now use it in all perf tools, such as: perf record -e probe:foo_show -aR sleep 1 $ sudo cat /sys/kernel/debug/tracing/kprobe_events p:probe/foo_show kobject_example:foo_show $ insmod kobject-example.ko $ lsmod Module Size Used by kobject_example 16384 0 Generate read to /sys/kernel/kobject_example/foo while recording data with below command $ sudo ./perf record -e probe:foo_show -a [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.097 MB perf.data (8 samples) ] $ sudo ./perf report --stdio -F overhead,comm,dso,sym ... # Samples: 8 of event 'probe:foo_show' # Event count (approx.): 8 # # Overhead Command Shared Object Symbol # ........ ....... ................. ............ # 100.00% cat [kobject_example] [k] foo_show Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/r/1461680741-12517-2-git-send-email-ravi.bangoria@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/probe-event.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 0de5d10dda71..bc2eb7cda2d1 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -588,32 +588,23 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
588 int ntevs, const char *module) 588 int ntevs, const char *module)
589{ 589{
590 int i, ret = 0; 590 int i, ret = 0;
591 char *tmp; 591 char *mod_name = NULL;
592 592
593 if (!module) 593 if (!module)
594 return 0; 594 return 0;
595 595
596 tmp = strrchr(module, '/'); 596 mod_name = find_module_name(module);
597 if (tmp) {
598 /* This is a module path -- get the module name */
599 module = strdup(tmp + 1);
600 if (!module)
601 return -ENOMEM;
602 tmp = strchr(module, '.');
603 if (tmp)
604 *tmp = '\0';
605 tmp = (char *)module; /* For free() */
606 }
607 597
608 for (i = 0; i < ntevs; i++) { 598 for (i = 0; i < ntevs; i++) {
609 tevs[i].point.module = strdup(module); 599 tevs[i].point.module =
600 strdup(mod_name ? mod_name : module);
610 if (!tevs[i].point.module) { 601 if (!tevs[i].point.module) {
611 ret = -ENOMEM; 602 ret = -ENOMEM;
612 break; 603 break;
613 } 604 }
614 } 605 }
615 606
616 free(tmp); 607 free(mod_name);
617 return ret; 608 return ret;
618} 609}
619 610