提交 bd05954b 编写于 作者: Y Yunlong Song 提交者: Arnaldo Carvalho de Melo

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: NYunlong 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.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 e366a6d8
...@@ -53,12 +53,14 @@ static int cmd_data_convert(int argc, const char **argv, ...@@ -53,12 +53,14 @@ static int cmd_data_convert(int argc, const char **argv,
const char *prefix __maybe_unused) const char *prefix __maybe_unused)
{ {
const char *to_ctf = NULL; const char *to_ctf = NULL;
bool force = false;
const struct option options[] = { const struct option options[] = {
OPT_INCR('v', "verbose", &verbose, "be more verbose"), OPT_INCR('v', "verbose", &verbose, "be more verbose"),
OPT_STRING('i', "input", &input_name, "file", "input file name"), OPT_STRING('i', "input", &input_name, "file", "input file name"),
#ifdef HAVE_LIBBABELTRACE_SUPPORT #ifdef HAVE_LIBBABELTRACE_SUPPORT
OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"), OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
#endif #endif
OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
OPT_END() OPT_END()
}; };
...@@ -76,7 +78,7 @@ static int cmd_data_convert(int argc, const char **argv, ...@@ -76,7 +78,7 @@ static int cmd_data_convert(int argc, const char **argv,
if (to_ctf) { if (to_ctf) {
#ifdef HAVE_LIBBABELTRACE_SUPPORT #ifdef HAVE_LIBBABELTRACE_SUPPORT
return bt_convert__perf2ctf(input_name, to_ctf); return bt_convert__perf2ctf(input_name, to_ctf, force);
#else #else
pr_err("The libbabeltrace support is not compiled in.\n"); pr_err("The libbabeltrace support is not compiled in.\n");
return -1; return -1;
......
...@@ -791,12 +791,13 @@ static int ctf_writer__init(struct ctf_writer *cw, const char *path) ...@@ -791,12 +791,13 @@ static int ctf_writer__init(struct ctf_writer *cw, const char *path)
return -1; 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_session *session;
struct perf_data_file file = { struct perf_data_file file = {
.path = input, .path = input,
.mode = PERF_DATA_MODE_READ, .mode = PERF_DATA_MODE_READ,
.force = force,
}; };
struct convert c = { struct convert c = {
.tool = { .tool = {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define __DATA_CONVERT_BT_H #define __DATA_CONVERT_BT_H
#ifdef HAVE_LIBBABELTRACE_SUPPORT #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 /* HAVE_LIBBABELTRACE_SUPPORT */
#endif /* __DATA_CONVERT_BT_H */ #endif /* __DATA_CONVERT_BT_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册