2015-04-02 13:48:01

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 00/10] perf tools: Support using -f to override file ownership for perf commands

Hi,
Enable perf commands to use perf file when it is not owned by current
user or root.

Yunlong Song (10):
perf tools: Support using -f to override perf.data file ownership for
evlist
perf tools: Support using -f to override perf.data file ownership for
inject
perf tools: Support using -f to override perf.data file ownership for
kmem
perf tools: Support using -f to override perf.data.guest file
ownership for kvm
perf tools: Support using -f to override perf.data file ownership for
lock
perf tools: Support using -f to override perf.data file ownership for
mem
perf tools: Support using -f to override perf.data file ownership for
script
perf tools: Support using -f to override perf.data file ownership for
timechart
perf tools: Support using -f to override perf.data file ownership for
trace
perf tools: Support using -f to override perf.data file ownership for
data convert

tools/perf/builtin-data.c | 4 +++-
tools/perf/builtin-evlist.c | 2 ++
tools/perf/builtin-inject.c | 1 +
tools/perf/builtin-kmem.c | 9 +++++----
tools/perf/builtin-kvm.c | 2 ++
tools/perf/builtin-lock.c | 5 +++++
tools/perf/builtin-mem.c | 3 +++
tools/perf/builtin-script.c | 9 +++++----
tools/perf/builtin-timechart.c | 3 +++
tools/perf/builtin-trace.c | 3 +++
tools/perf/util/data-convert-bt.c | 3 ++-
tools/perf/util/data-convert-bt.h | 2 +-
tools/perf/util/evsel.h | 1 +
tools/perf/util/kvm-stat.h | 1 +
14 files changed, 37 insertions(+), 11 deletions(-)

--
1.8.5.2


2015-04-02 13:45:08

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 01/10] perf tools: Support using -f to override perf.data file ownership for evlist

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

Before this patch:

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

usage: perf evlist [<options>]

-i, --input <file> Input file name
-F, --freq Show the sample frequency
-v, --verbose Show all event attr details
-g, --group Show event group information

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

After this patch:

# perf evlist
File perf.data not owned by current user or root (use -f to override)
# perf evlist -f
cycles

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

Signed-off-by: Yunlong Song <[email protected]>
---
tools/perf/builtin-evlist.c | 2 ++
tools/perf/util/evsel.h | 1 +
2 files changed, 3 insertions(+)

diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 0f93f85..695ec5a 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -24,6 +24,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
struct perf_data_file file = {
.path = file_name,
.mode = PERF_DATA_MODE_READ,
+ .force = details->force,
};

session = perf_session__new(&file, 0, NULL);
@@ -47,6 +48,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
"Show all event attr details"),
OPT_BOOLEAN('g', "group", &details.event_group,
"Show event group information"),
+ OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
OPT_END()
};
const char * const evlist_usage[] = {
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index dcf202a..c5a43d6 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -335,6 +335,7 @@ struct perf_attr_details {
bool freq;
bool verbose;
bool event_group;
+ bool force;
};

int perf_evsel__fprintf(struct perf_evsel *evsel,
--
1.8.5.2

2015-04-02 13:46:11

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 02/10] perf tools: Support using -f to override perf.data file ownership for inject

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 <[email protected]>
---
tools/perf/builtin-inject.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index ea46df25..40a33d7 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -443,6 +443,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
"be more verbose (show build ids, etc)"),
OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file",
"kallsyms pathname"),
+ OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
OPT_END()
};
const char * const inject_usage[] = {
--
1.8.5.2

2015-04-02 13:44:57

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 03/10] perf tools: Support using -f to override perf.data file ownership for kmem

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

Example:

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

Before this patch:

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

usage: perf kmem [<options>] {record|stat}

-i, --input <file> input file name
-v, --verbose be more verbose (show symbol address, etc)
--caller show per-callsite statistics
--alloc show per-allocation statistics
-s, --sort <key[,key2...]>
sort by keys: ptr, call_site, bytes, hit,
pingpong, frag
-l, --line <num> show n lines
--raw-ip show raw ip instead of symbol

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

After this patch:

# perf kmem stat
File perf.data not owned by current user or root (use -f to override)
# perf kmem stat -f
SUMMARY
=======
Total bytes requested: 437599
Total bytes allocated: 615472
Total bytes wasted on internal fragmentation: 177873
Internal fragmentation: 28.900259%
Cross CPU allocations: 6/1192

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

Signed-off-by: Yunlong Song <[email protected]>
---
tools/perf/builtin-kmem.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 64d3623..ac303ef 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -662,6 +662,10 @@ static int __cmd_record(int argc, const char **argv)
int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
{
const char * const default_sort_order = "frag,hit,bytes";
+ struct perf_data_file file = {
+ .path = input_name,
+ .mode = PERF_DATA_MODE_READ,
+ };
const struct option kmem_options[] = {
OPT_STRING('i', "input", &input_name, "file", "input file name"),
OPT_INCR('v', "verbose", &verbose,
@@ -675,6 +679,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
parse_sort_opt),
OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt),
OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
+ OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
OPT_END()
};
const char *const kmem_subcommands[] = { "record", "stat", NULL };
@@ -683,10 +688,6 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
NULL
};
struct perf_session *session;
- struct perf_data_file file = {
- .path = input_name,
- .mode = PERF_DATA_MODE_READ,
- };
int ret = -1;

