linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yunlong Song <yunlong.song@huawei.com>
To: <a.p.zijlstra@chello.nl>, <paulus@samba.org>, <mingo@redhat.com>,
	<acme@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <wangnan0@huawei.com>
Subject: [PATCH 09/10] perf tools: Support using -f to override perf.data file ownership for trace
Date: Thu, 2 Apr 2015 21:47:18 +0800	[thread overview]
Message-ID: <1427982439-27388-10-git-send-email-yunlong.song@huawei.com> (raw)
In-Reply-To: <1427982439-27388-1-git-send-email-yunlong.song@huawei.com>

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 <yunlong.song@huawei.com>
---
 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


  parent reply	other threads:[~2015-04-02 13:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-02 13:47 [PATCH 00/10] perf tools: Support using -f to override file ownership for perf commands Yunlong Song
2015-04-02 13:47 ` [PATCH 01/10] perf tools: Support using -f to override perf.data file ownership for evlist Yunlong Song
2015-04-03  5:08   ` [tip:perf/core] perf evlist: Support using -f to override perf.data file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 02/10] perf tools: Support using -f to override perf.data file ownership for inject Yunlong Song
2015-04-03  5:08   ` [tip:perf/core] perf inject: Support using -f to override perf.data file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 03/10] perf tools: Support using -f to override perf.data file ownership for kmem Yunlong Song
2015-04-03  5:08   ` [tip:perf/core] perf kmem: Support using -f to override perf.data file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 04/10] perf tools: Support using -f to override perf.data.guest file ownership for kvm Yunlong Song
2015-04-03  5:08   ` [tip:perf/core] perf kvm: Support using -f to override perf.data.guest file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 05/10] perf tools: Support using -f to override perf.data file ownership for lock Yunlong Song
2015-04-03  5:09   ` [tip:perf/core] perf lock: Support using -f to override perf.data file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 06/10] perf tools: Support using -f to override perf.data file ownership for mem Yunlong Song
2015-04-03  5:09   ` [tip:perf/core] perf mem: Support using -f to override perf.data file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 07/10] perf tools: Support using -f to override perf.data file ownership for script Yunlong Song
2015-04-03  5:09   ` [tip:perf/core] perf script: Support using -f to override perf.data file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 08/10] perf tools: Support using -f to override perf.data file ownership for timechart Yunlong Song
2015-04-03  5:10   ` [tip:perf/core] perf timechart: Support using -f to override perf.data file ownership tip-bot for Yunlong Song
2015-04-02 13:47 ` Yunlong Song [this message]
2015-04-03  5:10   ` [tip:perf/core] perf trace: " tip-bot for Yunlong Song
2015-04-02 13:47 ` [PATCH 10/10] perf tools: Support using -f to override perf.data file ownership for data convert Yunlong Song
2015-04-03  5:10   ` [tip:perf/core] perf data: Support using -f to override perf.data file ownership for 'convert' tip-bot for Yunlong Song
2015-04-02 15:13 ` [PATCH 00/10] perf tools: Support using -f to override file ownership for perf commands Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427982439-27388-10-git-send-email-yunlong.song@huawei.com \
    --to=yunlong.song@huawei.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).