Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf script: Allow the generated script to be a path

Allow the script generated by "perf script -g <language>" to be a file
path and the language determined by the file extension.

This is useful in testing so that the generated script file can be
written to a test directory.

Committer testing:

$ perf record ls a.a
ls: cannot access 'a.a': No such file or directory
[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.003 MB perf.data (7 samples) ]
$ perf script -g python
generated Python script: perf-script.py
$ perf script -g myscript.py
generated Python script: myscript.py
$ diff -u perf-script.py myscript.py
$ tail myscript.py
def trace_unhandled(event_name, context, event_fields_dict, perf_sample_dict):
print(get_dict_as_string(event_fields_dict))
print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')

def print_header(event_name, cpu, secs, nsecs, pid, comm):
print("%-20s %5u %05u.%09u %8u %-20s " % \
(event_name, cpu, secs, nsecs, pid, comm), end="")

def get_dict_as_string(a_dict, delimiter=' '):
return delimiter.join(['%s=%s'%(k,str(v))for k,v in sorted(a_dict.items())])
$

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Yujie Liu <yujie.liu@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
22ca2f7f 9083ce53

+24 -6
+4 -2
tools/perf/Documentation/perf-script.txt
··· 98 98 99 99 -g:: 100 100 --gen-script=:: 101 - Generate perf-script.[ext] starter script for given language, 102 - using current perf.data. 101 + Generate a starter script. If a language is given then the 102 + script is named perf-script.[ext] according to the 103 + language. If a file path is given then python is used for 104 + files ending '.py' and perl used for files ending '.pl'. 103 105 104 106 --dlfilter=<file>:: 105 107 Filter sample events using the given shared object file.
+20 -4
tools/perf/builtin-script.c
··· 4489 4489 if (generate_script_lang) { 4490 4490 struct stat perf_stat; 4491 4491 int input; 4492 + char *filename = strdup("perf-script"); 4492 4493 4493 4494 if (output_set_by_user()) { 4494 4495 fprintf(stderr, ··· 4517 4516 } 4518 4517 4519 4518 scripting_ops = script_spec__lookup(generate_script_lang); 4519 + if (!scripting_ops && ends_with(generate_script_lang, ".py")) { 4520 + scripting_ops = script_spec__lookup("python"); 4521 + free(filename); 4522 + filename = strdup(generate_script_lang); 4523 + filename[strlen(filename) - 3] = '\0'; 4524 + } else if (!scripting_ops && ends_with(generate_script_lang, ".pl")) { 4525 + scripting_ops = script_spec__lookup("perl"); 4526 + free(filename); 4527 + filename = strdup(generate_script_lang); 4528 + filename[strlen(filename) - 3] = '\0'; 4529 + } 4520 4530 if (!scripting_ops) { 4521 - fprintf(stderr, "invalid language specifier"); 4531 + fprintf(stderr, "invalid language specifier '%s'\n", generate_script_lang); 4522 4532 err = -ENOENT; 4523 4533 goto out_delete; 4524 4534 } 4535 + if (!filename) { 4536 + err = -ENOMEM; 4537 + goto out_delete; 4538 + } 4525 4539 #ifdef HAVE_LIBTRACEEVENT 4526 - err = scripting_ops->generate_script(session->tevent.pevent, 4527 - "perf-script"); 4540 + err = scripting_ops->generate_script(session->tevent.pevent, filename); 4528 4541 #else 4529 - err = scripting_ops->generate_script(NULL, "perf-script"); 4542 + err = scripting_ops->generate_script(NULL, filename); 4530 4543 #endif 4544 + free(filename); 4531 4545 goto out_delete; 4532 4546 } 4533 4547