argc = parse_options_subcommand(argc, argv, kmem_options,
--
1.8.5.2

2015-04-02 13:44:54

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 04/10] perf tools: Support using -f to override perf.data.guest file ownership for kvm

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

Example:

# perf kvm stat record ls
# chown Yunlong.Song:Yunlong.Song perf.data.guest
# ls -al perf.data.guest
-rw------- 1 Yunlong.Song Yunlong.Song 4128937 Apr 2 11:05 perf.data.guest
# id
uid=0(root) gid=0(root) groups=0(root),64(pkcs11)

Before this patch:

# perf kvm stat report
File perf.data.guest not owned by current user or root (use -f to override)
Initializing perf session failed
# perf kvm stat report -f
Error: unknown switch `f'

usage: perf kvm stat report [<options>]

--event <report event>
event for reporting: vmexit, mmio (x86 only),
ioport (x86 only)
--vcpu <n> vcpu id to report
-k, --key <sort-key> key for sorting: sample(sort by samples
number) time (sort by avg time)
-p, --pid <pid> analyze events only for given process id(s)

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

After this patch:

# perf kvm stat report
File perf.data.guest not owned by current user or root (use -f to override)
Initializing perf session failed
# perf kvm stat report -f
Analyze events for all VMs, all VCPUs:

VM-EXIT Samples Samples% Time% Min Time Max Time Avg time

Total Samples:0, Total events handled time:0.00us.

As shown above, the -f option really works now. Since we have not
launched any KVM related process, the result shows 0 sample here.

Signed-off-by: Yunlong Song <[email protected]>
---
tools/perf/builtin-kvm.c | 2 ++
tools/perf/util/kvm-stat.h | 1 +
2 files changed, 3 insertions(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 643722f..1f9338f 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1047,6 +1047,7 @@ static int read_events(struct perf_kvm_stat *kvm)
struct perf_data_file file = {
.path = kvm->file_name,
.mode = PERF_DATA_MODE_READ,
+ .force = kvm->force,
};

kvm->tool = eops;
@@ -1204,6 +1205,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
" time (sort by avg time)"),
OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid",
"analyze events only for given process id(s)"),
+ OPT_BOOLEAN('f', "force", &kvm->force, "don't complain, do it"),
OPT_END()
};

diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index cf1d7913..ae825d4 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -99,6 +99,7 @@ struct perf_kvm_stat {
int timerfd;
unsigned int display_time;
bool live;
+ bool force;
};

struct kvm_reg_events_ops {
--
1.8.5.2

2015-04-02 13:45:01

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 05/10] perf tools: Support using -f to override perf.data file ownership for lock

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

Example:

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

Before this patch:

# perf lock report
File perf.data not owned by current user or root (use -f to override)
Initializing perf session failed
# perf lock report -f
Error: unknown switch `f'

usage: perf lock report [<options>]

-k, --key <acquired> key for sorting (acquired / contended /
avg_wait / wait_total / wait_max / wait_min)

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

After this patch:

# perf lock report
File perf.data not owned by current user or root (use -f to override)
Initializing perf session failed
# perf lock report -f
Name acquired contended avg wait (ns) total wait (ns) ...

