From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung.kim@lge.com>,
Namhyung Kim <namhyung@kernel.org>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 03/25] perf trace: Add support for tracing workload given by command line
Date: Mon, 8 Oct 2012 19:32:28 -0300 [thread overview]
Message-ID: <1349735570-19339-4-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1349735570-19339-1-git-send-email-acme@infradead.org>
From: Namhyung Kim <namhyung.kim@lge.com>
Now perf trace is able to trace specified workload by forking it like
perf record does. And also finish the tracing if the workload quits or
gets SIGINT.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1349413336-26936-5-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-trace.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index da1183f..4e9320b 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -52,6 +52,13 @@ struct trace {
struct perf_record_opts opts;
};
+static bool done = false;
+
+static void sig_handler(int sig __maybe_unused)
+{
+ done = true;
+}
+
static int trace__read_syscall_info(struct trace *trace, int id)
{
char tp_name[128];
@@ -189,11 +196,12 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
return 0;
}
-static int trace__run(struct trace *trace)
+static int trace__run(struct trace *trace, int argc, const char **argv)
{
struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
struct perf_evsel *evsel;
int err = -1, i, nr_events = 0, before;
+ const bool forks = argc > 0;
if (evlist == NULL) {
printf("Not enough memory to run!\n");
@@ -214,6 +222,17 @@ static int trace__run(struct trace *trace)
perf_evlist__config_attrs(evlist, &trace->opts);
+ signal(SIGCHLD, sig_handler);
+ signal(SIGINT, sig_handler);
+
+ if (forks) {
+ err = perf_evlist__prepare_workload(evlist, &trace->opts, argv);
+ if (err < 0) {
+ printf("Couldn't run the workload!\n");
+ goto out_delete_evlist;
+ }
+ }
+
err = perf_evlist__open(evlist);
if (err < 0) {
printf("Couldn't create the events: %s\n", strerror(errno));
@@ -227,6 +246,10 @@ static int trace__run(struct trace *trace)
}
perf_evlist__enable(evlist);
+
+ if (forks)
+ perf_evlist__start_workload(evlist);
+
again:
before = nr_events;
@@ -272,8 +295,15 @@ again:
}
}
- if (nr_events == before)
+ if (nr_events == before) {
+ if (done)
+ goto out_delete_evlist;
+
poll(evlist->pollfd, evlist->nr_fds, -1);
+ }
+
+ if (done)
+ perf_evlist__disable(evlist);
goto again;
@@ -286,7 +316,8 @@ out:
int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
{
const char * const trace_usage[] = {
- "perf trace [<options>]",
+ "perf trace [<options>] [<command>]",
+ "perf trace [<options>] -- <command> [<options>]",
NULL
};
struct trace trace = {
@@ -326,8 +357,6 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
char bf[BUFSIZ];
argc = parse_options(argc, argv, trace_options, trace_usage, 0);
- if (argc)
- usage_with_options(trace_usage, trace_options);
err = perf_target__validate(&trace.opts.target);
if (err) {
@@ -343,8 +372,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
return err;
}
- if (perf_target__none(&trace.opts.target))
+ if (!argc && perf_target__none(&trace.opts.target))
trace.opts.target.system_wide = true;
- return trace__run(&trace);
+ return trace__run(&trace, argc, argv);
}
--
1.7.9.2.358.g22243
next prev parent reply other threads:[~2012-10-08 22:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-08 22:32 [GIT PULL 00/25] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 01/25] perf trace: Validate target task/user/cpu argument Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 02/25] perf trace: Explicitly enable system-wide mode if no option is given Arnaldo Carvalho de Melo
2012-10-08 22:32 ` Arnaldo Carvalho de Melo [this message]
2012-10-08 22:32 ` [PATCH 04/25] perf diff: Add -b option for perf diff to display paired entries only Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 05/25] perf diff: Add ratio computation way to compare hist entries Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 06/25] perf diff: Add option to sort entries based on diff computation Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 07/25] perf diff: Add weighted diff computation way to compare hist entries Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 08/25] perf diff: Add -p option to display period values for " Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 09/25] perf diff: Add -F option to display formula for computation Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 10/25] perf diff: Include samples without symbol in overall stats Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 11/25] perf diff: Display empty space for non paired samples Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 12/25] perf tools: Have the page size value available for all tools Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 13/25] perf machine: Introduce find_thread method Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 14/25] perf event: No need to create a thread when handling PERF_RECORD_EXIT Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 15/25] perf annotate: Handle PERF_RECORD_EXIT events Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 16/25] perf sched: " Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 17/25] perf machine: Carve up event processing specific from perf_tool Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 18/25] perf tools: Remove duplicated include from trace-event-python.c Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 19/25] perf kvm: Only process events for vcpus of interest Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 20/25] perf kvm: Remove typecast in init_kvm_event_record Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 21/25] perf kvm: Total count is a u64, print as so Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 22/25] perf kvm: Add braces around multi-line statements Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 23/25] perf tools: Add on_exit implementation Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 24/25] perf tools: Update Makefile for Android Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 25/25] Documentation: add documentation on compiling " Arnaldo Carvalho de Melo
2012-10-09 13:34 ` [GIT PULL 00/25] perf/core improvements and fixes Ingo Molnar
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=1349735570-19339-4-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
/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
all inboxes | Powered by JetHome®