All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Jiri Olsa <jolsa@redhat.com>,
	Stephane Eranian <eranian@google.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Namhyung Kim <namhyung.kim@lge.com>
Subject: [PATCH 11/20] perf header: Add HEADER_GROUP_DESC feature
Date: Thu,  4 Oct 2012 21:49:45 +0900	[thread overview]
Message-ID: <1349354994-17853-12-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1349354994-17853-1-git-send-email-namhyung@kernel.org>

From: Namhyung Kim <namhyung.kim@lge.com>

Save group relationship information so that it can be restored when
perf report is running.

Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-record.c |    3 +
 tools/perf/util/header.c    |  152 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h    |    2 +
 3 files changed, 157 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8c029fe2e22c..7940f0dd3db9 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -558,6 +558,9 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
 		goto out_delete_session;
 	}
 
+	if (!evsel_list->nr_groups)
+		perf_header__clear_feat(&session->header, HEADER_GROUP_DESC);
+
 	/*
 	 * perf_session__delete(session) will be called at perf_record__exit()
 	 */
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 7daad237dea5..caceb33d8d1b 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1072,6 +1072,41 @@ static int write_pmu_mappings(int fd, struct perf_header *h __maybe_unused,
 }
 
 /*
+ * File format:
+ *
+ * struct group_descs {
+ *	u32	nr_groups;
+ *	struct group_desc {
+ *		char	name[];
+ *		u32	leader_idx;
+ *		u32	nr_members;
+ *	}[nr_groups];
+ * };
+ */
+static int write_group_desc(int fd, struct perf_header *h __maybe_unused,
+			    struct perf_evlist *evlist)
+{
+	u32 nr_groups = evlist->nr_groups;
+	struct perf_evsel *evsel;
+
+	do_write(fd, &nr_groups, sizeof(nr_groups));
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		if (perf_evsel__is_group_leader(evsel) &&
+		    evsel->nr_members > 0) {
+			const char *name = evsel->group_name ?: "{anon_group}";
+			u32 leader_idx = evsel->idx;
+			u32 nr_members = evsel->nr_members;
+
+			do_write_string(fd, name);
+			do_write(fd, &leader_idx, sizeof(leader_idx));
+			do_write(fd, &nr_members, sizeof(nr_members));
+		}
+	}
+	return 0;
+}
+
+/*
  * default get_cpuid(): nothing gets recorded
  * actual implementation must be in arch/$(ARCH)/util/header.c
  */
@@ -1432,6 +1467,31 @@ error:
 	fprintf(fp, "# pmu mappings: unable to read\n");
 }
 
+static void print_group_desc(struct perf_header *ph, int fd __maybe_unused,
+			     FILE *fp)
+{
+	struct perf_session *session;
+	struct perf_evsel *evsel;
+	u32 nr = 0;
+
+	session = container_of(ph, struct perf_session, header);
+
+	list_for_each_entry(evsel, &session->evlist->entries, node) {
+		if (perf_evsel__is_group_leader(evsel) &&
+		    evsel->nr_members > 0) {
+			fprintf(fp, "# group: %s{%s", evsel->group_name ?: "",
+				perf_evsel__name(evsel));
+
+			nr = evsel->nr_members;
+		} else if (nr) {
+			fprintf(fp, ",%s", perf_evsel__name(evsel));
+
+			if (--nr == 0)
+				fprintf(fp, "}\n");
+		}
+	}
+}
+
 static int __event_process_build_id(struct build_id_event *bev,
 				    char *filename,
 				    struct perf_session *session)
@@ -1946,6 +2006,97 @@ error:
 	return -1;
 }
 