&ldata->output_l... 128 0 0 0 ...
&ctx->lock 114 0 0 0 ...
&p->pi_lock 112 0 0 0 ...
&(&pool->lock)->... 112 0 0 0 ...
&(&dentry->d_loc... 70 0 0 0 ...
&(&newf->file_lo... 62 0 0 0 ...
&(&fs->lock)->rl... 43 0 0 0 ...
...

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

Signed-off-by: Yunlong Song <[email protected]>
---
tools/perf/builtin-lock.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 7893a9b..d49c2ab 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -846,6 +846,8 @@ static const struct perf_evsel_str_handler lock_tracepoints[] = {
{ "lock:lock_release", perf_evsel__process_lock_release, }, /* CONFIG_LOCKDEP */
};

+static bool force;
+
static int __cmd_report(bool display_info)
{
int err = -EINVAL;
@@ -857,6 +859,7 @@ static int __cmd_report(bool display_info)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = force,
};

session = perf_session__new(&file, false, &eops);
@@ -945,6 +948,7 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
"dump thread list in perf.data"),
OPT_BOOLEAN('m', "map", &info_map,
"map of lock instances (address:name table)"),
+ OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
OPT_END()
};
const struct option lock_options[] = {
@@ -956,6 +960,7 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
const struct option report_options[] = {
OPT_STRING('k', "key", &sort_key, "acquired",
"key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
+ OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
/* TODO: type */
OPT_END()
};
--
1.8.5.2

2015-04-02 13:47:01

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 06/10] perf tools: Support using -f to override perf.data file ownership for mem

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

Example:

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

Before this patch:

# perf mem -D report
File perf.data not owned by current user or root (use -f to override)
# perf mem -D -f report
Error: unknown switch `f'

usage: perf mem [<options>] {record|report}

-t, --type <type> memory operations(load,store) Default load,store
-D, --dump-raw-samples
dump raw samples in ASCII
-U, --hide-unresolved
Only display entries resolved to a symbol
-i, --input <file> input file name
-C, --cpu <cpu> list of cpus to profile
-x, --field-separator <separator>
separator for columns, no spaces will be added
between columns '.' is reserved.

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

After this patch:

# perf mem -D report
File perf.data not owned by current user or root (use -f to override)
# perf mem -D -f report
# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL
39095 39095 0xffffffff81127e40 0x016ffff887f45148338 8 0x68100142
/proc/kcore:perf_event_aux
39095 39095 0xffffffff8100a3fe 0xffff89007f8cb7d0 6 0x68100142
/proc/kcore:native_sched_clock
39095 39095 0xffffffff81309139 0xffff88bf44c9ded8 6 0x68100142
/proc/kcore:acpi_map_lookup
39095 39095 0xffffffff810f8c4c 0xffff89007f8ccd88 6 0x68100142
/proc/kcore:rcu_nmi_exit
39095 39095 0xffffffff81136346 0xffff88fea995dd50 6 0x68100142
/proc/kcore:unlock_page
39095 39095 0xffffffff812a64a2 0xffff88fea995dcc8 6 0x68100142
/proc/kcore:half_md4_transform
39095 39095 0x7f0cf877c7e9 0x25dfb94 6 0x68100142
/lib64/libc-2.19.so:__readdir64
39095 39095 0x7f0cf87575a3 0x7f0cf9163731 6 0x68100142
/lib64/libc-2.19.so:__strcoll_l
39095 39095 0xffffffff8116910e 0xffffea01c1bfbd50 23 0x68100242
/proc/kcore:page_remove_rmap

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

Signed-off-by: Yunlong Song <[email protected]>
---
tools/perf/builtin-mem.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index b4dcf0b..675216e 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -15,6 +15,7 @@ struct perf_mem {
char const *input_name;
bool hide_unresolved;
bool dump_raw;
+ bool force;
int operation;
const char *cpu_list;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -120,6 +121,7 @@ static int report_raw_events(struct perf_mem *mem)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = mem->force,
};
int err = -EINVAL;
int ret;
@@ -290,6 +292,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
"separator",
"separator for columns, no spaces will be added"
" between columns '.' is reserved."),
+ OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"),
OPT_END()
};
const char *const mem_subcommands[] = { "record", "report", NULL };
--
1.8.5.2

2015-04-02 13:46:50

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 07/10] perf tools: Support using -f to override perf.data file ownership for script

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 <[email protected]>
---
tools/perf/builtin-script.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 662366c..459ab5b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1523,6 +1523,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
.ordering_requires_timestamps = true,
},
};
+ struct perf_data_file file = {
+ .mode = PERF_DATA_MODE_READ,
+ };
const struct option options[] = {
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
@@ -1550,7 +1553,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"When printing symbols do not display call chain"),
OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
"Look for files with symbols relative to this directory"),
- OPT_CALLBACK('f', "fields", NULL, "str",
+ OPT_CALLBACK('F', "fields", NULL, "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,"
@@ -1574,6 +1577,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"Show the fork/comm/exit events"),
OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events,
"Show the mmap events"),
+ OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
OPT_END()
};
const char * const script_subcommands[] = { "record", "report", NULL };
@@ -1585,9 +1589,6 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"perf script [<options>] <top-script> [script-args]",
NULL
};
- struct perf_data_file file = {
- .mode = PERF_DATA_MODE_READ,
- };

setup_scripting();

--
1.8.5.2

2015-04-02 13:46:14

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 08/10] perf tools: Support using -f to override perf.data file ownership for timechart

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

Example:

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

Before this patch:

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

usage: perf timechart [<options>] {record}

-i, --input <file> input file name
-o, --output <file> output file name
-w, --width <n> page width
--highlight <duration or task name>
highlight tasks. Pass duration in ns or process name.
-P, --power-only output power data only
-T, --tasks-only output processes data only
-p, --process <process>
process selector. Pass a pid or process name.
--symfs <directory>
Look for files with symbols relative to this directory
-n, --proc-num <n> min. number of tasks to print
-t, --topology sort CPUs according to topology
--io-skip-eagain skip EAGAIN errors
--io-min-time <time>
all IO faster than min-time will visually appear longer
--io-merge-dist <time>
merge events that are merge-dist us apart

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

After this patch:

# perf timechart
File perf.data not owned by current user or root (use -f to override)
# perf timechart -f
Written 0.0 seconds of trace to output.svg.
# cat output.svg
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="1000" height="10110" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<style type="text/css">
<![CDATA[
rect { stroke-width: 1; }
...
...

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

Signed-off-by: Yunlong Song <[email protected]>
---
tools/perf/builtin-timechart.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 494b3bb..e50fe11 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -67,6 +67,7 @@ struct timechart {
skip_eagain;
u64 min_time,
merge_dist;
+ bool force;
};

struct per_pidcomm;
@@ -1598,6 +1599,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = tchart->force,
};

struct perf_session *session = perf_session__new(&file, false,
@@ -1956,6 +1958,7 @@ int cmd_timechart(int argc, const char **argv,
OPT_CALLBACK(0, "io-merge-dist", &tchart.merge_dist, "time",
"merge events that are merge-dist us apart",
parse_time),
+ OPT_BOOLEAN('f', "force", &tchart.force, "don't complain, do it"),
OPT_END()
};
const char * const timechart_subcommands[] = { "record", NULL };
--
1.8.5.2

2015-04-02 13:45:04

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 09/10] perf tools: Support using -f to override perf.data file ownership for trace

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

Example:

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

Before this patch:

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

usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]

--event <event> event selector. use 'perf list' to list
available events
--comm show the thread COMM next to its id
--tool_stats show tool stats
-e, --expr <expr> list of events to trace
-o, --output <file> output file name
-i, --input <file> Analyze events in file
-p, --pid <pid> trace events on existing process id
-t, --tid <tid> trace events on existing thread id
--filter-pids <float>
...

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

After this patch:

# perf trace -i perf.data
File perf.data not owned by current user or root (use -f to override)
# perf trace -i perf.data -f
0.056 ( 0.002 ms): ls/47325 brk( ...
0.108 ( 0.018 ms): ls/47325 mmap(len: 4096, prot: READ|WRITE, ...
0.145 ( 0.013 ms): ls/47325 access(filename: 0x7f31259a0eb0, ...
0.172 ( 0.008 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.180 ( 0.004 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.185 ( 0.004 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.189 ( 0.003 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.195 ( 0.004 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.199 ( 0.002 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.205 ( 0.004 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.211 ( 0.004 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.220 ( 0.007 ms): ls/47325 open(filename: 0x7f312599e8ff, ...
...
...

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

Signed-off-by: Yunlong Song <[email protected]>
---
tools/perf/builtin-trace.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index bcc98ce..e124741 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1254,6 +1254,7 @@ struct trace {
bool show_comm;
bool show_tool_stats;
bool trace_syscalls;
+ bool force;
int trace_pgfaults;
};

@@ -2345,6 +2346,7 @@ static int trace__replay(struct trace *trace)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = trace->force,
};
struct perf_session *session;
struct perf_evsel *evsel;
@@ -2693,6 +2695,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min",
"Trace pagefaults", parse_pagefaults, "maj"),
OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"),
+ OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"),
OPT_END()
};
const char * const trace_subcommands[] = { "record", NULL };
--
1.8.5.2

2015-04-02 13:46:59

by Yunlong Song

[permalink] [raw]
Subject: [PATCH 10/10] perf tools: Support using -f to override perf.data file ownership for data 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 <[email protected]>
---
tools/perf/builtin-data.c | 4 +++-
tools/perf/util/data-convert-bt.c | 3 ++-
tools/perf/util/data-convert-bt.h | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 709152a..d6525bc 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -53,12 +53,14 @@ static int cmd_data_convert(int argc, const char **argv,
const char *prefix __maybe_unused)
{
const char *to_ctf = NULL;
+ bool force = false;
const struct option options[] = {
OPT_INCR('v', "verbose", &verbose, "be more verbose"),
OPT_STRING('i', "input", &input_name, "file", "input file name"),
#ifdef HAVE_LIBBABELTRACE_SUPPORT
OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
#endif
+ OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
OPT_END()
};

@@ -76,7 +78,7 @@ static int cmd_data_convert(int argc, const char **argv,

if (to_ctf) {
#ifdef HAVE_LIBBABELTRACE_SUPPORT
- return bt_convert__perf2ctf(input_name, to_ctf);
+ return bt_convert__perf2ctf(input_name, to_ctf, force);
#else
pr_err("The libbabeltrace support is not compiled in.\n");
return -1;
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index c6d6226..dd17c9a 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -791,12 +791,13 @@ err:
return -1;
}

-int bt_convert__perf2ctf(const char *input, const char *path)
+int bt_convert__perf2ctf(const char *input, const char *path, bool force)
{
struct perf_session *session;
struct perf_data_file file = {
.path = input,
.mode = PERF_DATA_MODE_READ,
+ .force = force,
};
struct convert c = {
.tool = {
diff --git a/tools/perf/util/data-convert-bt.h b/tools/perf/util/data-convert-bt.h
index dda30c5..4c20434 100644
--- a/tools/perf/util/data-convert-bt.h
+++ b/tools/perf/util/data-convert-bt.h
@@ -2,7 +2,7 @@
#define __DATA_CONVERT_BT_H
#ifdef HAVE_LIBBABELTRACE_SUPPORT

-int bt_convert__perf2ctf(const char *input_name, const char *to_ctf);
+int bt_convert__perf2ctf(const char *input_name, const char *to_ctf, bool force);

#endif /* HAVE_LIBBABELTRACE_SUPPORT */
#endif /* __DATA_CONVERT_BT_H */
--
1.8.5.2

2015-04-02 15:13:14

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 00/10] perf tools: Support using -f to override file ownership for perf commands

Em Thu, Apr 02, 2015 at 09:47:09PM +0800, Yunlong Song escreveu:
> Hi,
> Enable perf commands to use perf file when it is not owned by current
> user or root.
>
> Yunlong Song (10):
> perf tools: Support using -f to override perf.data file ownership for
> evlist
> perf tools: Support using -f to override perf.data file ownership for
> inject
> perf tools: Support using -f to override perf.data file ownership for
> kmem
> perf tools: Support using -f to override perf.data.guest file
> ownership for kvm
> perf tools: Support using -f to override perf.data file ownership for
> lock
> perf tools: Support using -f to override perf.data file ownership for
> mem
> perf tools: Support using -f to override perf.data file ownership for
> script
> perf tools: Support using -f to override perf.data file ownership for
> timechart
> perf tools: Support using -f to override perf.data file ownership for
> trace
> perf tools: Support using -f to override perf.data file ownership for
> data convert

Thanks, applied.

At some point we need to try to move more of these repeated stuff from
every tool and into some common place that could then be included in
tools, i.e. the commom set of options that all tools offes...

- Arnaldo

Subject: [tip:perf/core] perf evlist: Support using -f to override perf.data file ownership

Commit-ID: 9e3b6ec17374299516d83c2e36135b958a895aa3
Gitweb: http://git.kernel.org/tip/9e3b6ec17374299516d83c2e36135b958a895aa3
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:10 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:45 -0300

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

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

Before this patch:

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

usage: perf evlist [<options>]

-i, --input <file> Input file name
-F, --freq Show the sample frequency
-v, --verbose Show all event attr details
-g, --group Show event group information

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

After this patch:

# perf evlist
File perf.data not owned by current user or root (use -f to override)
# perf evlist -f
cycles

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

Signed-off-by: Yunlong Song <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-evlist.c | 2 ++
tools/perf/util/evsel.h | 1 +
2 files changed, 3 insertions(+)

diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 0f93f85..695ec5a 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -24,6 +24,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
struct perf_data_file file = {
.path = file_name,
.mode = PERF_DATA_MODE_READ,
+ .force = details->force,
};

session = perf_session__new(&file, 0, NULL);
@@ -47,6 +48,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
"Show all event attr details"),
OPT_BOOLEAN('g', "group", &details.event_group,
"Show event group information"),
+ OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
OPT_END()
};
const char * const evlist_usage[] = {
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index dcf202a..c5a43d6 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -335,6 +335,7 @@ struct perf_attr_details {
bool freq;
bool verbose;
bool event_group;
+ bool force;
};

int perf_evsel__fprintf(struct perf_evsel *evsel,

Subject: [tip:perf/core] perf inject: Support using -f to override perf.data file ownership

Commit-ID: ccaa474c8a0983d26ecb3eac755672b546b997c3
Gitweb: http://git.kernel.org/tip/ccaa474c8a0983d26ecb3eac755672b546b997c3
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:11 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:45 -0300

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 <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-inject.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index ea46df25..40a33d7 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -443,6 +443,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
"be more verbose (show build ids, etc)"),
OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file",
"kallsyms pathname"),
+ OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
OPT_END()
};
const char * const inject_usage[] = {

Subject: [tip:perf/core] perf kmem: Support using -f to override perf.data file ownership

Commit-ID: d1eeb77c1811fd178442ccb8f58004a19ec40dd3
Gitweb: http://git.kernel.org/tip/d1eeb77c1811fd178442ccb8f58004a19ec40dd3
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:12 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:46 -0300

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

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

Example:

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

Before this patch:

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

usage: perf kmem [<options>] {record|stat}

-i, --input <file> input file name
-v, --verbose be more verbose (show symbol address, etc)
--caller show per-callsite statistics
--alloc show per-allocation statistics
-s, --sort <key[,key2...]>
sort by keys: ptr, call_site, bytes, hit,
pingpong, frag
-l, --line <num> show n lines
--raw-ip show raw ip instead of symbol

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

After this patch:

# perf kmem stat
File perf.data not owned by current user or root (use -f to override)
# perf kmem stat -f
SUMMARY
=======
Total bytes requested: 437599
Total bytes allocated: 615472
Total bytes wasted on internal fragmentation: 177873
Internal fragmentation: 28.900259%
Cross CPU allocations: 6/1192

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

Signed-off-by: Yunlong Song <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-kmem.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 64d3623..ac303ef 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -662,6 +662,10 @@ static int __cmd_record(int argc, const char **argv)
int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
{
const char * const default_sort_order = "frag,hit,bytes";
+ struct perf_data_file file = {
+ .path = input_name,
+ .mode = PERF_DATA_MODE_READ,
+ };
const struct option kmem_options[] = {
OPT_STRING('i', "input", &input_name, "file", "input file name"),
OPT_INCR('v', "verbose", &verbose,
@@ -675,6 +679,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
parse_sort_opt),
OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt),
OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
+ OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
OPT_END()
};
const char *const kmem_subcommands[] = { "record", "stat", NULL };
@@ -683,10 +688,6 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
NULL
};
struct perf_session *session;
- struct perf_data_file file = {
- .path = input_name,
- .mode = PERF_DATA_MODE_READ,
- };
int ret = -1;

argc = parse_options_subcommand(argc, argv, kmem_options,

Subject: [tip:perf/core] perf kvm: Support using -f to override perf.data.guest file ownership

Commit-ID: 8cc5ec1f754355ed788838390e86389c9ffb7590
Gitweb: http://git.kernel.org/tip/8cc5ec1f754355ed788838390e86389c9ffb7590
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:13 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:47 -0300

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

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

Example:

# perf kvm stat record ls
# chown Yunlong.Song:Yunlong.Song perf.data.guest
# ls -al perf.data.guest
-rw------- 1 Yunlong.Song Yunlong.Song 4128937 Apr 2 11:05 perf.data.guest
# id
uid=0(root) gid=0(root) groups=0(root),64(pkcs11)

Before this patch:

# perf kvm stat report
File perf.data.guest not owned by current user or root (use -f to override)
Initializing perf session failed
# perf kvm stat report -f
Error: unknown switch `f'

usage: perf kvm stat report [<options>]

--event <report event>
event for reporting: vmexit, mmio (x86 only),
ioport (x86 only)
--vcpu <n> vcpu id to report
-k, --key <sort-key> key for sorting: sample(sort by samples
number) time (sort by avg time)
-p, --pid <pid> analyze events only for given process id(s)

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

After this patch:

# perf kvm stat report
File perf.data.guest not owned by current user or root (use -f to override)
Initializing perf session failed
# perf kvm stat report -f
Analyze events for all VMs, all VCPUs:

VM-EXIT Samples Samples% Time% Min Time Max Time Avg time

Total Samples:0, Total events handled time:0.00us.

As shown above, the -f option really works now. Since we have not
launched any KVM related process, the result shows 0 sample here.

Signed-off-by: Yunlong Song <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-kvm.c | 2 ++
tools/perf/util/kvm-stat.h | 1 +
2 files changed, 3 insertions(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 643722f..1f9338f 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1047,6 +1047,7 @@ static int read_events(struct perf_kvm_stat *kvm)
struct perf_data_file file = {
.path = kvm->file_name,
.mode = PERF_DATA_MODE_READ,
+ .force = kvm->force,
};

kvm->tool = eops;
@@ -1204,6 +1205,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
" time (sort by avg time)"),
OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid",
"analyze events only for given process id(s)"),
+ OPT_BOOLEAN('f', "force", &kvm->force, "don't complain, do it"),
OPT_END()
};

diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index cf1d7913..ae825d4 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -99,6 +99,7 @@ struct perf_kvm_stat {
int timerfd;
unsigned int display_time;
bool live;
+ bool force;
};

struct kvm_reg_events_ops {

Subject: [tip:perf/core] perf lock: Support using -f to override perf.data file ownership

Commit-ID: c4ac732a0377d1544a8385393a9877b693ff0652
Gitweb: http://git.kernel.org/tip/c4ac732a0377d1544a8385393a9877b693ff0652
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:14 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:48 -0300

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

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

Example:

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

Before this patch:

# perf lock report
File perf.data not owned by current user or root (use -f to override)
Initializing perf session failed
# perf lock report -f
Error: unknown switch `f'

usage: perf lock report [<options>]

-k, --key <acquired> key for sorting (acquired / contended /
avg_wait / wait_total / wait_max / wait_min)

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

After this patch:

# perf lock report
File perf.data not owned by current user or root (use -f to override)
Initializing perf session failed
# perf lock report -f
Name acquired contended avg wait (ns) total wait (ns) ...

&ldata->output_l... 128 0 0 0 ...
&ctx->lock 114 0 0 0 ...
&p->pi_lock 112 0 0 0 ...
&(&pool->lock)->... 112 0 0 0 ...
&(&dentry->d_loc... 70 0 0 0 ...
&(&newf->file_lo... 62 0 0 0 ...
&(&fs->lock)->rl... 43 0 0 0 ...
...

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

Signed-off-by: Yunlong Song <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-lock.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 7893a9b..d49c2ab 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -846,6 +846,8 @@ static const struct perf_evsel_str_handler lock_tracepoints[] = {
{ "lock:lock_release", perf_evsel__process_lock_release, }, /* CONFIG_LOCKDEP */
};

+static bool force;
+
static int __cmd_report(bool display_info)
{
int err = -EINVAL;
@@ -857,6 +859,7 @@ static int __cmd_report(bool display_info)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = force,
};

session = perf_session__new(&file, false, &eops);
@@ -945,6 +948,7 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
"dump thread list in perf.data"),
OPT_BOOLEAN('m', "map", &info_map,
"map of lock instances (address:name table)"),
+ OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
OPT_END()
};
const struct option lock_options[] = {
@@ -956,6 +960,7 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
const struct option report_options[] = {
OPT_STRING('k', "key", &sort_key, "acquired",
"key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
+ OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
/* TODO: type */
OPT_END()
};

Subject: [tip:perf/core] perf mem: Support using -f to override perf.data file ownership

Commit-ID: 62a1a63a77451dee8fd318a5106ca108d6a8ebcb
Gitweb: http://git.kernel.org/tip/62a1a63a77451dee8fd318a5106ca108d6a8ebcb
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:15 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:49 -0300

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

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

Example:

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

Before this patch:

# perf mem -D report
File perf.data not owned by current user or root (use -f to override)
# perf mem -D -f report
Error: unknown switch `f'

usage: perf mem [<options>] {record|report}

-t, --type <type> memory operations(load,store) Default load,store
-D, --dump-raw-samples
dump raw samples in ASCII
-U, --hide-unresolved
Only display entries resolved to a symbol
-i, --input <file> input file name
-C, --cpu <cpu> list of cpus to profile
-x, --field-separator <separator>
separator for columns, no spaces will be added
between columns '.' is reserved.

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

After this patch:

# perf mem -D report
File perf.data not owned by current user or root (use -f to override)
# perf mem -D -f report
# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL
39095 39095 0xffffffff81127e40 0x016ffff887f45148338 8 0x68100142
/proc/kcore:perf_event_aux
39095 39095 0xffffffff8100a3fe 0xffff89007f8cb7d0 6 0x68100142
/proc/kcore:native_sched_clock
39095 39095 0xffffffff81309139 0xffff88bf44c9ded8 6 0x68100142
/proc/kcore:acpi_map_lookup
39095 39095 0xffffffff810f8c4c 0xffff89007f8ccd88 6 0x68100142
/proc/kcore:rcu_nmi_exit
39095 39095 0xffffffff81136346 0xffff88fea995dd50 6 0x68100142
/proc/kcore:unlock_page
39095 39095 0xffffffff812a64a2 0xffff88fea995dcc8 6 0x68100142
/proc/kcore:half_md4_transform
39095 39095 0x7f0cf877c7e9 0x25dfb94 6 0x68100142
/lib64/libc-2.19.so:__readdir64
39095 39095 0x7f0cf87575a3 0x7f0cf9163731 6 0x68100142
/lib64/libc-2.19.so:__strcoll_l
39095 39095 0xffffffff8116910e 0xffffea01c1bfbd50 23 0x68100242
/proc/kcore:page_remove_rmap

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

Signed-off-by: Yunlong Song <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-mem.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index b4dcf0b..675216e 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -15,6 +15,7 @@ struct perf_mem {
char const *input_name;
bool hide_unresolved;
bool dump_raw;
+ bool force;
int operation;
const char *cpu_list;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -120,6 +121,7 @@ static int report_raw_events(struct perf_mem *mem)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = mem->force,
};
int err = -EINVAL;
int ret;
@@ -290,6 +292,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
"separator",
"separator for columns, no spaces will be added"
" between columns '.' is reserved."),
+ OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"),
OPT_END()
};
const char *const mem_subcommands[] = { "record", "report", NULL };

