aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorTom Zanussi <tzanussi@gmail.com>2009-12-15 03:53:35 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-15 04:31:31 -0500
commit586bc5cce88be993dad584c3936c49f945368551 (patch)
treef335951b59c1106918ced48a6e1242e131808225 /tools
parentc249a4ce796b30b742bb4854bf3039ced12ef8e5 (diff)
perf trace/scripting: Add support for script args
One oversight of the original scripting_ops patch was a lack of support for passing args to handler scripts. This adds argc/argv to the start_script() scripting_op, and changes the rw-by-file script to take 'comm' arg rather than the 'perf' value currently hard-coded. It also takes the opportunity to do some related minor cleanup. Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Cc: fweisbec@gmail.com Cc: rostedt@goodmis.org LKML-Reference: <1260867220-15699-2-git-send-email-tzanussi@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-trace.c19
-rw-r--r--tools/perf/scripts/perl/bin/rw-by-file-report2
-rw-r--r--tools/perf/scripts/perl/rw-by-file.pl5
-rw-r--r--tools/perf/util/trace-event-perl.c36
-rw-r--r--tools/perf/util/trace-event.h2
5 files changed, 38 insertions, 26 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 07da66511bd5..88b0353d4019 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -12,7 +12,9 @@
12static char const *script_name; 12static char const *script_name;
13static char const *generate_script_lang; 13static char const *generate_script_lang;
14 14
15static int default_start_script(const char *script __attribute((unused))) 15static int default_start_script(const char *script __unused,
16 int argc __unused,
17 const char **argv __unused)
16{ 18{
17 return 0; 19 return 0;
18} 20}
@@ -22,7 +24,7 @@ static int default_stop_script(void)
22 return 0; 24 return 0;
23} 25}
24 26
25static int default_generate_script(const char *outfile __attribute ((unused))) 27static int default_generate_script(const char *outfile __unused)
26{ 28{
27 return 0; 29 return 0;
28} 30}
@@ -302,15 +304,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
302 304
303 setup_scripting(); 305 setup_scripting();
304 306
305 argc = parse_options(argc, argv, options, annotate_usage, 0); 307 argc = parse_options(argc, argv, options, annotate_usage,
306 if (argc) { 308 PARSE_OPT_STOP_AT_NON_OPTION);
307 /*
308 * Special case: if there's an argument left then assume tha
309 * it's a symbol filter:
310 */
311 if (argc > 1)
312 usage_with_options(annotate_usage, options);
313 }
314 309
315 setup_pager(); 310 setup_pager();
316 311
@@ -350,7 +345,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
350 } 345 }
351 346
352 if (script_name) { 347 if (script_name) {
353 err = scripting_ops->start_script(script_name); 348 err = scripting_ops->start_script(script_name, argc, argv);
354 if (err) 349 if (err)
355 goto out; 350 goto out;
356 } 351 }
diff --git a/tools/perf/scripts/perl/bin/rw-by-file-report b/tools/perf/scripts/perl/bin/rw-by-file-report
index f5dcf9cb5bd2..1c0567516aba 100644
--- a/tools/perf/scripts/perl/bin/rw-by-file-report
+++ b/tools/perf/scripts/perl/bin/rw-by-file-report
@@ -1,5 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl 2perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $1
3 3
4 4
5 5
diff --git a/tools/perf/scripts/perl/rw-by-file.pl b/tools/perf/scripts/perl/rw-by-file.pl
index 61f91561d848..2a39097687b9 100644
--- a/tools/perf/scripts/perl/rw-by-file.pl
+++ b/tools/perf/scripts/perl/rw-by-file.pl
@@ -18,8 +18,9 @@ use lib "./Perf-Trace-Util/lib";
18use Perf::Trace::Core; 18use Perf::Trace::Core;
19use Perf::Trace::Util; 19use Perf::Trace::Util;
20 20
21# change this to the comm of the program you're interested in 21my $usage = "perf trace -s rw-by-file.pl <comm>\n";
22my $for_comm = "perf"; 22
23my $for_comm = shift or die $usage;
23 24
24my %reads; 25my %reads;
25my %writes; 26my %writes;
diff --git a/tools/perf/util/trace-event-perl.c b/tools/perf/util/trace-event-perl.c
index a5ffe60db5d6..6f10e7602452 100644
--- a/tools/perf/util/trace-event-perl.c
+++ b/tools/perf/util/trace-event-perl.c
@@ -267,7 +267,7 @@ int common_lock_depth(struct scripting_context *context)
267} 267}
268 268
269static void perl_process_event(int cpu, void *data, 269static void perl_process_event(int cpu, void *data,
270 int size __attribute((unused)), 270 int size __unused,
271 unsigned long long nsecs, char *comm) 271 unsigned long long nsecs, char *comm)
272{ 272{
273 struct format_field *field; 273 struct format_field *field;
@@ -359,28 +359,42 @@ static void run_start_sub(void)
359/* 359/*
360 * Start trace script 360 * Start trace script
361 */ 361 */
362static int perl_start_script(const char *script) 362static int perl_start_script(const char *script, int argc, const char **argv)
363{ 363{
364 const char *command_line[2] = { "", NULL }; 364 const char **command_line;
365 int i, err = 0;
365 366
367 command_line = malloc((argc + 2) * sizeof(const char *));
368 command_line[0] = "";
366 command_line[1] = script; 369 command_line[1] = script;
370 for (i = 2; i < argc + 2; i++)
371 command_line[i] = argv[i - 2];
367 372
368 my_perl = perl_alloc(); 373 my_perl = perl_alloc();
369 perl_construct(my_perl); 374 perl_construct(my_perl);
370 375
371 if (perl_parse(my_perl, xs_init, 2, (char **)command_line, 376 if (perl_parse(my_perl, xs_init, argc + 2, (char **)command_line,
372 (char **)NULL)) 377 (char **)NULL)) {
373 return -1; 378 err = -1;
379 goto error;
380 }
374 381
375 perl_run(my_perl); 382 perl_run(my_perl);
376 if (SvTRUE(ERRSV)) 383 if (SvTRUE(ERRSV)) {
377 return -1; 384 err = -1;
385 goto error;
386 }
378 387
379 run_start_sub(); 388 run_start_sub();
380 389
390 free(command_line);
381 fprintf(stderr, "perf trace started with Perl script %s\n\n", script); 391 fprintf(stderr, "perf trace started with Perl script %s\n\n", script);
382
383 return 0; 392 return 0;
393error:
394 perl_free(my_perl);
395 free(command_line);
396
397 return err;
384} 398}
385 399
386/* 400/*
@@ -579,7 +593,9 @@ static void print_unsupported_msg(void)
579 "\n etc.\n"); 593 "\n etc.\n");
580} 594}
581 595
582static int perl_start_script_unsupported(const char *script __unused) 596static int perl_start_script_unsupported(const char *script __unused,
597 int argc __unused,
598 const char **argv __unused)
583{ 599{
584 print_unsupported_msg(); 600 print_unsupported_msg();
585 601
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 81698d5e6503..6ad405620c9b 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -270,7 +270,7 @@ enum trace_flag_type {
270 270
271struct scripting_ops { 271struct scripting_ops {
272 const char *name; 272 const char *name;
273 int (*start_script) (const char *); 273 int (*start_script) (const char *script, int argc, const char **argv);
274 int (*stop_script) (void); 274 int (*stop_script) (void);
275 void (*process_event) (int cpu, void *data, int size, 275 void (*process_event) (int cpu, void *data, int size,
276 unsigned long long nsecs, char *comm); 276 unsigned long long nsecs, char *comm);