perf inject: Support using -f to override perf.data file ownership
authorYunlong Song <yunlong.song@huawei.com>
Thu, 2 Apr 2015 13:47:11 +0000 (21:47 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Apr 2015 16:18:45 +0000 (13:18 -0300)
commitccaa474c8a0983d26ecb3eac755672b546b997c3
treef55eb9912c858dca30304fe60dfb282a3cc0b5bc
parent9e3b6ec17374299516d83c2e36135b958a895aa3
perf inject: Support using -f to override perf.data file ownership

Enable perf inject to use perf.data when it is not owned by current user
or root.

Example:

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

Before this patch:

 # perf inject -v -b -i perf.data -o perf.data.new
 File perf.data not owned by current user or root (use -f to override)
 # perf inject -v -b -i perf.data -o perf.data.new -f
   Error: unknown switch `f'

  usage: perf inject [<options>]

     -b, --build-ids       Inject build-ids into the output stream
     -i, --input <file>    input file name
     -o, --output <file>   output file name
     -s, --sched-stat      Merge sched-stat and sched-switch for getting
     events where and how long tasks slept
     -v, --verbose         be more verbose (show build ids, etc)
         --kallsyms <file>
                           kallsyms pathname

As shown above, the -f option does not work at all.

After this patch:

 # perf inject -v -b -i perf.data -o perf.data.new
 File perf.data not owned by current user or root (use -f to override)
 # perf inject -v -b -i perf.data -o perf.data.new -f
 build id event received for [kernel.kallsyms]:
 f6dcb66d8b98f1c0d9eb87bf043444b69f91d30c
 symsrc__init: cannot get elf header.
 Looking at the vmlinux_path (7 entries long)
 Using /proc/kcore for kernel object code
 Using /proc/kallsyms for symbols

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-3-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-inject.c