Subject: [tip:perf/core] perf script: Support using -f to override perf.data file ownership

Commit-ID: 06af0f2c919d7c8f05efebe0d96a6f22297aafd4
Gitweb: http://git.kernel.org/tip/06af0f2c919d7c8f05efebe0d96a6f22297aafd4
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:16 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:50 -0300

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 <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-script.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 257dd06..58f10b8 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1515,6 +1515,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
.ordering_requires_timestamps = true,
},
};
+ struct perf_data_file file = {
+ .mode = PERF_DATA_MODE_READ,
+ };
const struct option options[] = {
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
@@ -1542,7 +1545,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"When printing symbols do not display call chain"),
OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
"Look for files with symbols relative to this directory"),
- OPT_CALLBACK('f', "fields", NULL, "str",
+ OPT_CALLBACK('F', "fields", NULL, "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,"
@@ -1566,6 +1569,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"Show the fork/comm/exit events"),
OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events,
"Show the mmap events"),
+ OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
OPT_END()
};
const char * const script_subcommands[] = { "record", "report", NULL };
@@ -1577,9 +1581,6 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"perf script [<options>] <top-script> [script-args]",
NULL
};
- struct perf_data_file file = {
- .mode = PERF_DATA_MODE_READ,
- };

setup_scripting();

