mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@google.com>
To: linux-kernel@vger.kernel.org
Cc: acme@redhat.com, jolsa@redhat.com, peterz@infradead.org,
	mingo@elte.hu, irogers@google.com
Subject: [PATCH v2] perf headers: fix processing of pmu_mappings
Date: Tue,  9 Jun 2020 12:30:50 -0700	[thread overview]
Message-ID: <20200609193050.241972-1-eranian@google.com> (raw)

This patch changes the handling of the env->pmu_mappings string.
It transforms the string from a \0 separated list of value:name pairs
into a space separated list of value:name pairs. This makes it much simpler
to parse looking for a particular value or name.

This version also updates print_pmu_mappings() to handle the new space
separator.

Before: printf(env->pmu_mappings);
14:amd_iommu_1

After: printf(env->pmu_mappings);
14:amd_iommu_1 7:uprobe 5:breakpoint 10:amd_l3 19:amd_iommu_6 8:power 4:cpu 17:amd_iommu_4 15:amd_iommu_2 1:software 6:kprobe 13:amd_iommu_0 9:amd_df 20:amd_iommu_7 18:amd_iommu_5 2:tracepoint 21:msr 12:ibs_op 16:amd_iommu_3 11:ibs_fetch

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/util/header.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 31a7f278036c..3649c0e1740b 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1470,10 +1470,19 @@ static void print_pmu_mappings(struct feat_fd *ff, FILE *fp)
 			goto error;
 
 		str = tmp + 1;
+
+		tmp = strchr(str, ' ');
+		if (tmp)
+			*tmp = '\0';
+
 		fprintf(fp, "%s%s = %" PRIu32, delimiter, str, type);
 
 		delimiter = ", ";
-		str += strlen(str) + 1;
+
+		if (tmp) {
+			*tmp = ' ';
+			str = tmp + 1;
+		}
 		pmu_num--;
 	}
 
@@ -1956,13 +1965,15 @@ static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused)
 static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused)
 {
 	char *name;
-	u32 pmu_num;
+	u32 pmu_num, o_num;
 	u32 type;
 	struct strbuf sb;
 
 	if (do_read_u32(ff, &pmu_num))
 		return -1;
 
+	o_num = pmu_num;
+
 	if (!pmu_num) {
 		pr_debug("pmu mappings not available\n");
 		return 0;
@@ -1980,10 +1991,11 @@ static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused)
 		if (!name)
 			goto error;
 
-		if (strbuf_addf(&sb, "%u:%s", type, name) < 0)
+		/* add proper spacing between entries */
+		if (pmu_num < o_num && strbuf_add(&sb, " ", 1) < 0)
 			goto error;
-		/* include a NULL character at the end */
-		if (strbuf_add(&sb, "", 1) < 0)
+
+		if (strbuf_addf(&sb, "%u:%s", type, name) < 0)
 			goto error;
 
 		if (!strcmp(name, "msr"))
@@ -1992,6 +2004,9 @@ static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused)
 		free(name);
 		pmu_num--;
 	}
+	/* include a NULL character at the end */
+	if (strbuf_add(&sb, "", 1) < 0)
+		goto error;
 	ff->ph->env.pmu_mappings = strbuf_detach(&sb, NULL);
 	return 0;
 
-- 
2.27.0.278.ge193c7cf3a9-goog


                 reply	other threads:[~2020-06-09 19:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200609193050.241972-1-eranian@google.com \
    --to=eranian@google.com \
    --cc=acme@redhat.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --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 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®