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

perf script: Support using -f to override perf.data file ownership

Enable perf script to use perf.data when it is not owned by current user
or root. Change the short option name of --fields to -F to avoid confusion
with --force.

Example:

# perf record ls
# chown Yunlong.Song:Yunlong.Song perf.data
# ls -al perf.data
-rw------- 1 Yunlong.Song Yunlong.Song 28360 Apr 2 14:53 perf.data
# id
uid=0(root) gid=0(root) groups=0(root),64(pkcs11)

Before this patch:

# perf script
File perf.data not owned by current user or root (use -f to override)
# perf script -f
Error: switch `f' requires a value

usage: perf script [<options>]
or: perf script [<options>] record <script> [<record-options>] <command>
or: perf script [<options>] report <script> [script-args]
or: perf script [<options>] <script> [<record-options>] <command>
or: perf script [<options>] <top-script> [script-args]

-f, --fields <str> comma separated output fields prepend with
'type:'. Valid types: hw,sw,trace,raw. Fields:
comm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr,symoff,period

As shown above, the -f option does not work at all. And -f is already
taken up by --fields, which makes --force confused, so change the short
option name of --fields to -F like what other perf commands do (e.g.
perf report -F) and use -f as the short option name of --force.

After this patch:

# perf script
File perf.data not owned by current user or root (use -f to override)
# perf script -f
:41298 41298 2590086.564226: 1 cycles: ffffffff8103efc6
native_write_msr_safe ([kernel.kallsyms])
:41298 41298 2590086.564244: 1 cycles: ffffffff8103efc6
native_write_msr_safe ([kernel.kallsyms])
:41298 41298 2590086.564249: 7 cycles: ffffffff8103efc6
native_write_msr_safe ([kernel.kallsyms])
:41298 41298 2590086.564255: 176 cycles: ffffffff8103efc6
native_write_msr_safe ([kernel.kallsyms])
ls 41298 2590086.567346: 4059 cycles: ffffffff8105a592
raise_softirq ([kernel.kallsyms])
ls 41298 2590086.567353: 3717 cycles: ffffffff8105a592
raise_softirq ([kernel.kallsyms])
ls 41298 2590086.567358: 63058 cycles: ffffffff8105a592
raise_softirq ([kernel.kallsyms])
ls 41298 2590086.567448: 1706255 cycles: 406ae0
[unknown] (/usr/bin/ls)

As shown above, the -f option really works now.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1427982439-27388-8-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Yunlong Song and committed by
Arnaldo Carvalho de Melo
06af0f2c 62a1a63a

+5 -4
+5 -4
tools/perf/builtin-script.c
··· 1515 1515 .ordering_requires_timestamps = true, 1516 1516 }, 1517 1517 }; 1518 + struct perf_data_file file = { 1519 + .mode = PERF_DATA_MODE_READ, 1520 + }; 1518 1521 const struct option options[] = { 1519 1522 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, 1520 1523 "dump raw trace in ASCII"), ··· 1545 1542 "When printing symbols do not display call chain"), 1546 1543 OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory", 1547 1544 "Look for files with symbols relative to this directory"), 1548 - OPT_CALLBACK('f', "fields", NULL, "str", 1545 + OPT_CALLBACK('F', "fields", NULL, "str", 1549 1546 "comma separated output fields prepend with 'type:'. " 1550 1547 "Valid types: hw,sw,trace,raw. " 1551 1548 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," ··· 1569 1566 "Show the fork/comm/exit events"), 1570 1567 OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events, 1571 1568 "Show the mmap events"), 1569 + OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), 1572 1570 OPT_END() 1573 1571 }; 1574 1572 const char * const script_subcommands[] = { "record", "report", NULL }; ··· 1580 1576 "perf script [<options>] <script> [<record-options>] <command>", 1581 1577 "perf script [<options>] <top-script> [script-args]", 1582 1578 NULL 1583 - }; 1584 - struct perf_data_file file = { 1585 - .mode = PERF_DATA_MODE_READ, 1586 1579 }; 1587 1580 1588 1581 setup_scripting();