Subject: [tip:perf/core] perf timechart: Support using -f to override perf.data file ownership

Commit-ID: 44f7e432e3dc8a13f5661e8b722f53645df083d1
Gitweb: http://git.kernel.org/tip/44f7e432e3dc8a13f5661e8b722f53645df083d1
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:17 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:50 -0300

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

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

Example:

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

Before this patch:

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

usage: perf timechart [<options>] {record}

-i, --input <file> input file name
-o, --output <file> output file name
-w, --width <n> page width
--highlight <duration or task name>
highlight tasks. Pass duration in ns or process name.
-P, --power-only output power data only
-T, --tasks-only output processes data only
-p, --process <process>
process selector. Pass a pid or process name.
--symfs <directory>
Look for files with symbols relative to this directory
-n, --proc-num <n> min. number of tasks to print
-t, --topology sort CPUs according to topology
--io-skip-eagain skip EAGAIN errors
--io-min-time <time>
all IO faster than min-time will visually appear longer
--io-merge-dist <time>
merge events that are merge-dist us apart

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

After this patch:

# perf timechart
File perf.data not owned by current user or root (use -f to override)
# perf timechart -f
Written 0.0 seconds of trace to output.svg.
# cat output.svg
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="1000" height="10110" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<style type="text/css">
<![CDATA[
rect { stroke-width: 1; }
...
...

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

Signed-off-by: Yunlong Song <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-timechart.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 494b3bb..e50fe11 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -67,6 +67,7 @@ struct timechart {
skip_eagain;
u64 min_time,
merge_dist;
+ bool force;
};

struct per_pidcomm;
@@ -1598,6 +1599,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = tchart->force,
};

struct perf_session *session = perf_session__new(&file, false,
@@ -1956,6 +1958,7 @@ int cmd_timechart(int argc, const char **argv,
OPT_CALLBACK(0, "io-merge-dist", &tchart.merge_dist, "time",
"merge events that are merge-dist us apart",
parse_time),
+ OPT_BOOLEAN('f', "force", &tchart.force, "don't complain, do it"),
OPT_END()
};
const char * const timechart_subcommands[] = { "record", NULL };

Subject: [tip:perf/core] perf trace: Support using -f to override perf.data file ownership

Commit-ID: e366a6d8949f3cfab01906b42c591098d59f3f35
Gitweb: http://git.kernel.org/tip/e366a6d8949f3cfab01906b42c591098d59f3f35
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:18 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:51 -0300

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

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

Example:

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

Before this patch:

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

usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]

--event <event> event selector. use 'perf list' to list
available events
--comm show the thread COMM next to its id
--tool_stats show tool stats
-e, --expr <expr> list of events to trace
-o, --output <file> output file name
-i, --input <file> Analyze events in file
-p, --pid <pid> trace events on existing process id
-t, --tid <tid> trace events on existing thread id
--filter-pids <float>
...

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

After this patch:

# perf trace -i perf.data
File perf.data not owned by current user or root (use -f to override)
# perf trace -i perf.data -f
0.056 ( 0.002 ms): ls/47325 brk( ...
0.108 ( 0.018 ms): ls/47325 mmap(len: 4096, prot: READ|WRITE, ...
0.145 ( 0.013 ms): ls/47325 access(filename: 0x7f31259a0eb0, ...
0.172 ( 0.008 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.180 ( 0.004 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.185 ( 0.004 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.189 ( 0.003 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.195 ( 0.004 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.199 ( 0.002 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.205 ( 0.004 ms): ls/47325 open(filename: 0x7fffeb9a0d00, ...
0.211 ( 0.004 ms): ls/47325 stat(filename: 0x7fffeb9a0d00, ...
0.220 ( 0.007 ms): ls/47325 open(filename: 0x7f312599e8ff, ...
...
...

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

Signed-off-by: Yunlong Song <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-trace.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index bcc98ce..e124741 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1254,6 +1254,7 @@ struct trace {
bool show_comm;
bool show_tool_stats;
bool trace_syscalls;
+ bool force;
int trace_pgfaults;
};

@@ -2345,6 +2346,7 @@ static int trace__replay(struct trace *trace)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+ .force = trace->force,
};
struct perf_session *session;
struct perf_evsel *evsel;
@@ -2693,6 +2695,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min",
"Trace pagefaults", parse_pagefaults, "maj"),
OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"),
+ OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"),
OPT_END()
};
const char * const trace_subcommands[] = { "record", NULL };

Subject: [tip:perf/core] perf data: Support using -f to override perf.data file ownership for 'convert'

Commit-ID: bd05954bfa17f03a7bd4454178ba09786b35e383
Gitweb: http://git.kernel.org/tip/bd05954bfa17f03a7bd4454178ba09786b35e383
Author: Yunlong Song <[email protected]>
AuthorDate: Thu, 2 Apr 2015 21:47:19 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 2 Apr 2015 13:18:52 -0300

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 <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-data.c | 4 +++-
tools/perf/util/data-convert-bt.c | 3 ++-
tools/perf/util/data-convert-bt.h | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 709152a..d6525bc 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -53,12 +53,14 @@ static int cmd_data_convert(int argc, const char **argv,
const char *prefix __maybe_unused)
{
const char *to_ctf = NULL;
+ bool force = false;
const struct option options[] = {
OPT_INCR('v', "verbose", &verbose, "be more verbose"),
OPT_STRING('i', "input", &input_name, "file", "input file name"),
#ifdef HAVE_LIBBABELTRACE_SUPPORT
OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
#endif
+ OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
OPT_END()
};

@@ -76,7 +78,7 @@ static int cmd_data_convert(int argc, const char **argv,

if (to_ctf) {
#ifdef HAVE_LIBBABELTRACE_SUPPORT
- return bt_convert__perf2ctf(input_name, to_ctf);
+ return bt_convert__perf2ctf(input_name, to_ctf, force);
#else
pr_err("The libbabeltrace support is not compiled in.\n");
return -1;
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index c6d6226..dd17c9a 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -791,12 +791,13 @@ err:
return -1;
}

-int bt_convert__perf2ctf(const char *input, const char *path)
+int bt_convert__perf2ctf(const char *input, const char *path, bool force)
{
struct perf_session *session;
struct perf_data_file file = {
.path = input,
.mode = PERF_DATA_MODE_READ,
+ .force = force,
};
struct convert c = {
.tool = {
diff --git a/tools/perf/util/data-convert-bt.h b/tools/perf/util/data-convert-bt.h
index dda30c5..4c20434 100644
--- a/tools/perf/util/data-convert-bt.h
+++ b/tools/perf/util/data-convert-bt.h
@@ -2,7 +2,7 @@
#define __DATA_CONVERT_BT_H
#ifdef HAVE_LIBBABELTRACE_SUPPORT

-int bt_convert__perf2ctf(const char *input_name, const char *to_ctf);
+int bt_convert__perf2ctf(const char *input_name, const char *to_ctf, bool force);

#endif /* HAVE_LIBBABELTRACE_SUPPORT */
#endif /* __DATA_CONVERT_BT_H */