+static int process_group_desc(struct perf_file_section *section __maybe_unused,
+			      struct perf_header *ph, int fd,
+			      void *data __maybe_unused)
+{
+	size_t ret = -1;
+	u32 i, nr, nr_groups;
+	struct perf_session *session;
+	struct perf_evsel *evsel, *leader;
+	struct group_desc {
+		char *name;
+		u32 leader_idx;
+		u32 nr_members;
+	} *desc;
+
+	ret = read(fd, &nr_groups, sizeof(nr_groups));
+	if (ret != sizeof(nr_groups))
+		return -1;
+
+	if (ph->needs_swap)
+		nr_groups = bswap_32(nr_groups);
+
+	ph->env.nr_groups = nr_groups;
+	if (!nr_groups) {
+		pr_debug("group desc not available\n");
+		return 0;
+	}
+
+	desc = calloc(nr_groups, sizeof(*desc));
+	if (!desc)
+		return -1;
+
+	for (i = 0; i < nr_groups; i++) {
+		desc[i].name = do_read_string(fd, ph);
+		if (!desc[i].name)
+			goto out_free;
+
+		ret = read(fd, &desc[i].leader_idx, sizeof(u32));
+		if (ret != sizeof(u32))
+			goto out_free;
+
+		ret = read(fd, &desc[i].nr_members, sizeof(u32));
+		if (ret != sizeof(u32))
+			goto out_free;
+
+		if (ph->needs_swap) {
+			desc[i].leader_idx = bswap_32(desc[i].leader_idx);
+			desc[i].nr_members = bswap_32(desc[i].nr_members);
+		}
+	}
+
+	/*
+	 * Rebuild group relationship based on the group_desc
+	 */
+	session = container_of(ph, struct perf_session, header);
+	session->evlist->nr_groups = nr_groups;
+
+	i = nr = 0;
+	list_for_each_entry(evsel, &session->evlist->entries, node) {
+		if (evsel->idx == (int) desc[i].leader_idx) {
+			evsel->leader = NULL;
+			/* {anon_group} is a dummy name */
+			if (strcmp(desc[i].name, "{anon_group}"))
+				evsel->group_name = desc[i].name;
+			evsel->nr_members = desc[i].nr_members;
+
+			BUG_ON(i >= nr_groups);
+			BUG_ON(nr > 0);
+
+			leader = evsel;
+			nr = evsel->nr_members;
+			i++;
+		} else if (nr) {
+			/* This is a group member */
+			evsel->leader = leader;
+			/* group_idx starts from 0 */
+			evsel->group_idx = leader->nr_members - nr;
+			nr--;
+		}
+	}
+
+	BUG_ON(i != nr_groups);
+	BUG_ON(nr != 0);
+
+out_free:
+	while ((int) --i >= 0)
+		free(desc[i].name);
+	free(desc);
+
+	return ret;
+}
+
 struct feature_ops {
 	int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
 	void (*print)(struct perf_header *h, int fd, FILE *fp);
@@ -1985,6 +2136,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
 	FEAT_OPF(HEADER_NUMA_TOPOLOGY,	numa_topology),
 	FEAT_OPA(HEADER_BRANCH_STACK,	branch_stack),
 	FEAT_OPP(HEADER_PMU_MAPPINGS,	pmu_mappings),
+	FEAT_OPP(HEADER_GROUP_DESC,	group_desc),
 };
 
 struct header_print_data {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 99bdd3abce59..f143aa7153a2 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -29,6 +29,7 @@ enum {
 	HEADER_NUMA_TOPOLOGY,
 	HEADER_BRANCH_STACK,
 	HEADER_PMU_MAPPINGS,
+	HEADER_GROUP_DESC,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
@@ -79,6 +80,7 @@ struct perf_session_env {
 	char			*numa_nodes;
 	int			nr_pmu_mappings;
 	char			*pmu_mappings;
+	int			nr_groups;
 };
 
 struct perf_header {
-- 
1.7.9.2


  parent reply	other threads:[~2012-10-04 12:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-04 12:49 [PATCH 00/20] perf report: Add support for event group view (v3) Namhyung Kim
2012-10-04 12:49 ` [PATCH 01/20] perf hists: Add struct hists pointer to struct hist_entry Namhyung Kim
2012-10-05  9:00   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2012-10-04 12:49 ` [PATCH 02/20] perf diff: Refactor diff displacement possition info Namhyung Kim
2012-10-05  9:01   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2012-10-04 12:49 ` [PATCH 03/20] perf hists: Separate overhead and baseline columns Namhyung Kim
2012-10-05  9:02   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2012-10-04 12:49 ` [PATCH 04/20] perf tools: Removing hists pair argument from output path Namhyung Kim
2012-10-05  9:03   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2012-10-04 12:49 ` [PATCH 05/20] perf tool: Add hpp interface to enable/disable hpp column Namhyung Kim
2012-10-05  9:03   ` [tip:perf/urgent] perf tool: Add hpp interface to enable/ disable " tip-bot for Jiri Olsa
2012-10-04 12:49 ` [PATCH 06/20] perf diff: Removing the total_period argument from output code Namhyung Kim
2012-10-05  9:04   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2012-10-04 12:49 ` [PATCH 07/20] perf hists: Introduce struct he_stat Namhyung Kim
2012-10-05  9:05   ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2012-10-04 12:49 ` [PATCH 08/20] perf hists: Move he->stat.nr_events initialization to a template Namhyung Kim
2012-10-05  9:06   ` [tip:perf/urgent] perf hists: Move he->stat. nr_events " tip-bot for Namhyung Kim
2012-10-04 12:49 ` [PATCH 09/20] perf hists: Add more helpers for hist entry stat Namhyung Kim
2012-10-05  9:07   ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2012-10-04 12:49 ` [PATCH 10/20] perf tools: Keep group information Namhyung Kim
2012-10-04 12:49 ` Namhyung Kim [this message]
2012-10-04 13:03   ` [PATCH UPDATED 11/20] perf header: Add HEADER_GROUP_DESC feature Namhyung Kim
2012-10-04 12:49 ` [PATCH 12/20] perf hists: Collapse group hist_entries to a leader Namhyung Kim
2012-10-04 12:49 ` [PATCH 13/20] perf hists: Maintain total periods of group members in the leader Namhyung Kim
2012-10-04 12:49 ` [PATCH 14/20] perf report: Make another loop for output resorting Namhyung Kim
2012-10-04 12:49 ` [PATCH 15/20] perf ui/hist: Add support for event group view Namhyung Kim
2012-10-04 12:49 ` [PATCH 16/20] perf ui/browser: " Namhyung Kim
2012-10-04 12:49 ` [PATCH 17/20] perf ui/gtk: " Namhyung Kim
2012-10-04 12:49 ` [PATCH 18/20] perf report: Bypass non-leader events when event group is enabled Namhyung Kim
2012-10-04 12:49 ` [PATCH 19/20] perf report: Show group description " Namhyung Kim
2012-10-04 12:49 ` [PATCH 20/20] perf report: Add --group option Namhyung Kim
2012-10-18 10:56 ` [PATCH 00/20] perf report: Add support for event group view (v3) 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=1349354994-17853-12-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@ghostprotocols.net \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=peterz@infradead.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.