Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp814688ybg; Tue, 9 Jun 2020 13:37:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiSkUdaDu1s1uKuMXYpT+0y362ReVFxNrzM1x/silV3WRcBbgAPcpRceQBucDwOz6ILz8y X-Received: by 2002:a50:b2a1:: with SMTP id p30mr29411071edd.199.1591735038025; Tue, 09 Jun 2020 13:37:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591735038; cv=none; d=google.com; s=arc-20160816; b=peyfUIWUnYgdd9PCAr465YIbYVu14nUFqJY6cSmD+mC5J0JlCS7ZIA5L01QuWJW2b0 KbFHpTVmoAn5PI9XUDcK9y7QYmzBtQ4/9Xu9KPrSg1RI46sprKVQcXk+6G/SqYmdZ2TB 0MGkuftfflbEDT3idYuie3oeQqxeQv8TaHodOi1ulvCq+LY93v/vOgUYlW9yLJTc2w5n PkM9vecqBgP3ylbGF8UninZD5J8oFi1pTxeveYwsdJbclnTAUhjYhZXs8CjtIqByVhnn ffTzGOIwcJgM1QAMdNmwZeR1usQmacl74vxmKNsljLRit9quZrstLBnQ3fyBW7D63IAO qM3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=cfTAn0LNYLU00F0dbUPQhyJJ5MG3nR6jD1nNWMRLG4c=; b=nEK+qPoouTWENl+KAxFAsJXaoFdEgshPn3PMTh7PZE2XWpTXoICXfKpLMZB0V5IDuT N4zHaeCvhPGuktW3h/Jzs6wCgwj+dU5Fr7eYax0YGqtVfjjJfih0QveiZJdWSGHtF/n2 cQ8igrLyC1waRIOUjadQCvgSZq4qJE+QnAuW3rzCh+fIrq6Qxnt8x4SENL2eSNn2chVw e0sMKQdIHO4pWm72yiQw4wi3Xd3cTL4jCeqNYZ5HbV9U2hSyqM5Q8QXLCST2P9fMpL6m 8A/dFd2D634I14R17awq5tkdKPK/PbH98Qd0k/4mCcKbvtPJSpanPAywVA60zbuospOK p55g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KOygoqm4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si11677589ejn.590.2020.06.09.13.36.55; Tue, 09 Jun 2020 13:37:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KOygoqm4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389246AbgFITbI (ORCPT + 99 others); Tue, 9 Jun 2020 15:31:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728679AbgFITbH (ORCPT ); Tue, 9 Jun 2020 15:31:07 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A59C05BD1E for ; Tue, 9 Jun 2020 12:31:05 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id v1so17564512qvx.8 for ; Tue, 09 Jun 2020 12:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=cfTAn0LNYLU00F0dbUPQhyJJ5MG3nR6jD1nNWMRLG4c=; b=KOygoqm4n/oeoeWDMxxwFtlwF4dI09KSdKn+f3BkKwbwdL6FEbQmz6Lpk8ApcIb7my ARQ8IidmjNiSXnLDlJIFtDhPHwSVU0GgeE4H4gngouKcPoE8bMByuPt0mEY7seuqez1q ZIfuyJcZvbAC+TNv90ydLFoYMMBb4vdz4SGqxEPEGjp6ucOWqPVI8zoes8VfeSdP9k3v 9BVKGFMMSiBRWyk4pHs5dj/d8jik3gjXJ1MzADzxhQjt08p/+lKE2ayXUVJU5k7xawYj AjB8bI8vdt8AOeyWD/KtRwljwSv3qA9q38b7gJyGWsikR/pO8RdJB0DHHnWiH0rAjn9H r7JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=cfTAn0LNYLU00F0dbUPQhyJJ5MG3nR6jD1nNWMRLG4c=; b=q7Ixdkx24Hu6QomaU8GJCwbuLCR3Bg6tOhN82McrnfNo4K0ojGK0kDOvKcS20bNHbU ZUzJnSbfIP6vmkCuJxFm/QM4xgvuHIOl3o5fCXezUxvyKKwy2AFAtTWz63fkP+o25zu3 JbNbZrUoEDSwQiL/msMZJ1yeac2CU9h8SO8jihqYLUBtOcNYJaGsIhcyuWC4WvTzTxKQ rJSDO+a7I8VvlJ3dgA7ysnDe2pqKm6oLuD7/A+OjXaiEgeUI3hWcMDj++hLyGbSSwEm3 lrswwg0LIFkyF3T5fSlczB4bFdGRjWexi8/V2GJGzWCumxH53fw/Bf0DtQMgPNp0Eo1k pE8g== X-Gm-Message-State: AOAM531osRi55XILK7x+2PDVjOcy70zfOQ2BQyiSW49/BCWhgMLSfMpn QhXvvzG7r4F9yRuS6xut7JjXG66u1BIKHs76siHv4PlKmT4fNuynLT8fAQssToBccjmu941yZGh rY98+Al69xngQ9qnuQleEwBkkSNxtG6uoKe4SOODvRDfLYwo0PDtBnqOKkmZu7NtStiAbg+VR X-Received: by 2002:ad4:48c8:: with SMTP id v8mr5831900qvx.15.1591731064120; Tue, 09 Jun 2020 12:31:04 -0700 (PDT) Date: Tue, 9 Jun 2020 12:30:50 -0700 Message-Id: <20200609193050.241972-1-eranian@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.27.0.278.ge193c7cf3a9-goog Subject: [PATCH v2] perf headers: fix processing of pmu_mappings From: Stephane Eranian To: linux-kernel@vger.kernel.org Cc: acme@redhat.com, jolsa@redhat.com, peterz@infradead.org, mingo@elte.hu, irogers@google.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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