All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>
Subject: [PATCH 2/3] perf trace: Create struct thread for command line workload
Date: Wed, 20 May 2015 11:48:34 +0900	[thread overview]
Message-ID: <1432090115-902-2-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1432090115-902-1-git-send-email-namhyung@kernel.org>

When perf creates a new child to profile, the events are enabled on
exec().  And in this case, it doesn't synthesize any event for the
child since they'll be generated during exec().  But there's an window
between the enabling and the event generation.  This leads to some
early event not having a comm but pid (like ':15328').

Fix it by using perf_evlist__start_workload_ex() to create
corresponding thread at the same time.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-trace.c |  4 +++-
 tools/perf/util/evlist.c   | 14 ++++++++++++++
 tools/perf/util/evlist.h   |  2 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index a05490d06374..e30d0ed1e60f 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2282,7 +2282,9 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
 		perf_evlist__enable(evlist);
 
 	if (forks)
-		perf_evlist__start_workload(evlist);
+		perf_evlist__start_workload_ex(evlist,
+					       perf_evlist__create_workload_thread,
+					       trace->host);
 
 	trace->multiple_threads = evlist->threads->map[0] == -1 ||
 				  evlist->threads->nr > 1 ||
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index bfe455ec673b..f84305915e47 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1516,6 +1516,20 @@ int perf_evlist__start_workload_ex(struct perf_evlist *evlist,
 	return ret;
 }
 
+int perf_evlist__create_workload_thread(struct perf_evlist *evlist, void *arg)
+{
+	struct machine *machine = arg;
+	int pid = evlist->workload.pid;
+	struct thread *thread;
+
+	thread = machine__findnew_thread(machine, pid, pid);
+	if (thread == NULL)
+		return -1;
+
+	thread__set_comm(thread, program_invocation_short_name, 0);
+	return 0;
+}
+
 int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
 			      struct perf_sample *sample)
 {
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 6212f036c134..a02b0f4ba4f9 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -126,6 +126,8 @@ int perf_evlist__start_workload(struct perf_evlist *evlist);
 typedef int (*workload_callback_t)(struct perf_evlist *evlist, void *arg);
 int perf_evlist__start_workload_ex(struct perf_evlist *evlist,
 				   workload_callback_t callback, void *arg);
+/* workload_callbacks */
+int perf_evlist__create_workload_thread(struct perf_evlist *evlist, void *arg);
 
 struct option;
 
-- 
2.4.0


  reply	other threads:[~2015-05-20  2:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20  2:48 [PATCH 1/3] perf tools: Introduce perf_evlist__start_workload_ex() Namhyung Kim
2015-05-20  2:48 ` Namhyung Kim [this message]
2015-05-20  2:48 ` [PATCH 3/3] perf record: Synthesize COMM event for a command line workload Namhyung Kim
2015-05-20  7:08   ` Jiri Olsa

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=1432090115-902-2-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.