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

perf data: Support using -f to override perf.data file ownership for 'convert'

Enable perf data convert 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 17:35 perf.data
# id
uid=0(root) gid=0(root) groups=0(root),64(pkcs11)

Before this patch:

# perf data convert --to-ctf=./ctf-data/
File perf.data not owned by current user or root (use -f to override)
# perf data convert --to-ctf=./ctf-data/ -f
Error: unknown switch `f'

usage: perf data convert [<options>]

-v, --verbose be more verbose
-i, --input <file> input file name
--to-ctf ... Convert to CTF format

After this patch:

# perf data convert --to-ctf=./ctf-data/
File perf.data not owned by current user or root (use -f to override)
# perf data convert --to-ctf=./ctf-data/ -f
# ls ctf-data/
metadata perf_stream_0

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.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-11-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
bd05954b e366a6d8

+6 -3
+3 -1
tools/perf/builtin-data.c
··· 53 53 const char *prefix __maybe_unused) 54 54 { 55 55 const char *to_ctf = NULL; 56 + bool force = false; 56 57 const struct option options[] = { 57 58 OPT_INCR('v', "verbose", &verbose, "be more verbose"), 58 59 OPT_STRING('i', "input", &input_name, "file", "input file name"), 59 60 #ifdef HAVE_LIBBABELTRACE_SUPPORT 60 61 OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"), 61 62 #endif 63 + OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), 62 64 OPT_END() 63 65 }; 64 66 ··· 78 76 79 77 if (to_ctf) { 80 78 #ifdef HAVE_LIBBABELTRACE_SUPPORT 81 - return bt_convert__perf2ctf(input_name, to_ctf); 79 + return bt_convert__perf2ctf(input_name, to_ctf, force); 82 80 #else 83 81 pr_err("The libbabeltrace support is not compiled in.\n"); 84 82 return -1;
+2 -1
tools/perf/util/data-convert-bt.c
··· 791 791 return -1; 792 792 } 793 793 794 - int bt_convert__perf2ctf(const char *input, const char *path) 794 + int bt_convert__perf2ctf(const char *input, const char *path, bool force) 795 795 { 796 796 struct perf_session *session; 797 797 struct perf_data_file file = { 798 798 .path = input, 799 799 .mode = PERF_DATA_MODE_READ, 800 + .force = force, 800 801 }; 801 802 struct convert c = { 802 803 .tool = {
+1 -1
tools/perf/util/data-convert-bt.h
··· 2 2 #define __DATA_CONVERT_BT_H 3 3 #ifdef HAVE_LIBBABELTRACE_SUPPORT 4 4 5 - int bt_convert__perf2ctf(const char *input_name, const char *to_ctf); 5 + int bt_convert__perf2ctf(const char *input_name, const char *to_ctf, bool force); 6 6 7 7 #endif /* HAVE_LIBBABELTRACE_SUPPORT */ 8 8 #endif /* __DATA_CONVERT_BT_H */