mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Stephane Eranian <eranian@google.com>,
	Jiri Olsa <jolsa@redhat.com>, Ulrich Drepper <drepper@gmail.com>,
	Andi Kleen <andi@firstfloor.org>
Subject: [PATCH 06/12] perf header: Reconstruct group relationship by parsing cmdline
Date: Tue, 24 Jul 2012 18:01:27 +0900	[thread overview]
Message-ID: <1343120493-23059-7-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1343120493-23059-1-git-send-email-namhyung@kernel.org>

In order to support the event group viewer, their group relationship
is needed. Since it's not recorded explicitly anywhere in the perf.data
we should parse saved cmdline and apply the result to the evlist. It is
assumed that parsed entries are in a same order with the originals.

I know it's fragile but hard to find other way to do it in the current
condition. :(

Cc: Stephane Eranian <eranian@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/header.c |  110 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 0efbaa3c5a6b..9d9553fed8a6 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1404,6 +1404,40 @@ static int process_version(struct perf_file_section *section __used,
 	return ph->version ? 0 : -ENOMEM;
 }
 
+/*
+ * Reconstruct group relationship using parsed entries. It's assumed that
+ * the parsed entries are in a same order with the original entries.
+ */
+static void reconstruct_group_relation(struct list_head *parsed_head,
+				       struct list_head *orig_head)
+{
+	struct perf_evsel *pos, *orig;
+	struct perf_evsel *leader = NULL;
+
+	/* Fake first entry to use list_for_each_entry_continue */
+	orig = container_of(orig_head, struct perf_evsel, node);
+
+	list_for_each_entry(pos, parsed_head, node) {
+		list_for_each_entry_continue(orig, orig_head, node) {
+			BUG_ON(pos->attr.type != orig->attr.type);
+			BUG_ON(pos->attr.config != orig->attr.config);
+
+			if (pos->leader == NULL) {
+				orig->leader = NULL;
+				if (pos->group_name)
+					orig->group_name = strdup(pos->group_name);
+				orig->nr_children = pos->nr_children;
+
+				leader = orig;
+			} else {
+				orig->leader = leader;
+				orig->group_idx = pos->group_idx;
+			}
+			break;
+		}
+	}
+}
+
 /* Each argv would be separated by a NULL character */
 static int process_cmdline(struct perf_file_section *section __used,
 			   struct perf_header *ph, int fd, void *data __used)
@@ -1413,6 +1447,11 @@ static int process_cmdline(struct perf_file_section *section __used,
 	u32 nr, i;
 	char *cmdline = NULL;
 	size_t len = 0;
+	LIST_HEAD(head);
+	struct perf_evlist *evlist = NULL;
+	int nr_entries = 0;
+	bool found = false;
+	bool regenerated = false;
 
 	ret = read(fd, &nr, sizeof(nr));
 	if (ret != (ssize_t)sizeof(nr))
@@ -1421,6 +1460,25 @@ static int process_cmdline(struct perf_file_section *section __used,
 	if (ph->needs_swap)
 		nr = bswap_32(nr);
 
+	if (symbol_conf.report_group) {
+		struct perf_session *session;
+
+		session = container_of(ph, struct perf_session, header);
+		evlist = session->evlist;
+
+		/*
+		 * The evlist->entries will be regenerated by parsing cmdline
+		 * to track grouping information. However we cannot use the
+		 * generated entries since they lack sample id information.
+		 *
+		 * Save the original entries to 'head' and reconstruct group
+		 * information using parse entries.
+		 */
+		list_splice_init(&evlist->entries, &head);
+		nr_entries = evlist->nr_entries;
+		evlist->nr_entries = 0;
+	}
+
 	ph->cmdline_argc = nr;
 
 	for (i = 0; i < nr; i++) {
@@ -1428,6 +1486,19 @@ static int process_cmdline(struct perf_file_section *section __used,
 		if (!str)
 			goto error;
 
+		if (symbol_conf.report_group) {
+			if (found) {
+				/* Regenerate evlist */
+				if (!parse_events(evlist, str, 0))
+					regenerated = true;
+			}
+
+			if (!strcmp(str, "-e"))
+				found = true;
+			else
+				found = false;
+		}
+
 		tmp = realloc(cmdline, len + strlen(str) + 1);
 		if (!tmp)
 			goto error;
@@ -1439,10 +1510,49 @@ static int process_cmdline(struct perf_file_section *section __used,
 		len += strlen(str) + 1;
 		free(str);
 	}
+
+	if (symbol_conf.report_group) {
+		struct perf_evsel *pos, *orig;
+
+		if (regenerated) {
+			BUG_ON(evlist->nr_entries != nr_entries);
+
+			reconstruct_group_relation(&evlist->entries, &head);
+
+			/* Parsed entries are not needed anymore */
+			list_for_each_entry_safe(pos, orig, &evlist->entries, node) {
+				list_del_init(&pos->node);
+				perf_evsel__delete(pos);
+			}
+
+			/* Restore the original entries */
+			list_splice(&head, &evlist->entries);
+		} else {
+			/*
+			 * Indirect record command doesn't contain events on
+			 * the cmdline. Restore original entries.
+			 */
+			list_splice(&head, &evlist->entries);
+			evlist->nr_entries = nr_entries;
+		}
+	}
 	ph->cmdline = cmdline;
 	return 0;
 
 error:
+	if (symbol_conf.report_group) {
+		struct perf_evsel *pos, *n;
+
+		/* Delete intermediate entries */
+		list_for_each_entry_safe(pos, n, &evlist->entries, node) {
+			list_del_init(&pos->node);
+			perf_evsel__delete(pos);
+		}
+
+		/* Restore original entries */
+		list_splice(&head, &evlist->entries);
+		evlist->nr_entries = nr_entries;
+	}
 	free(cmdline);
 	free(str);
 	return -1;
-- 
1.7.10.4


  parent reply	other threads:[~2012-07-24  9:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24  9:01 [RFC/PATCHSET 00/12] perf report: Add support to event group viewing (v1) Namhyung Kim
2012-07-24  9:01 ` [PATCH 01/12] perf tools: Add a couple of helper routines to handle groups Namhyung Kim
2012-07-24  9:01 ` [PATCH 02/12] perf hist: Convert to struct he_stat Namhyung Kim
2012-07-24  9:01 ` [PATCH 03/12] perf hist: Collapse group hist_entries to a leader Namhyung Kim
2012-07-24  9:01 ` [PATCH 04/12] perf hist: Maintain total periods of group members in the leader Namhyung Kim
2012-07-24  9:01 ` [PATCH 05/12] perf report: Make another loop for output resorting Namhyung Kim
2012-07-24  9:01 ` Namhyung Kim [this message]
2012-07-25 15:39   ` [PATCH 06/12] perf header: Reconstruct group relationship by parsing cmdline Jiri Olsa
2012-07-25 15:52     ` Namhyung Kim
2012-07-24  9:01 ` [PATCH 07/12] perf ui/hist: Add support to group viewing Namhyung Kim
2012-07-24  9:01 ` [PATCH 08/12] perf ui/browser: " Namhyung Kim
2012-07-24  9:01 ` [PATCH 09/12] perf ui/gtk: " Namhyung Kim
2012-07-24  9:01 ` [PATCH 10/12] perf report: Show leader events only when event group is enabled Namhyung Kim
2012-07-24  9:01 ` [PATCH 11/12] perf report: Show group description " Namhyung Kim
2012-07-24  9:01 ` [PATCH 12/12] perf report: Add --group option Namhyung Kim
2012-07-24  9:13 ` [RFC/PATCHSET 00/12] perf report: Add support to event group viewing (v1) Namhyung Kim
2012-07-24 21:17 ` Andi Kleen

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=1343120493-23059-7-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=andi@firstfloor.org \
    --cc=drepper@gmail.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@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®