From nobody Sat Jul 25 18:53:28 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FCD3412C15 for ; Tue, 14 Jul 2026 17:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784050869; cv=none; b=I5/tVIRo0SStc0TwfZybgsLH9wK1929qHXNyLQBQ2FXCHCwputC9Eb0+xLjM782Mx5Mtak2LlZyCjeJyjufY0CS0CaB7hS+TCJw52Un9F2AsTw3G7rZS0fQeKyP7oU1qsAjHlkHULTrrg4O+maA/madK5kDdmrukqs2VDz4j+Cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784050869; c=relaxed/simple; bh=qmrtKiGF0ZVk8eUpawKEpUhSUqva96lDh69er5MYvQA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=GXgA9ZzhrXQ8ozACyAtYb5I3AsZdBhrri6p+q6aPfz2bTyXScKNChmRCiSeNRiCiVzxQpNCtIoEpUpMRnX0gtMt1Usjbb6dECLVqWQFRQbN+80crTljO3zli4Ju9DARgiB4vUDN63t395zflSSQXXRVGtIgfliKNo8Xlv2Ft39c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dLJHi+r2; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dLJHi+r2" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8488ac68185so7103410b3a.2 for ; Tue, 14 Jul 2026 10:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784050866; x=1784655666; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=7rvBy7DlOMve5rkrpKhLf6NBngXNk1okw769cOawHiY=; b=dLJHi+r2dIhITXBh04Dj02nx0NXK7wO7afgzRrdLFBpkJOCpwgkaU95N5WHoTp3UJu C7OxbOSDFQxVGpSNVVzaX874lZwlfBGUCJ8aRqMReW+kO5t+DljEBdogeKA6FfltSzzb QcaLoQixTV5mKm9a+16pMPpAwzydgu6s34VMrtI/5MS+umQQoACFVtlCmKSRHPCVs0Ej EFvFE6tLtMW2kmoCfQbft+B3Ow44yd1AyOnPXoDBvRWPxI1Dq37SXrbQOkg5tjiHKhws aQJHVBXtynhUEdZQX6tBeAEinN7Jetv5U8yMe9lyRHzXImgRHtlOwvVzyl6r4MD70P6s x3CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784050866; x=1784655666; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7rvBy7DlOMve5rkrpKhLf6NBngXNk1okw769cOawHiY=; b=DQ7O5K78bZGY4Ps9Cdqix4dtGOR0tU/GrTljEk2LeZDNagDzwsy4T4eoPNuXOwfE+q CuXFSjzrwmx5xvrbNGkjpZH0ZI+YhIITdneuwCAcnSuFEn5TvUT03g783O2S3B1DHVK1 Mouq0vIvYDUj42KMfQc2GOZzv6QDe8ZN1Ef/9W8+IDUa9MN1aIUdfMXhuHnY1DwhRQW/ qjOCLXJ2y1j04PTAYyrR/aMFcn3wgjNsrIdQXf8ZJXs2HnQpDmIIWs7GHRlqQiVz07je JoPQ4pmJtkZStIXfyWl0MXsH7w2ZdFQOQJL7qFLUFzmowcfTTkV74d1OIPSMV6sY1SvT Cr6A== X-Forwarded-Encrypted: i=1; AHgh+Rpk0vcPbxvMfe+o1e8m7EpWnnLt+Xg9JIX4M5+VAMqnrEWnZR/mrSMY7E/Qk/rGTJZpbfcf7yxw1MuJ2jc=@vger.kernel.org X-Gm-Message-State: AOJu0YzUTvA3XY6W0eEeG/Y1xVm/zw/8VPWKL3zEYYYOG++F249TrmaI fZxZcJWn/qZi+qKn1KNAy76bDUooiztdnEyKmAzetj8y7JBOWFfhkFoZCTlaEHPoZw4Z23SZwmg QbkT/nA== X-Received: from pfblh15.prod.google.com ([2002:a05:6a00:710f:b0:845:eada:32d2]) (user=ctshao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3cd4:b0:847:8b1d:230d with SMTP id d2e1a72fcca58-84889611e43mr14054895b3a.3.1784050865536; Tue, 14 Jul 2026 10:41:05 -0700 (PDT) Date: Tue, 14 Jul 2026 10:40:52 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog Message-ID: <20260714174052.1826692-1-ctshao@google.com> Subject: [PATCH] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output From: Chun-Tse Shao To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org Cc: alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, afaerber@suse.de, mani@kernel.org, dapeng1.mi@linux.intel.com, thomas.falcon@intel.com, irogers@google.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Chun-Tse Shao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When running `perf stat` with `-A` (--no-aggr) and `--metric-only` in JSON output mode (`-j`), `perf stat` evaluates metric expressions across all matching PMUs (including uncore PMUs like `uncore_iio_0`, `uncore_iio_1`, etc.). However, `perf stat` previously formatted JSON output by printing only "cpu" : "" and grouping all metric values on a single line per CPU without identifying which PMU instance evaluated each metric. As a result, when an uncore event spans multiple PMU boxes, `perf stat` printed repeated, ambiguous metric keys without PMU names. Fix this by: 1. Including "pmu" : "" in print_aggr_id_json when evsel->pmu is a non-core or hybrid PMU in AGGR_NONE mode (-A). 2. Starting a new JSON metric line in AGGR_NONE mode (-A) whenever the underlying PMU instance changes across PMU events. 3. Updating perf_json_output_lint.py to recognize the new "pmu" key in the JSON test suite. Example output: $ perf stat -M iio_bandwidth_read -a -A --metric-only -j -I 1000 {"interval" : 1.000314908, "cpu" : "0", "pmu" : "uncore_iio_0", "MB/s ii= o_bandwidth_read" : "0.0"} {"interval" : 1.000314908, "cpu" : "0", "pmu" : "uncore_iio_1", "MB/s ii= o_bandwidth_read" : "0.1"} {"interval" : 1.000314908, "cpu" : "0", "pmu" : "uncore_iio_11", "MB/s i= io_bandwidth_read" : "0.0"} ... {"interval" : 1.000314908, "cpu" : "56", "pmu" : "uncore_iio_0", "MB/s i= io_bandwidth_read" : "0.0"} {"interval" : 1.000314908, "cpu" : "56", "pmu" : "uncore_iio_1", "MB/s i= io_bandwidth_read" : "0.0"} {"interval" : 1.000314908, "cpu" : "56", "pmu" : "uncore_iio_11", "MB/s = iio_bandwidth_read" : "0.0"} Signed-off-by: Chun-Tse Shao Assisted-by: Gemini:gemini-3.1-pro-preview --- .../tests/shell/lib/perf_json_output_lint.py | 1 + tools/perf/util/stat-display.c | 41 +++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/tools/perf/tests/shell/lib/perf_json_output_lint.py b/tools/pe= rf/tests/shell/lib/perf_json_output_lint.py index dafbde56cc76..36767905fcdb 100644 --- a/tools/perf/tests/shell/lib/perf_json_output_lint.py +++ b/tools/perf/tests/shell/lib/perf_json_output_lint.py @@ -64,6 +64,7 @@ def check_json_output(expected_items): 'metric-threshold': lambda x: x in ['unknown', 'good', 'less good', = 'nearly bad', 'bad'], 'metricgroup': lambda x: True, 'node': lambda x: True, + 'pmu': lambda x: True, 'pcnt-running': lambda x: isfloat(x), 'socket': lambda x: True, 'thread': lambda x: True, diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f94f1324d24a..d7f1feb63878 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -397,6 +397,8 @@ static void print_aggr_id_json(struct perf_stat_config = *config, struct outstate json_out(os, "\"cpu\" : \"%d\"", id.cpu.cpu); } + if (evsel && evsel->pmu && (!evsel->pmu->is_core || evsel__is_hybrid(evs= el))) + json_out(os, "\"pmu\" : \"%s\"", evsel->pmu->name); break; case AGGR_THREAD: json_out(os, "\"thread\" : \"%s-%d\"", @@ -1009,11 +1011,12 @@ static void print_counter_aggrdata(struct perf_stat= _config *config, =20 static void print_metric_begin(struct perf_stat_config *config, struct evlist *evlist, - struct outstate *os, int aggr_idx) + struct outstate *os, int aggr_idx, + struct evsel *counter) { struct perf_stat_aggr *aggr; struct aggr_cpu_id id; - struct evsel *evsel; + struct evsel *evsel =3D counter ?: evlist__first(evlist); =20 os->first =3D true; if (!config->metric_only) @@ -1028,7 +1031,6 @@ static void print_metric_begin(struct perf_stat_confi= g *config, else fprintf(config->output, "%s", os->timestamp); } - evsel =3D evlist__first(evlist); id =3D config->aggr_map->map[aggr_idx]; aggr =3D &evsel->stats->aggr[aggr_idx]; aggr_printout(config, os, evsel, id, aggr->nr); @@ -1066,7 +1068,7 @@ static void print_aggr(struct perf_stat_config *confi= g, * Without each counter has its own line. */ cpu_aggr_map__for_each_idx(aggr_idx, config->aggr_map) { - print_metric_begin(config, evlist, os, aggr_idx); + print_metric_begin(config, evlist, os, aggr_idx, NULL); =20 evlist__for_each_entry(evlist, counter) { print_counter_aggrdata(config, counter, aggr_idx, os); @@ -1092,7 +1094,7 @@ static void print_aggr_cgroup(struct perf_stat_config= *config, os->cgrp =3D evsel->cgrp; =20 cpu_aggr_map__for_each_idx(aggr_idx, config->aggr_map) { - print_metric_begin(config, evlist, os, aggr_idx); + print_metric_begin(config, evlist, os, aggr_idx, NULL); =20 evlist__for_each_entry(evlist, counter) { if (counter->cgrp !=3D os->cgrp) @@ -1128,7 +1130,8 @@ static void print_no_aggr_metric(struct perf_stat_con= fig *config, =20 perf_cpu_map__for_each_cpu(cpu, all_idx, evlist__core(evlist)->user_reque= sted_cpus) { struct evsel *counter; - bool first =3D true; + struct perf_pmu *last_pmu =3D NULL; + bool line_open =3D false; =20 evlist__for_each_entry(evlist, counter) { u64 ena, run, val; @@ -1146,10 +1149,24 @@ static void print_no_aggr_metric(struct perf_stat_c= onfig *config, =20 os->evsel =3D counter; os->id =3D aggr_cpu_id__cpu(cpu, /*data=3D*/NULL); - if (first) { - print_metric_begin(config, evlist, os, aggr_idx); - first =3D false; + + if (config->metric_only) { + struct perf_pmu *pmu =3D counter->pmu; + + if (!evsel__is_tool(counter)) { + if (config->json_output && line_open && pmu !=3D last_pmu) { + print_metric_end(config, os); + line_open =3D false; + } + if (!line_open) { + print_metric_begin(config, evlist, os, + aggr_idx, counter); + line_open =3D true; + last_pmu =3D pmu; + } + } } + val =3D ps->aggr[aggr_idx].counts.val; ena =3D ps->aggr[aggr_idx].counts.ena; run =3D ps->aggr[aggr_idx].counts.run; @@ -1157,7 +1174,7 @@ static void print_no_aggr_metric(struct perf_stat_con= fig *config, uval =3D val * counter->scale; printout(config, os, uval, run, ena, 1.0, aggr_idx); } - if (!first) + if (line_open) print_metric_end(config, os); } } @@ -1520,7 +1537,7 @@ static void print_cgroup_counter(struct perf_stat_con= fig *config, struct evlist print_metric_end(config, os); =20 os->cgrp =3D counter->cgrp; - print_metric_begin(config, evlist, os, /*aggr_idx=3D*/0); + print_metric_begin(config, evlist, os, /*aggr_idx=3D*/0, NULL); } =20 print_counter(config, counter, os); @@ -1570,7 +1587,7 @@ void evlist__print_counters(struct evlist *evlist, st= ruct perf_stat_config *conf } else if (config->cgroup_list) { print_cgroup_counter(config, evlist, &os); } else { - print_metric_begin(config, evlist, &os, /*aggr_idx=3D*/0); + print_metric_begin(config, evlist, &os, /*aggr_idx=3D*/0, NULL); evlist__for_each_entry(evlist, counter) { print_counter(config, counter, &os); } --=20 2.55.0.141.g00534a21ce-goog