Commit 9e3b6ec1 authored by Yunlong Song's avatar Yunlong Song Committed by Arnaldo Carvalho de Melo

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: default avatarYunlong Song <yunlong.song@huawei.com>
Tested-by: default avatarArnaldo 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-2-git-send-email-yunlong.song@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c7273835
...@@ -24,6 +24,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details ...@@ -24,6 +24,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
struct perf_data_file file = { struct perf_data_file file = {
.path = file_name, .path = file_name,
.mode = PERF_DATA_MODE_READ, .mode = PERF_DATA_MODE_READ,
.force = details->force,
}; };
session = perf_session__new(&file, 0, NULL); session = perf_session__new(&file, 0, NULL);
...@@ -47,6 +48,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -47,6 +48,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
"Show all event attr details"), "Show all event attr details"),
OPT_BOOLEAN('g', "group", &details.event_group, OPT_BOOLEAN('g', "group", &details.event_group,
"Show event group information"), "Show event group information"),
OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
OPT_END() OPT_END()
}; };
const char * const evlist_usage[] = { const char * const evlist_usage[] = {
......
...@@ -335,6 +335,7 @@ struct perf_attr_details { ...@@ -335,6 +335,7 @@ struct perf_attr_details {
bool freq; bool freq;
bool verbose; bool verbose;
bool event_group; bool event_group;
bool force;
}; };
int perf_evsel__fprintf(struct perf_evsel *evsel, int perf_evsel__fprintf(struct perf_evsel *evsel,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment