From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 B1CE3272E7C for ; Wed, 23 Jul 2025 23:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312962; cv=none; b=beI4A6Aegpeu5bTDnvvUEM/AqQf1i8SehkdxyAE9enc9zDAV2R3o0Ap1epotwbrvyLh5NReYp02NN+KS1qGLOfcrcGS9n8ks9pXvgAWd6gVvT1p3+Gr59CnDNJZGR807Aobk8tplv7gX70PxaHYsPETo4LKYzPDe64Ju5EBf+Go= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312962; c=relaxed/simple; bh=3Usi47lyrFc7iDjBhSmmHShAGxmn1mYkiehUSL8mUbs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KJofh2rQwqhtLjEzZIxpi6lLdrT+YpvRSgX/KddODB2DJQts5AAw3cfaG/rSGzQ1sxSDnsLTgQ6X/H0BIfBBU8v9qmmWt3ruBjlvP9yLENxhjt1+c94VJ3mbPcMmQwF6iTI3t0FE5OQAldS0aZb1qbAiAZu/edDrnvYrQK0zQ8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B//FDOYp; arc=none smtp.client-ip=209.85.215.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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B//FDOYp" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b31bc3128fcso649436a12.0 for ; Wed, 23 Jul 2025 16:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312960; x=1753917760; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1sWxfNe34Mj6t3LasBAGDQyCtGclSZeWUJ5gZiRJafk=; b=B//FDOYpCkT9Dk2t67Fa6vWCBCqPfOEnw7TTebnLzl4d83ITVwcrCMBrnzpHlPaKQk D5eOepm6xE+0Yy9tNhl9+lI7u4sePzRArXDVOW3BrbsLiv02obZz0omVZ7mvhN1YSu11 30857hjvRDM/5fTNjz1SkNDALtaf0caY7SthyhU5Yrrorex+M9Oh4ndv+ymAxHYTB8F1 BFe+QJ6FW7wMiAN3O5S6bje5kPlrd/Q+aqsPXtQRhsfJUED02/ND+uHC5NqwLrI5xE7E MPVNvABn6V+fTvwwbvAoMMrSnchZFBcVOdqet1XXOg6LZCQniMYiSH2OMjQaEtae3YKY xkwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312960; x=1753917760; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1sWxfNe34Mj6t3LasBAGDQyCtGclSZeWUJ5gZiRJafk=; b=KgUpmKGHWSlnC2gCu+87DejQNBbRysJocK3lIpknYQBSUw59uYhN4lfFYFLCPUobXP XKq2vq7juoV+nC+ZBG+asLvJQ8kXhesM9bF6xf+50kGC9fIUuOzyjfpD/AO8gUnRdVAv sSD9FrqOQmHEpXsW2SPcHSxHq2sEb6W6fxHJppyEvGXGjluxQfvcPmjSnYu+DFCOgc6h yMbzdIxQttBJJv380MekpEukEkk1X3w8KbAfL30UTmopKEQlApvaY1jPJmZBsTf9PqkD g9qPwxJxRDly2orxXuw+rq6hK2RKHRZntuuIwUR/4xYjvbGaDFTmCxJlWOPNYE6dx/9h SHaQ== X-Forwarded-Encrypted: i=1; AJvYcCUxVvzoS2WLHIyebNZJlCTIYEpF4ekqLLxHiLJov/JEuanJ2fMg8VbVTjqaDO9PcIHgGiNgUo+KoAjmQ7k=@vger.kernel.org X-Gm-Message-State: AOJu0YyQsnQjLIk0Hf3PsAhMqDpsCNx8Thkcjd7c8JboMQhu5WWbPWgJ vHYDWebeFnBpdXuPK6ktyVsj6oZvivawMYsk6hnO3tH7RovFm2C86FfEUzcseqQaUY75b4X7Zz9 YEIhAZW4khg== X-Google-Smtp-Source: AGHT+IFWa0zKJu+AEViGjzLR3s2/1byxoKTTG4pnA24NhEV84SVs/Viqot4b6OxDZoOhF3OhrOpnC1ftLj5u X-Received: from pgl12.prod.google.com ([2002:a63:b0c:0:b0:b2e:c3f7:2536]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:e92:b0:21f:5324:340 with SMTP id adf61e73a8af0-23d491f56femr7200323637.41.1753312960046; Wed, 23 Jul 2025 16:22:40 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:02 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-2-irogers@google.com> Subject: [PATCH v8 01/16] perf python: Add more exceptions on error paths From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Returning NULL will cause the python interpreter to fail but not report an error. If none wants to be returned then Py_None needs returning. Set the error for the cases returning NULL so that more meaningful interpreter behavior is had. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 2f28f71325a8..3affde0ad15a 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -475,13 +475,19 @@ static PyObject *pyrf_event__new(const union perf_eve= nt *event) if ((event->header.type < PERF_RECORD_MMAP || event->header.type > PERF_RECORD_SAMPLE) && !(event->header.type =3D=3D PERF_RECORD_SWITCH || - event->header.type =3D=3D PERF_RECORD_SWITCH_CPU_WIDE)) + event->header.type =3D=3D PERF_RECORD_SWITCH_CPU_WIDE)) { + PyErr_Format(PyExc_TypeError, "Unexpected header type %u", + event->header.type); return NULL; + } =20 // FIXME this better be dynamic or we need to parse everything // before calling perf_mmap__consume(), including tracepoint fields. - if (sizeof(pevent->event) < event->header.size) + if (sizeof(pevent->event) < event->header.size) { + PyErr_Format(PyExc_TypeError, "Unexpected event size: %zd < %u", + sizeof(pevent->event), event->header.size); return NULL; + } =20 ptype =3D pyrf_event__type[event->header.type]; pevent =3D PyObject_New(struct pyrf_event, ptype); @@ -1199,8 +1205,10 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyr= f_evlist *pevlist, return NULL; =20 md =3D get_md(evlist, cpu); - if (!md) + if (!md) { + PyErr_Format(PyExc_TypeError, "Unknown CPU '%d'", cpu); return NULL; + } =20 if (perf_mmap__read_init(&md->core) < 0) goto end; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 9C8C4271442 for ; Wed, 23 Jul 2025 23:22:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312971; cv=none; b=Hlh/kdpXJUFZ31qAJRjKKcnw1TwwjXFcsUzWxWGtfo7co+E2oJy7huvIcTULDQ4d16sL1NoUgkctZ2wFuygq1cYbrQ80YXOwJOjmXUbLTEJN3RMu/qWx6RYyDOmlOLSRSxYmh+0T7qMIdYJcl04YLmnAJspWBhVpZWFc7z3Xces= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312971; c=relaxed/simple; bh=ER+ROh0awh637RS9uiVnOuDSibdn3+5EdcbFQUBw10M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mc4KLaZAmE7m+mnraFsNQ29YQmTZvvXNo+p9AU/OWh3P5OPgo2ZQZotEyRaJcnixfk4gvxiD9qeWJHMUXuu64jvq2LzAzwU3S+/9i8cvdiT5yumvEw/RY6QAXJeqDZXoFB/ZQErDeq78jga2l6whaFYeZkYrXYhfwY9eSMw7IVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q0VDVOtO; arc=none smtp.client-ip=209.85.216.73 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q0VDVOtO" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-315af0857f2so304384a91.0 for ; Wed, 23 Jul 2025 16:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312967; x=1753917767; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PQ94nl6w6thBxbPBl4PbvDw+dEht0fnCn5uTJzzLUFs=; b=q0VDVOtODTQeAgJkT9kdorusDe1p8eJ4vg36pXH/yvBghkLKWpmCPV+lQaC0i5w5OX qHF/C9fFL+xobBQ3IzcnWz8u5cnk9anrY5vY+HgVtm/CSzKICuL3DGilSTdAS3BepESk Vdf2tGje+iC+jkufaw8mE7OOseG4MV1G6r+iIx0XDsGMg7Br9hrkzJFr2B/RGRogMFgd IO+dmn3LYabfPCnZ9pGi9bMMOf3XHi7cRvMvS8yl9McnIAEQJrWTM2SbFdek+fGdItu2 7m7IEeKl3dP6txz9hj+fNL9YY+MxS0TlUvU/fqwUhsCueIU7tO0paOf+JkRlirdn1gro 6oLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312967; x=1753917767; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PQ94nl6w6thBxbPBl4PbvDw+dEht0fnCn5uTJzzLUFs=; b=KQ7SzY5NgVme+0dR+zvkgvCggtzg14I4bQc/o1uyptYcFtAxXSwaPaJ1nwDwpijIv0 65SKzRpD/RnbnkqQpA+eUupWxpN0Gf1DbLViRoEx/KxrRoZjCkun2+Fh808QAJE3YScn ltFDga/mygk7MpR1A6doyFwGW52HU3kizAvvsW8ZwYT4HDCxasKlwAeX55wrMSt+aHwE t+RVXaANIgTqeuQTHFVFfho/fipYe7ubxO3nMqV87sOmhKu1Z5hITxgGTg1/SGm/qnCV CJMIBS2wD/9tZ+8eVozaNJ9haEsUrVJSGw5qQru81XhPugxxDb3It/rkyJ8en38DL0MR 7POg== X-Forwarded-Encrypted: i=1; AJvYcCWQBoeszruI/DINyFGIxqb9fK/AWYjQyTobgdsl8tf+77ApJpwmFnmC//fWoXRfAa7LkqP8IDqDxvELpIA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7EcbSeyvCsbNu5fkl90DxClHhiiiO5jb9XieLGH5WT6fQeiLx Sw75x8AkvtHtpkzNLyf6DUliHIc0svYbYKkDeHLB/EOBxRdWW+ZZ0Pbdd+fNoIIFtFT2pD/luKG 5mN7OG3cX1g== X-Google-Smtp-Source: AGHT+IEktQRboa9PIGB+pwpq35lIZkLgRAJKBuMh6+ahcu2oBJePC2n+o+EHIRv+Zrf2qVR1/BPB/F7vDamF X-Received: from pjbsu16.prod.google.com ([2002:a17:90b:5350:b0:301:1bf5:2f07]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1fc3:b0:31c:3872:9411 with SMTP id 98e67ed59e1d1-31e50859d8bmr7793100a91.33.1753312966867; Wed, 23 Jul 2025 16:22:46 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:03 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-3-irogers@google.com> Subject: [PATCH v8 02/16] perf jevents: Add common software event json From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add json for software events so that in perf list the events can have a description. Common json exists for the tool PMU but it has no sysfs equivalent. Modify the map_for_pmu code to return the common map (rather than an architecture specific one) when a PMU with a common name is being looked for, this allows the events to be found. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- .../arch/common/common/software.json | 92 ++++++ tools/perf/pmu-events/empty-pmu-events.c | 266 +++++++++++------- tools/perf/pmu-events/jevents.py | 15 +- 3 files changed, 264 insertions(+), 109 deletions(-) create mode 100644 tools/perf/pmu-events/arch/common/common/software.json diff --git a/tools/perf/pmu-events/arch/common/common/software.json b/tools= /perf/pmu-events/arch/common/common/software.json new file mode 100644 index 000000000000..f2551f1107fd --- /dev/null +++ b/tools/perf/pmu-events/arch/common/common/software.json @@ -0,0 +1,92 @@ +[ + { + "Unit": "software", + "EventName": "cpu-clock", + "BriefDescription": "Per-CPU high-resolution timer based event", + "ConfigCode": "0" + }, + { + "Unit": "software", + "EventName": "task-clock", + "BriefDescription": "Per-task high-resolution timer based event", + "ConfigCode": "1" + }, + { + "Unit": "software", + "EventName": "faults", + "BriefDescription": "Number of page faults [This event is an alias of = page-faults]", + "ConfigCode": "2" + }, + { + "Unit": "software", + "EventName": "page-faults", + "BriefDescription": "Number of page faults [This event is an alias of = faults]", + "ConfigCode": "2" + }, + { + "Unit": "software", + "EventName": "context-switches", + "BriefDescription": "Number of context switches [This event is an alia= s of cs]", + "ConfigCode": "3" + }, + { + "Unit": "software", + "EventName": "cs", + "BriefDescription": "Number of context switches [This event is an alia= s of context-switches]", + "ConfigCode": "3" + }, + { + "Unit": "software", + "EventName": "cpu-migrations", + "BriefDescription": "Number of times a process has migrated to a new C= PU [This event is an alias of migrations]", + "ConfigCode": "4" + }, + { + "Unit": "software", + "EventName": "migrations", + "BriefDescription": "Number of times a process has migrated to a new C= PU [This event is an alias of cpu-migrations]", + "ConfigCode": "4" + }, + { + "Unit": "software", + "EventName": "minor-faults", + "BriefDescription": "Number of minor page faults. Minor faults don't r= equire I/O to handle", + "ConfigCode": "5" + }, + { + "Unit": "software", + "EventName": "major-faults", + "BriefDescription": "Number of major page faults. Major faults require= I/O to handle", + "ConfigCode": "6" + }, + { + "Unit": "software", + "EventName": "alignment-faults", + "BriefDescription": "Number of kernel handled memory alignment faults", + "ConfigCode": "7" + }, + { + "Unit": "software", + "EventName": "emulation-faults", + "BriefDescription": "Number of kernel handled unimplemented instructio= n faults handled through emulation", + "ConfigCode": "8" + }, + { + "Unit": "software", + "EventName": "dummy", + "BriefDescription": "A placeholder event that doesn't count anything", + "ConfigCode": "9" + }, + { + "Unit": "software", + "EventName": "bpf-output", + "BriefDescription": "An event used by BPF programs to write to the per= f ring buffer", + "ConfigCode": "10" + }, + { + "Unit": "software", + "EventName": "cgroup-switches", + "BriefDescription": "Number of context switches to a task in a differe= nt cgroup", + "ConfigCode": "11" + } +] diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index a4569a74db07..041c598b16d8 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -19,109 +19,147 @@ struct pmu_table_entry { }; =20 static const char *const big_c_string =3D -/* offset=3D0 */ "tool\000" -/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000\000\000\000" -/* offset=3D81 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000\000\000\000" -/* offset=3D151 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000\000\000\000" -/* offset=3D219 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000\000\000\000" -/* offset=3D295 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000\000\000\000" -/* offset=3D440 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\0= 00\000" -/* offset=3D543 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000\000\000\000" -/* offset=3D660 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000\000\000\000" -/* offset=3D736 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000\000\000\000" -/* offset=3D822 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0\000\000\000" -/* offset=3D932 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\0= 00\000\000" -/* offset=3D1039 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000\000\000\= 000" -/* offset=3D1138 */ "default_core\000" -/* offset=3D1151 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000\000\000\000" -/* offset=3D1213 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000\000\000\000" -/* offset=3D1275 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000\000\000\000Attributable Level 3 cache access, read\0= 00" -/* offset=3D1373 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\0= 00\000\000" -/* offset=3D1475 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000\000\000\000" -/* offset=3D1608 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000\000\000\000" -/* offset=3D1726 */ "hisi_sccl,ddrc\000" -/* offset=3D1741 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000\000" -/* offset=3D1811 */ "uncore_cbox\000" -/* offset=3D1823 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000\000\000\000\000" -/* offset=3D1977 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000\000" -/* offset=3D2031 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000\000" -/* offset=3D2089 */ "hisi_sccl,l3c\000" -/* offset=3D2103 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000\000" -/* offset=3D2171 */ "uncore_imc_free_running\000" -/* offset=3D2195 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000\000" -/* offset=3D2275 */ "uncore_imc\000" -/* offset=3D2286 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000\000" -/* offset=3D2351 */ "uncore_sys_ddr_pmu\000" -/* offset=3D2370 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" -/* offset=3D2446 */ "uncore_sys_ccn_pmu\000" -/* offset=3D2465 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" -/* offset=3D2542 */ "uncore_sys_cmn_pmu\000" -/* offset=3D2561 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000\000\000\000" -/* offset=3D2704 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" -/* offset=3D2726 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" -/* offset=3D2789 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" -/* offset=3D2955 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3019 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3086 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" -/* offset=3D3157 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" -/* offset=3D3251 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" -/* offset=3D3385 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" -/* offset=3D3449 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3517 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3587 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" -/* offset=3D3609 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" -/* offset=3D3631 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" -/* offset=3D3651 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" +/* offset=3D0 */ "software\000" +/* offset=3D9 */ "cpu-clock\000software\000Per-CPU high-resolution timer b= ased event\000config=3D0\000\00000\000\000\000\000\000" +/* offset=3D87 */ "task-clock\000software\000Per-task high-resolution time= r based event\000config=3D1\000\00000\000\000\000\000\000" +/* offset=3D167 */ "faults\000software\000Number of page faults [This even= t is an alias of page-faults]\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D262 */ "page-faults\000software\000Number of page faults [This= event is an alias of faults]\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D357 */ "context-switches\000software\000Number of context swit= ches [This event is an alias of cs]\000config=3D3\000\00000\000\000\000\000= \000" +/* offset=3D458 */ "cs\000software\000Number of context switches [This eve= nt is an alias of context-switches]\000config=3D3\000\00000\000\000\000\000= \000" +/* offset=3D559 */ "cpu-migrations\000software\000Number of times a proces= s has migrated to a new CPU [This event is an alias of migrations]\000confi= g=3D4\000\00000\000\000\000\000\000" +/* offset=3D691 */ "migrations\000software\000Number of times a process ha= s migrated to a new CPU [This event is an alias of cpu-migrations]\000confi= g=3D4\000\00000\000\000\000\000\000" +/* offset=3D823 */ "minor-faults\000software\000Number of minor page fault= s. Minor faults don't require I/O to handle\000config=3D5\000\00000\000\000= \000\000\000" +/* offset=3D932 */ "major-faults\000software\000Number of major page fault= s. Major faults require I/O to handle\000config=3D6\000\00000\000\000\000\0= 00\000" +/* offset=3D1035 */ "alignment-faults\000software\000Number of kernel hand= led memory alignment faults\000config=3D7\000\00000\000\000\000\000\000" +/* offset=3D1127 */ "emulation-faults\000software\000Number of kernel hand= led unimplemented instruction faults handled through emulation\000config=3D= 8\000\00000\000\000\000\000\000" +/* offset=3D1254 */ "dummy\000software\000A placeholder event that doesn't= count anything\000config=3D9\000\00000\000\000\000\000\000" +/* offset=3D1334 */ "bpf-output\000software\000An event used by BPF progra= ms to write to the perf ring buffer\000config=3D0xa\000\00000\000\000\000\0= 00\000" +/* offset=3D1436 */ "cgroup-switches\000software\000Number of context swit= ches to a task in a different cgroup\000config=3D0xb\000\00000\000\000\000\= 000\000" +/* offset=3D1539 */ "tool\000" +/* offset=3D1544 */ "duration_time\000tool\000Wall clock interval time in = nanoseconds\000config=3D1\000\00000\000\000\000\000\000" +/* offset=3D1620 */ "user_time\000tool\000User (non-kernel) time in nanose= conds\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D1690 */ "system_time\000tool\000System/kernel time in nanoseco= nds\000config=3D3\000\00000\000\000\000\000\000" +/* offset=3D1758 */ "has_pmem\000tool\0001 if persistent memory installed = otherwise 0\000config=3D4\000\00000\000\000\000\000\000" +/* offset=3D1834 */ "num_cores\000tool\000Number of cores. A core consists= of 1 or more thread, with each thread being associated with a logical Linu= x CPU\000config=3D5\000\00000\000\000\000\000\000" +/* offset=3D1979 */ "num_cpus\000tool\000Number of logical Linux CPUs. The= re may be multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\= 000\000" +/* offset=3D2082 */ "num_cpus_online\000tool\000Number of online logical L= inux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\0000= 0\000\000\000\000\000" +/* offset=3D2199 */ "num_dies\000tool\000Number of dies. Each die has 1 or= more cores\000config=3D8\000\00000\000\000\000\000\000" +/* offset=3D2275 */ "num_packages\000tool\000Number of packages. Each pack= age has 1 or more die\000config=3D9\000\00000\000\000\000\000\000" +/* offset=3D2361 */ "slots\000tool\000Number of functional units that in p= arallel can execute parts of an instruction\000config=3D0xa\000\00000\000\0= 00\000\000\000" +/* offset=3D2471 */ "smt_on\000tool\0001 if simultaneous multithreading (a= ka hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\= 000\000\000" +/* offset=3D2578 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000\000\000\= 000" +/* offset=3D2677 */ "default_core\000" +/* offset=3D2690 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000\000\000\000" +/* offset=3D2752 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000\000\000\000" +/* offset=3D2814 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000\000\000\000Attributable Level 3 cache access, read\0= 00" +/* offset=3D2912 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\0= 00\000\000" +/* offset=3D3014 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000\000\000\000" +/* offset=3D3147 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000\000\000\000" +/* offset=3D3265 */ "hisi_sccl,ddrc\000" +/* offset=3D3280 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000\000" +/* offset=3D3350 */ "uncore_cbox\000" +/* offset=3D3362 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000\000\000\000\000" +/* offset=3D3516 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000\000" +/* offset=3D3570 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000\000" +/* offset=3D3628 */ "hisi_sccl,l3c\000" +/* offset=3D3642 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000\000" +/* offset=3D3710 */ "uncore_imc_free_running\000" +/* offset=3D3734 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000\000" +/* offset=3D3814 */ "uncore_imc\000" +/* offset=3D3825 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000\000" +/* offset=3D3890 */ "uncore_sys_ddr_pmu\000" +/* offset=3D3909 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" +/* offset=3D3985 */ "uncore_sys_ccn_pmu\000" +/* offset=3D4004 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" +/* offset=3D4081 */ "uncore_sys_cmn_pmu\000" +/* offset=3D4100 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000\000\000\000" +/* offset=3D4243 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D4265 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D4328 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" +/* offset=3D4494 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D4558 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D4625 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D4696 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" +/* offset=3D4790 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" +/* offset=3D4924 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D4988 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D5056 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D5126 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D5148 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D5170 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D5190 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" ; =20 +static const struct compact_pmu_event pmu_events__common_software[] =3D { +{ 1035 }, /* alignment-faults\000software\000Number of kernel handled memo= ry alignment faults\000config=3D7\000\00000\000\000\000\000\000 */ +{ 1334 }, /* bpf-output\000software\000An event used by BPF programs to wr= ite to the perf ring buffer\000config=3D0xa\000\00000\000\000\000\000\000 */ +{ 1436 }, /* cgroup-switches\000software\000Number of context switches to = a task in a different cgroup\000config=3D0xb\000\00000\000\000\000\000\000 = */ +{ 357 }, /* context-switches\000software\000Number of context switches [Th= is event is an alias of cs]\000config=3D3\000\00000\000\000\000\000\000 */ +{ 9 }, /* cpu-clock\000software\000Per-CPU high-resolution timer based eve= nt\000config=3D0\000\00000\000\000\000\000\000 */ +{ 559 }, /* cpu-migrations\000software\000Number of times a process has mi= grated to a new CPU [This event is an alias of migrations]\000config=3D4\00= 0\00000\000\000\000\000\000 */ +{ 458 }, /* cs\000software\000Number of context switches [This event is an= alias of context-switches]\000config=3D3\000\00000\000\000\000\000\000 */ +{ 1254 }, /* dummy\000software\000A placeholder event that doesn't count a= nything\000config=3D9\000\00000\000\000\000\000\000 */ +{ 1127 }, /* emulation-faults\000software\000Number of kernel handled unim= plemented instruction faults handled through emulation\000config=3D8\000\00= 000\000\000\000\000\000 */ +{ 167 }, /* faults\000software\000Number of page faults [This event is an = alias of page-faults]\000config=3D2\000\00000\000\000\000\000\000 */ +{ 932 }, /* major-faults\000software\000Number of major page faults. Major= faults require I/O to handle\000config=3D6\000\00000\000\000\000\000\000 */ +{ 691 }, /* migrations\000software\000Number of times a process has migrat= ed to a new CPU [This event is an alias of cpu-migrations]\000config=3D4\00= 0\00000\000\000\000\000\000 */ +{ 823 }, /* minor-faults\000software\000Number of minor page faults. Minor= faults don't require I/O to handle\000config=3D5\000\00000\000\000\000\000= \000 */ +{ 262 }, /* page-faults\000software\000Number of page faults [This event i= s an alias of faults]\000config=3D2\000\00000\000\000\000\000\000 */ +{ 87 }, /* task-clock\000software\000Per-task high-resolution timer based = event\000config=3D1\000\00000\000\000\000\000\000 */ +}; static const struct compact_pmu_event pmu_events__common_tool[] =3D { -{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000\000\000\000 */ -{ 219 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000\000\000\000 */ -{ 295 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000\000\000\000 */ -{ 440 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\000\000 */ -{ 543 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= \000\000\000 */ -{ 660 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000\000\000\000 */ -{ 736 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000\000\000\000 */ -{ 822 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000\000\00= 0\000 */ -{ 932 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\000\000\0= 00 */ -{ 151 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000\000\000\000 */ -{ 1039 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000\000\000\000 */ -{ 81 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000\000\000\000 */ +{ 1544 }, /* duration_time\000tool\000Wall clock interval time in nanoseco= nds\000config=3D1\000\00000\000\000\000\000\000 */ +{ 1758 }, /* has_pmem\000tool\0001 if persistent memory installed otherwis= e 0\000config=3D4\000\00000\000\000\000\000\000 */ +{ 1834 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or= more thread, with each thread being associated with a logical Linux CPU\00= 0config=3D5\000\00000\000\000\000\000\000 */ +{ 1979 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may b= e multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\000\000 = */ +{ 2082 }, /* num_cpus_online\000tool\000Number of online logical Linux CPU= s. There may be multiple such CPUs on a core\000config=3D7\000\00000\000\00= 0\000\000\000 */ +{ 2199 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more co= res\000config=3D8\000\00000\000\000\000\000\000 */ +{ 2275 }, /* num_packages\000tool\000Number of packages. Each package has = 1 or more die\000config=3D9\000\00000\000\000\000\000\000 */ +{ 2361 }, /* slots\000tool\000Number of functional units that in parallel = can execute parts of an instruction\000config=3D0xa\000\00000\000\000\000\0= 00\000 */ +{ 2471 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hyper= threading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\000\000\= 000 */ +{ 1690 }, /* system_time\000tool\000System/kernel time in nanoseconds\000c= onfig=3D3\000\00000\000\000\000\000\000 */ +{ 2578 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000\000\000\000 */ +{ 1620 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\00= 0config=3D2\000\00000\000\000\000\000\000 */ =20 }; =20 const struct pmu_table_entry pmu_events__common[] =3D { +{ + .entries =3D pmu_events__common_software, + .num_entries =3D ARRAY_SIZE(pmu_events__common_software), + .pmu_name =3D { 0 /* software\000 */ }, +}, { .entries =3D pmu_events__common_tool, .num_entries =3D ARRAY_SIZE(pmu_events__common_tool), - .pmu_name =3D { 0 /* tool\000 */ }, + .pmu_name =3D { 1539 /* tool\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_cpu_default_cor= e[] =3D { -{ 1151 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000\000\000\000 */ -{ 1213 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000\000\000\000 */ -{ 1475 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000\000\000\000 */ -{ 1608 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000\000\000\000 */ -{ 1275 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000\000\000\000Attributable Level 3 cache access, read\000 */ -{ 1373 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\000\000\0= 00 */ +{ 2690 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000\000\000\000 */ +{ 2752 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000\000\000\000 */ +{ 3014 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000\000\000\000 */ +{ 3147 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000\000\000\000 */ +{ 2814 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000\000\000\000Attributable Level 3 cache access, read\000 */ +{ 2912 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\000\000\0= 00 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_d= drc[] =3D { -{ 1741 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000\000\000\000\000 */ +{ 3280 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l= 3c[] =3D { -{ 2103 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000\000 */ +{ 3642 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox= [] =3D { -{ 1977 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000\000 */ -{ 2031 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000\000 */ -{ 1823 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000\000\000\000\000 */ +{ 3516 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000\000 */ +{ 3570 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000\000 */ +{ 3362 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc[= ] =3D { -{ 2286 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000\000 */ +{ 3825 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_= free_running[] =3D { -{ 2195 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000\000 */ +{ 3734 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000\000 */ =20 }; =20 @@ -129,51 +167,51 @@ const struct pmu_table_entry pmu_events__test_soc_cpu= [] =3D { { .entries =3D pmu_events__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_default_core), - .pmu_name =3D { 1138 /* default_core\000 */ }, + .pmu_name =3D { 2677 /* default_core\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_ddrc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc), - .pmu_name =3D { 1726 /* hisi_sccl,ddrc\000 */ }, + .pmu_name =3D { 3265 /* hisi_sccl,ddrc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_l3c, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c), - .pmu_name =3D { 2089 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 3628 /* hisi_sccl,l3c\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_cbox, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox), - .pmu_name =3D { 1811 /* uncore_cbox\000 */ }, + .pmu_name =3D { 3350 /* uncore_cbox\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc), - .pmu_name =3D { 2275 /* uncore_imc\000 */ }, + .pmu_name =3D { 3814 /* uncore_imc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc_free_running, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_= running), - .pmu_name =3D { 2171 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 3710 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 2704 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ -{ 3385 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ -{ 3157 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ -{ 3251 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ -{ 3449 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ -{ 3517 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ -{ 2789 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ -{ 2726 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ -{ 3651 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ -{ 3587 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ -{ 3609 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ -{ 3631 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ -{ 3086 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ -{ 2955 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ -{ 3019 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ +{ 4243 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 4924 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 4696 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ +{ 4790 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ +{ 4988 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 5056 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 4328 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ +{ 4265 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 5190 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 5126 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 5148 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 5170 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 4625 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 4494 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 4558 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -181,18 +219,18 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { { .entries =3D pmu_metrics__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core), - .pmu_name =3D { 1138 /* default_core\000 */ }, + .pmu_name =3D { 2677 /* default_core\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 2465 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ +{ 4004 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= cmn_pmu[] =3D { -{ 2561 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000\000\000\000 */ +{ 4100 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ddr_pmu[] =3D { -{ 2370 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ +{ 3909 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ =20 }; =20 @@ -200,17 +238,17 @@ const struct pmu_table_entry pmu_events__test_soc_sys= [] =3D { { .entries =3D pmu_events__test_soc_sys_uncore_sys_ccn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_p= mu), - .pmu_name =3D { 2446 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 3985 /* uncore_sys_ccn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_cmn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_p= mu), - .pmu_name =3D { 2542 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 4081 /* uncore_sys_cmn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_ddr_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_p= mu), - .pmu_name =3D { 2351 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 3890 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 @@ -632,8 +670,20 @@ static const struct pmu_events_map *map_for_pmu(struct= perf_pmu *pmu) { struct perf_cpu cpu =3D {-1}; =20 - if (pmu) + if (pmu) { + for (size_t i =3D 0; i < ARRAY_SIZE(pmu_events__common); i= ++) { + const char *pmu_name =3D &big_c_string[pmu_events_= _common[i].pmu_name.offset]; + + if (!strcmp(pmu_name, pmu->name)) { + const struct pmu_events_map *map =3D &pmu_= events_map[0]; + + while (strcmp("common", map->arch)) + map++; + return map; + } + } cpu =3D perf_cpu_map__min(pmu->cpus); + } return map_for_cpu(cpu); } =20 diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index e821155151ec..60e13a1a7d7a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -295,6 +295,7 @@ class JsonEvent: 'cpu_atom': 'cpu_atom', 'ali_drw': 'ali_drw', 'arm_cmn': 'arm_cmn', + 'software': 'software', 'tool': 'tool', } return table[unit] if unit in table else f'uncore_{unit.lower()}' @@ -1158,8 +1159,20 @@ static const struct pmu_events_map *map_for_pmu(stru= ct perf_pmu *pmu) { struct perf_cpu cpu =3D {-1}; =20 - if (pmu) + if (pmu) { + for (size_t i =3D 0; i < ARRAY_SIZE(pmu_events__common); i= ++) { + const char *pmu_name =3D &big_c_string[pmu_events_= _common[i].pmu_name.offset]; + + if (!strcmp(pmu_name, pmu->name)) { + const struct pmu_events_map *map =3D &pmu_= events_map[0]; + + while (strcmp("common", map->arch)) + map++; + return map; + } + } cpu =3D perf_cpu_map__min(pmu->cpus); + } return map_for_cpu(cpu); } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 1FC3E271461 for ; Wed, 23 Jul 2025 23:22:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312973; cv=none; b=QuLXT6HCfHBjaFYqYHd04kJCbR5UokVJtGlLyY4WESiccevnLcr12M/GKYQG5s3e3iTd8GJUfuQCcDwiO6itSV7Il/T7r6jJ0IazVL3lItrdFaXtO7CnLWpI6ngH4r1K0nSf0MYW1IezDkwjDGS+KAhz2HacQ+wojp9mDAL5yZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312973; c=relaxed/simple; bh=17rEB4MJAJG1hwEIP5Lm9Dl7JqEt+d4aAcKCELOYq5k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KZbwekdfGisgNuKA6acvpF8dFhno3jkrz1y6Yic/yr9IdlBULI1DapzgRdywHy/C7C78o2+7Q4UQdeq569NIXLPWt0MrQwoD+nIymA6MZk1JHCO9X/VEoMqP+2GhybEzToSQZGKfmk1MzEvLWhLoUCEFoeArzW5X+uNzOdKWLNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=alM6xRMD; arc=none smtp.client-ip=209.85.216.74 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="alM6xRMD" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-31215090074so499063a91.0 for ; Wed, 23 Jul 2025 16:22:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312971; x=1753917771; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=H3jSe/pI6LJ1LwZTg3yGBw9DxWFVtNW3isKMNOtxi/o=; b=alM6xRMD+O25n2WV4OyKqVzQmZcMMlUW0AQOMGXxSvYRbo4MTLGe1hUoiMXzVQtFOn +ttejqsuoMSZQXci62BzEf54zYx6yxfqxBa594v0KcvOLfN2saVb6jKhC+5Rtz49QduB 3ZkuA8VK+fA6uo8pYHOWyj0d/K5O6LDPn1NeSyuYM+5b8YFGxtGuXvgktHT0QGncubWF y5o+F4kZYZhWME86waO2tGJ1Rb6pIMQ5DZnqusY2RFe0GtQEGq4uwygpdL3qClKHRC2w DJYtFtZhWeIDhBHsOzT96kqp0icjv9TgfVoXQbbCXB0nP31iz5kzdbuf+Bwv9TrBWJcl rvwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312971; x=1753917771; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H3jSe/pI6LJ1LwZTg3yGBw9DxWFVtNW3isKMNOtxi/o=; b=iM7UBiE83MPMm074kb2fnGI9QedTAW+RNZ9MrwBuRbBrL8JPg1EnZIhdZt40LZGXSo rBdB0x1OkJaEGSBznq6ATJBv1US3ot3Hk/wWTfugLpu1JtdiFyEquXx+Mb081K0whUzy QrzkS62BVVxBaSXUjSD0IpUJONBKIfQ80R3p2wHJZb514nAIwvR7uN8SD58aWABxGsZc DPxonJtAK8vXlBQtaGEKijsNWDkNksfH+9csrA6OS5igNDDvjRmeG5nMUo3UWilr7q5k PjpPuBXh6fa9BO08QDgJ7+5j5R8z34VRu8iHiHg27ewXCrvn1GxbgGgXEKkJunH3LAQz PJ0Q== X-Forwarded-Encrypted: i=1; AJvYcCUxhTJE0tvI1aKJ+gD3SJeXSi+ketLqn1WpwoHKmbRMpmqNdb8hsC/GNIylMHi/yatFCYhRqtC6QtTqiJI=@vger.kernel.org X-Gm-Message-State: AOJu0YyzsrIyBya9msQ9joax3SjeEma7eQx+JPtEZlja/dhOviCiVjbz 2R6X27+MKk0MhKKIG6Tt2kG0G9acfHFnUczeEpoT2sApzx/gUElsqyeeer3HCnSmgDu9zSAOF9m 1p4BHfL93pQ== X-Google-Smtp-Source: AGHT+IGk7+ULF4hyjENYXKr/zeh//TuNrbkwWVTfkk+ehu3vwl1IY3OnSUWlSm5QE+8HzoxYSigb0h4hFtnW X-Received: from plbme13.prod.google.com ([2002:a17:902:fc4d:b0:23f:8c02:f1bb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1b4d:b0:235:1706:1fe7 with SMTP id d9443c01a7336-23f9812b6c9mr71793135ad.4.1753312971438; Wed, 23 Jul 2025 16:22:51 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:04 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-4-irogers@google.com> Subject: [PATCH v8 03/16] perf parse-events: Remove non-json software events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the hard coded encodings from parse-events. This has the consequence that software events are matched using the sysfs/json priority, will be case insensitive and will be wildcarded across PMUs. As there were software and hardware types in the parsing code, the removal means software vs hardware logic can be removed and hardware assumed. Now the perf json provides detailed descriptions of software events, remove the previous listing support that didn't contain event descriptions. When globbing is required for the "sw" option in perf list, use string PMU globbing as was done previously for the tool PMU. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-list.c | 19 ++++++------- tools/perf/util/parse-events.c | 51 ---------------------------------- tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-events.l | 38 +++++++++---------------- tools/perf/util/parse-events.y | 29 ++++++++----------- tools/perf/util/print-events.c | 2 -- 6 files changed, 33 insertions(+), 107 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index e9b595d75df2..674bb0afbf93 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -623,16 +623,17 @@ int cmd_list(int argc, const char **argv) else if (strcmp(argv[i], "sw") =3D=3D 0 || strcmp(argv[i], "software") =3D=3D 0) { char *old_pmu_glob =3D default_ps.pmu_glob; + static const char * const sw_globs[] =3D { "software", "tool" }; =20 - print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, - event_symbols_sw, PERF_COUNT_SW_MAX); - default_ps.pmu_glob =3D strdup("tool"); - if (!default_ps.pmu_glob) { - ret =3D -1; - goto out; + for (size_t j =3D 0; j < ARRAY_SIZE(sw_globs); j++) { + default_ps.pmu_glob =3D strdup(sw_globs[j]); + if (!default_ps.pmu_glob) { + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + zfree(&default_ps.pmu_glob); } - perf_pmus__print_pmu_events(&print_cb, ps); - zfree(&default_ps.pmu_glob); default_ps.pmu_glob =3D old_pmu_glob; } else if (strcmp(argv[i], "cache") =3D=3D 0 || strcmp(argv[i], "hwcache") =3D=3D 0) @@ -679,8 +680,6 @@ int cmd_list(int argc, const char **argv) default_ps.event_glob =3D s; print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE, event_symbols_hw, PERF_COUNT_HW_MAX); - print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, - event_symbols_sw, PERF_COUNT_SW_MAX); print_hwcache_events(&print_cb, ps); perf_pmus__print_pmu_events(&print_cb, ps); print_tracepoint_events(&print_cb, ps); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index a59ae5ca0f89..1ae481c9802b 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -84,57 +84,6 @@ const struct event_symbol event_symbols_hw[PERF_COUNT_HW= _MAX] =3D { }, }; =20 -const struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] =3D { - [PERF_COUNT_SW_CPU_CLOCK] =3D { - .symbol =3D "cpu-clock", - .alias =3D "", - }, - [PERF_COUNT_SW_TASK_CLOCK] =3D { - .symbol =3D "task-clock", - .alias =3D "", - }, - [PERF_COUNT_SW_PAGE_FAULTS] =3D { - .symbol =3D "page-faults", - .alias =3D "faults", - }, - [PERF_COUNT_SW_CONTEXT_SWITCHES] =3D { - .symbol =3D "context-switches", - .alias =3D "cs", - }, - [PERF_COUNT_SW_CPU_MIGRATIONS] =3D { - .symbol =3D "cpu-migrations", - .alias =3D "migrations", - }, - [PERF_COUNT_SW_PAGE_FAULTS_MIN] =3D { - .symbol =3D "minor-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_PAGE_FAULTS_MAJ] =3D { - .symbol =3D "major-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_ALIGNMENT_FAULTS] =3D { - .symbol =3D "alignment-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_EMULATION_FAULTS] =3D { - .symbol =3D "emulation-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_DUMMY] =3D { - .symbol =3D "dummy", - .alias =3D "", - }, - [PERF_COUNT_SW_BPF_OUTPUT] =3D { - .symbol =3D "bpf-output", - .alias =3D "", - }, - [PERF_COUNT_SW_CGROUP_SWITCHES] =3D { - .symbol =3D "cgroup-switches", - .alias =3D "", - }, -}; - static const char *const event_types[] =3D { [PERF_TYPE_HARDWARE] =3D "hardware", [PERF_TYPE_SOFTWARE] =3D "software", diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index b47bf2810112..62dc7202e3ba 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -264,7 +264,6 @@ struct event_symbol { const char *alias; }; extern const struct event_symbol event_symbols_hw[]; -extern const struct event_symbol event_symbols_sw[]; =20 char *parse_events_formats_error_string(char *additional_terms); =20 diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 4af7b9c1f44d..2034590eb789 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -117,12 +117,12 @@ do { \ yyless(0); \ } while (0) =20 -static int sym(yyscan_t scanner, int type, int config) +static int sym(yyscan_t scanner, int config) { YYSTYPE *yylval =3D parse_events_get_lval(scanner); =20 - yylval->num =3D (type << 16) + config; - return type =3D=3D PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; + yylval->num =3D config; + return PE_VALUE_SYM_HW; } =20 static int term(yyscan_t scanner, enum parse_events__term_type type) @@ -391,28 +391,16 @@ r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } <> { BEGIN(INITIAL); } } =20 -cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUN= T_HW_CPU_CYCLES); } -stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_= TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TY= PE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW= _INSTRUCTIONS); } -cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT= _HW_CACHE_REFERENCES); } -cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW= _CACHE_MISSES); } -branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE,= PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } -branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_H= W_BRANCH_MISSES); } -bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_B= US_CYCLES); } -ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_R= EF_CPU_CYCLES); } -cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CP= U_CLOCK); } -task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_T= ASK_CLOCK); } -page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COU= NT_SW_PAGE_FAULTS); } -minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW= _PAGE_FAULTS_MIN); } -major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW= _PAGE_FAULTS_MAJ); } -context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_CO= UNT_SW_CONTEXT_SWITCHES); } -cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PE= RF_COUNT_SW_CPU_MIGRATIONS); } -alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_ALIGNMENT_FAULTS); } -emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_EMULATION_FAULTS); } -dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY= ); } -bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_B= PF_OUTPUT); } -cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_CGROUP_SWITCHES); } +cpu-cycles|cycles { return sym(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_= COUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_CO= UNT_HW_STALLED_CYCLES_BACKEND); } +instructions { return sym(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return sym(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES= ); } +cache-misses { return sym(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return sym(yyscanner, PERF_COUNT_HW_BRANC= H_INSTRUCTIONS); } +branch-misses { return sym(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return sym(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return sym(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } =20 {lc_type} { return str(yyscanner, PE_LEGACY_CACHE); } {lc_type}-{lc_op_result} { return str(yyscanner, PE_LEGACY_CACHE); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index f888cbb076d6..a2361c0040d7 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -55,7 +55,7 @@ static void free_list_evsel(struct list_head* list_evsel) %} =20 %token PE_START_EVENTS PE_START_TERMS -%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM +%token PE_VALUE PE_VALUE_SYM_HW PE_TERM %token PE_EVENT_NAME %token PE_RAW PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH @@ -66,10 +66,8 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_TERM_HW %type PE_VALUE %type PE_VALUE_SYM_HW -%type PE_VALUE_SYM_SW %type PE_MODIFIER_EVENT %type PE_TERM -%type value_sym %type PE_RAW %type PE_NAME %type PE_LEGACY_CACHE @@ -306,24 +304,19 @@ PE_NAME sep_dc $$ =3D list; } =20 -value_sym: -PE_VALUE_SYM_HW -| -PE_VALUE_SYM_SW - event_legacy_symbol: -value_sym '/' event_config '/' +PE_VALUE_SYM_HW '/' event_config '/' { struct list_head *list; - int type =3D $1 >> 16; - int config =3D $1 & 255; int err; - bool wildcard =3D (type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYP= E_HW_CACHE); =20 list =3D alloc_list(); if (!list) YYNOMEM; - err =3D parse_events_add_numeric(_parse_state, list, type, config, $3, wi= ldcard); + err =3D parse_events_add_numeric(_parse_state, list, + PERF_TYPE_HARDWARE, $1, + $3, + /*wildcard=3D*/true); parse_events_terms__delete($3); if (err) { free_list_evsel(list); @@ -332,18 +325,18 @@ value_sym '/' event_config '/' $$ =3D list; } | -value_sym sep_slash_slash_dc +PE_VALUE_SYM_HW sep_slash_slash_dc { struct list_head *list; - int type =3D $1 >> 16; - int config =3D $1 & 255; - bool wildcard =3D (type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYP= E_HW_CACHE); int err; =20 list =3D alloc_list(); if (!list) YYNOMEM; - err =3D parse_events_add_numeric(_parse_state, list, type, config, /*head= _config=3D*/NULL, wildcard); + err =3D parse_events_add_numeric(_parse_state, list, + PERF_TYPE_HARDWARE, $1, + /*head_config=3D*/NULL, + /*wildcard=3D*/true); if (err) PE_ABORT(err); $$ =3D list; diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index e233bacaa641..c1a8708b55ab 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -521,8 +521,6 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) { print_symbol_events(print_cb, print_state, PERF_TYPE_HARDWARE, event_symbols_hw, PERF_COUNT_HW_MAX); - print_symbol_events(print_cb, print_state, PERF_TYPE_SOFTWARE, - event_symbols_sw, PERF_COUNT_SW_MAX); =20 print_hwcache_events(print_cb, print_state); =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 75AA42737F0 for ; Wed, 23 Jul 2025 23:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312977; cv=none; b=rrmid3UArirzbRz6W0vQEuB3jmuNmz30Vk2dMQz6MR16oLENChYWBjj+hbUuKY/edjvBFeoIcYvaldvXtrj6LO6uZmz4iUp+y2nhSpATpcCRKHwV1p7reDrI4mXYAvjco6nu06eYCype4J49MyoiSOgbLlNZfXyPoXzCCqS2gS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312977; c=relaxed/simple; bh=tE74RNbYZV6qoUXLX6zP0wZBqh0cMN/lDuB25GJ9V7s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jaHyILT8UijBQ1dXoAXaLLI7aboL8PwbUPW31jzmeY8y5SWPASn1t+O/JO2BIHbBGnbbRkBz/kuKrxBzPY3nv8OUSB6o9KNg7kdPS4deZLuPIjiVnnc71unzh1geyWD6xA04jpyV6LMavGC23K3MBq3zyRL2YhcxZC0gBSAbyhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Cuc2yhxi; arc=none smtp.client-ip=209.85.214.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Cuc2yhxi" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2355651d204so2772305ad.2 for ; Wed, 23 Jul 2025 16:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312975; x=1753917775; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZzAoY2/0bYYy0Y49MP8J/HVmXMXErIlx8RY6RE0UuMI=; b=Cuc2yhxitJcbgzEv2irwii5t7Pinv874tyfXJFH2GWwHZTBFFF5gfP5wFBDDCSqc0/ JEek8ZrIIQaiSmMl+mPpvGtrTOjTpbrvVx47a+RVZxmm1Jgg4W8vadpcBzD0ohAH50K5 FAWUKJYxvaxVG0YVGbzHHL0MpT27indesRBLKx/AiM3x+z6DsuqDtpCLjj2s7R/Lrljb OnNbmt6oLQRT3lBCDFiQ5gBL1I4ASCz72+zulksw/BhxH9D7T0QPzAoKOzxLTELMI55U OWNq2rqwRR107gfSRdGBmIe3SC11nTHRGBpYIALmxtKDHsDRqx+euZMcY+oQXlO4Tbek 5fHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312975; x=1753917775; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZzAoY2/0bYYy0Y49MP8J/HVmXMXErIlx8RY6RE0UuMI=; b=k3bGOi7cVsSDR5VRCCw02ENa/3EGKacql/+GiVF3d4Wzw7GnAJemYl5AUymzRSGzmb VOmOUa3DakzaqBhBA2b25xVwEhV/aBkx8yZQDYyYADBp8iokSII4R0KybznPOas3Nk15 tWwr0UuxfHipx15cGROkxmmOExm40hoidwWwGIAx8ruLcWbDMGouMB6FCUh461JRG/hB hOHuoLF0AMttpfBbTY3Z+bhy2fvAnEIDKWKGxy03qxACVdd1WGB6ts/Eyo8y48QcDdu+ wdCXL5wPfjXXs6ie4G0K3JGD4LgrsJJr/0lQt2cmQ/23S/3A59TaWt905JdYEoWcY+WF Ew0Q== X-Forwarded-Encrypted: i=1; AJvYcCU6k4M4br7oogMdNErqLvIo4G1a8NuVJU/xua2Ja+SOKjDTeg7K9LhUxo2MgyX0CV8veBnPtaq2avZGKHI=@vger.kernel.org X-Gm-Message-State: AOJu0YzDKeV8ZSkA60lYUE2di2DdAmOMkKiAHHBJ8qP1HpcO2LyNShL4 H4frNbqDMy8LxQzHPXkZCQktzeIsmLIDmYmwGDTmOZQZLYSY0LDL+SU3eIgOxJR7kS8f6uIXl9p EGRfkS6B8kA== X-Google-Smtp-Source: AGHT+IEEcX5zA+6fJGW9UrCkKhwKuMA/N428eLPKwCKCDmLU+9rn8YnffIF+aD57pwl0KO6WkIRxE9gKnmXA X-Received: from plbmu14.prod.google.com ([2002:a17:903:b4e:b0:23f:8df8:e7af]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:ac8:b0:220:ea90:191e with SMTP id d9443c01a7336-23f981468cbmr73059425ad.4.1753312974771; Wed, 23 Jul 2025 16:22:54 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:05 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-5-irogers@google.com> Subject: [PATCH v8 04/16] perf tp_pmu: Factor existing tracepoint logic to new file From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Start the creation of a tracepoint PMU abstraction. Tracepoint events don't follow the regular sysfs perf conventions. Eventually the new PMU abstraction will bridge the gap so tracepoint events look more like regular perf ones. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/Build | 1 + tools/perf/util/evsel.c | 21 +---- tools/perf/util/parse-events.c | 147 ++++++++++++++------------------- tools/perf/util/tp_pmu.c | 95 +++++++++++++++++++++ tools/perf/util/tp_pmu.h | 12 +++ 5 files changed, 170 insertions(+), 106 deletions(-) create mode 100644 tools/perf/util/tp_pmu.c create mode 100644 tools/perf/util/tp_pmu.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 12bc01c843b2..4959e7a990e4 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -88,6 +88,7 @@ perf-util-y +=3D pmu-bison.o perf-util-y +=3D drm_pmu.o perf-util-y +=3D hwmon_pmu.o perf-util-y +=3D tool_pmu.o +perf-util-y +=3D tp_pmu.o perf-util-y +=3D svghelper.o perf-util-y +=3D trace-event-info.o perf-util-y +=3D trace-event-scripting.o diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3896a04d90af..5a1d19b4e5cd 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -59,6 +59,7 @@ #include "drm_pmu.h" #include "hwmon_pmu.h" #include "tool_pmu.h" +#include "tp_pmu.h" #include "rlimit.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" @@ -571,24 +572,6 @@ struct evsel *evsel__clone(struct evsel *dest, struct = evsel *orig) return NULL; } =20 -static int trace_event__id(const char *sys, const char *name) -{ - char *tp_dir =3D get_events_file(sys); - char path[PATH_MAX]; - int id, err; - - if (!tp_dir) - return -1; - - scnprintf(path, PATH_MAX, "%s/%s/id", tp_dir, name); - put_events_file(tp_dir); - err =3D filename__read_int(path, &id); - if (err) - return err; - - return id; -} - /* * Returns pointer with encoded error via interface. */ @@ -622,7 +605,7 @@ struct evsel *evsel__newtp_idx(const char *sys, const c= har *name, int idx, bool event_attr_init(&attr); =20 if (format) { - id =3D trace_event__id(sys, name); + id =3D tp_pmu__id(sys, name); if (id < 0) { err =3D id; goto out_free; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1ae481c9802b..f19541ca5268 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -17,13 +17,12 @@ #include "string2.h" #include "strbuf.h" #include "debug.h" -#include -#include #include #include #include #include "pmu.h" #include "pmus.h" +#include "tp_pmu.h" #include "asm/bug.h" #include "ui/ui.h" #include "util/parse-branch-options.h" @@ -33,6 +32,7 @@ #include "util/stat.h" #include "util/util.h" #include "tracepoint.h" +#include =20 #define MAX_NAME_LEN 100 =20 @@ -558,105 +558,82 @@ static int add_tracepoint(struct parse_events_state = *parse_state, return 0; } =20 -static int add_tracepoint_multi_event(struct parse_events_state *parse_sta= te, - struct list_head *list, - const char *sys_name, const char *evt_name, - struct parse_events_error *err, - struct parse_events_terms *head_config, YYLTYPE *loc) -{ - char *evt_path; - struct io_dirent64 *evt_ent; - struct io_dir evt_dir; - int ret =3D 0, found =3D 0; - - evt_path =3D get_events_file(sys_name); - if (!evt_path) { - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; - } - io_dir__init(&evt_dir, open(evt_path, O_CLOEXEC | O_DIRECTORY | O_RDONLY)= ); - if (evt_dir.dirfd < 0) { - put_events_file(evt_path); - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; - } +struct add_tracepoint_multi_args { + struct parse_events_state *parse_state; + struct list_head *list; + const char *sys_glob; + const char *evt_glob; + struct parse_events_error *err; + struct parse_events_terms *head_config; + YYLTYPE *loc; + int found; +}; =20 - while (!ret && (evt_ent =3D io_dir__readdir(&evt_dir))) { - if (!strcmp(evt_ent->d_name, ".") - || !strcmp(evt_ent->d_name, "..") - || !strcmp(evt_ent->d_name, "enable") - || !strcmp(evt_ent->d_name, "filter")) - continue; +static int add_tracepoint_multi_event_cb(void *state, const char *sys_name= , const char *evt_name) +{ + struct add_tracepoint_multi_args *args =3D state; + int ret; =20 - if (!strglobmatch(evt_ent->d_name, evt_name)) - continue; + if (!strglobmatch(evt_name, args->evt_glob)) + return 0; =20 - found++; + args->found++; + ret =3D add_tracepoint(args->parse_state, args->list, sys_name, evt_name, + args->err, args->head_config, args->loc); =20 - ret =3D add_tracepoint(parse_state, list, sys_name, evt_ent->d_name, - err, head_config, loc); - } + return ret; +} =20 - if (!found) { - tracepoint_error(err, ENOENT, sys_name, evt_name, loc->first_column); - ret =3D -1; +static int add_tracepoint_multi_event(struct add_tracepoint_multi_args *ar= gs, const char *sys_name) +{ + if (strpbrk(args->evt_glob, "*?") =3D=3D NULL) { + /* Not a glob. */ + args->found++; + return add_tracepoint(args->parse_state, args->list, sys_name, args->evt= _glob, + args->err, args->head_config, args->loc); } =20 - put_events_file(evt_path); - close(evt_dir.dirfd); - return ret; + return tp_pmu__for_each_tp_event(sys_name, args, add_tracepoint_multi_eve= nt_cb); } =20 -static int add_tracepoint_event(struct parse_events_state *parse_state, - struct list_head *list, - const char *sys_name, const char *evt_name, - struct parse_events_error *err, - struct parse_events_terms *head_config, YYLTYPE *loc) +static int add_tracepoint_multi_sys_cb(void *state, const char *sys_name) { - return strpbrk(evt_name, "*?") ? - add_tracepoint_multi_event(parse_state, list, sys_name, evt_name, - err, head_config, loc) : - add_tracepoint(parse_state, list, sys_name, evt_name, - err, head_config, loc); + struct add_tracepoint_multi_args *args =3D state; + + if (!strglobmatch(sys_name, args->sys_glob)) + return 0; + + return add_tracepoint_multi_event(args, sys_name); } =20 static int add_tracepoint_multi_sys(struct parse_events_state *parse_state, struct list_head *list, - const char *sys_name, const char *evt_name, + const char *sys_glob, const char *evt_glob, struct parse_events_error *err, struct parse_events_terms *head_config, YYLTYPE *loc) { - struct io_dirent64 *events_ent; - struct io_dir events_dir; - int ret =3D 0; - char *events_dir_path =3D get_tracing_file("events"); + struct add_tracepoint_multi_args args =3D { + .parse_state =3D parse_state, + .list =3D list, + .sys_glob =3D sys_glob, + .evt_glob =3D evt_glob, + .err =3D err, + .head_config =3D head_config, + .loc =3D loc, + .found =3D 0, + }; + int ret; =20 - if (!events_dir_path) { - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; + if (strpbrk(sys_glob, "*?") =3D=3D NULL) { + /* Not a glob. */ + ret =3D add_tracepoint_multi_event(&args, sys_glob); + } else { + ret =3D tp_pmu__for_each_tp_sys(&args, add_tracepoint_multi_sys_cb); } - io_dir__init(&events_dir, open(events_dir_path, O_CLOEXEC | O_DIRECTORY |= O_RDONLY)); - put_events_file(events_dir_path); - if (events_dir.dirfd < 0) { - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; + if (args.found =3D=3D 0) { + tracepoint_error(err, ENOENT, sys_glob, evt_glob, loc->first_column); + return -ENOENT; } - - while (!ret && (events_ent =3D io_dir__readdir(&events_dir))) { - if (!strcmp(events_ent->d_name, ".") - || !strcmp(events_ent->d_name, "..") - || !strcmp(events_ent->d_name, "enable") - || !strcmp(events_ent->d_name, "header_event") - || !strcmp(events_ent->d_name, "header_page")) - continue; - - if (!strglobmatch(events_ent->d_name, sys_name)) - continue; - - ret =3D add_tracepoint_event(parse_state, list, events_ent->d_name, - evt_name, err, head_config, loc); - } - close(events_dir.dirfd); return ret; } =20 @@ -1348,12 +1325,8 @@ int parse_events_add_tracepoint(struct parse_events_= state *parse_state, return -EINVAL; } =20 - if (strpbrk(sys, "*?")) - return add_tracepoint_multi_sys(parse_state, list, sys, event, - err, head_config, loc); - else - return add_tracepoint_event(parse_state, list, sys, event, - err, head_config, loc); + return add_tracepoint_multi_sys(parse_state, list, sys, event, + err, head_config, loc); } =20 static int __parse_events_add_numeric(struct parse_events_state *parse_sta= te, diff --git a/tools/perf/util/tp_pmu.c b/tools/perf/util/tp_pmu.c new file mode 100644 index 000000000000..42bd967a4530 --- /dev/null +++ b/tools/perf/util/tp_pmu.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "tp_pmu.h" +#include +#include +#include +#include +#include +#include + +int tp_pmu__id(const char *sys, const char *name) +{ + char *tp_dir =3D get_events_file(sys); + char path[PATH_MAX]; + int id, err; + + if (!tp_dir) + return -1; + + scnprintf(path, PATH_MAX, "%s/%s/id", tp_dir, name); + put_events_file(tp_dir); + err =3D filename__read_int(path, &id); + if (err) + return err; + + return id; +} + + +int tp_pmu__for_each_tp_event(const char *sys, void *state, tp_event_callb= ack cb) +{ + char *evt_path; + struct io_dirent64 *evt_ent; + struct io_dir evt_dir; + int ret =3D 0; + + evt_path =3D get_events_file(sys); + if (!evt_path) + return -errno; + + io_dir__init(&evt_dir, open(evt_path, O_CLOEXEC | O_DIRECTORY | O_RDONLY)= ); + if (evt_dir.dirfd < 0) { + ret =3D -errno; + put_events_file(evt_path); + return ret; + } + put_events_file(evt_path); + + while (!ret && (evt_ent =3D io_dir__readdir(&evt_dir))) { + if (!strcmp(evt_ent->d_name, ".") + || !strcmp(evt_ent->d_name, "..") + || !strcmp(evt_ent->d_name, "enable") + || !strcmp(evt_ent->d_name, "filter")) + continue; + + ret =3D cb(state, sys, evt_ent->d_name); + if (ret) + break; + } + close(evt_dir.dirfd); + return ret; +} + +int tp_pmu__for_each_tp_sys(void *state, tp_sys_callback cb) +{ + struct io_dirent64 *events_ent; + struct io_dir events_dir; + int ret =3D 0; + char *events_dir_path =3D get_tracing_file("events"); + + if (!events_dir_path) + return -errno; + + io_dir__init(&events_dir, open(events_dir_path, O_CLOEXEC | O_DIRECTORY |= O_RDONLY)); + if (events_dir.dirfd < 0) { + ret =3D -errno; + put_events_file(events_dir_path); + return ret; + } + put_events_file(events_dir_path); + + while (!ret && (events_ent =3D io_dir__readdir(&events_dir))) { + if (!strcmp(events_ent->d_name, ".") || + !strcmp(events_ent->d_name, "..") || + !strcmp(events_ent->d_name, "enable") || + !strcmp(events_ent->d_name, "header_event") || + !strcmp(events_ent->d_name, "header_page")) + continue; + + ret =3D cb(state, events_ent->d_name); + if (ret) + break; + } + close(events_dir.dirfd); + return ret; +} diff --git a/tools/perf/util/tp_pmu.h b/tools/perf/util/tp_pmu.h new file mode 100644 index 000000000000..49537303bd73 --- /dev/null +++ b/tools/perf/util/tp_pmu.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ +#ifndef __TP_PMU_H +#define __TP_PMU_H + +typedef int (*tp_sys_callback)(void *state, const char *sys_name); +typedef int (*tp_event_callback)(void *state, const char *sys_name, const = char *evt_name); + +int tp_pmu__id(const char *sys, const char *name); +int tp_pmu__for_each_tp_event(const char *sys, void *state, tp_event_callb= ack cb); +int tp_pmu__for_each_tp_sys(void *state, tp_sys_callback cb); + +#endif /* __TP_PMU_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 746242737FD for ; Wed, 23 Jul 2025 23:23:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312982; cv=none; b=pJ2clbP4ujl7XnMQVuqFZHRq2gDOZ9gUI+qJpjpy4ovaHddY22BTVA9VDs+V2ZTL6RZDDPGllrTtAYSjTIJsyJ8ldHTiB6GCErNboL6YExZBvsnAV706yOgMTzaMpUtEp9bLDdgtn1fynx76FxaDf6jTUqEV+Sg4LIkZEXftNGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312982; c=relaxed/simple; bh=lPXmRk8uXh05O798oSMHwJXgWz4TAAy36TccZE5ZHik=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DyiqsgN86Px7xczKBE8lxQUhI55dnhMeUSLO3nuQK8lDa2+ZUnUIyHJ4gYmfw9K5Qv4TRPNfkMGeUdxw4OR18ita5c8H5+GrdTafxPaWn2jy3PlUTf7SIQuvZHw6/GtOvz0bsM1C+M7ROC2Uay2fJuINIo0fqabds0qpbPaZusw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MM2MdW1R; arc=none smtp.client-ip=209.85.214.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MM2MdW1R" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2356ce66d7cso4976225ad.1 for ; Wed, 23 Jul 2025 16:23:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312980; x=1753917780; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iO4rKgWRrLvd7Hy4UwJjm8FO19N1xYwxxMcu1mvGBiY=; b=MM2MdW1RW8FXKHHr0dGvbyAaK+V4TjxYlDXdDnDVBlLnARJnZtrYaCWJDbr0e6lWwv 5J78VZfpWcDv/X3hCzgc1pXyqCrT53JPkq8xMKlMeLLPv7jUIXGHK7nSSPYjDgi+ImV3 T78zZRl4Q1XVJ85BpjIL3044EbDqNrC9VOCw2tdiOH3c6YzxJk7kFsX60wGs0rEh60Xl 9jwxtL5HVyZol1FQDfgh4mQDExeJFqSCZ0TrINlJQPWxPGC+J1sYvp0kkuwqIg/maM6G HOkIZd7AipFWKL5QuFHIoYZDAmJ1/5LqDDIaF1zCoUwFnl4tG6wV1mAap7pz0GwbHm6s tPpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312980; x=1753917780; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iO4rKgWRrLvd7Hy4UwJjm8FO19N1xYwxxMcu1mvGBiY=; b=Zc1DOd9SfCJXHDUO21wp0llZF9Ib0oKQ5HV9jGjVotW7cbJMpJgsQGsetpsKLTqq8K 7jTOo1jXgZQeIg3L0l+dShKX+sOOpPRic2wsl04DB9Kr4BsvWGb7UWS8J9G1jz0NZyM/ aOjBVoMeUUvxohvxRZ/KtPtZ7nfat2toes8DZdkiLRj3Sps7baCKMFxy0+nmtQEq9hjh ocADLcW8xU21h4q/JfbGpmdY6vLgyNFWLiganuVaXwKwhkq88x3DjYVXS4wU0hdVUvPt 7Mr+Y/BNl3M+0+sreQkUed2aSlV7B/CQf5xKWnQcZoKyfjUR2bRK3tvKinQeLCax/Rlw dyQg== X-Forwarded-Encrypted: i=1; AJvYcCWN8cdRADv2I4UvNHD9a0NgmCqvvgiwxb7QGyv0FNtcVOr3wbcA9kJfvXGrtXiQzwLdtunSiajxzDgtPSI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2iIAQN1Vmz40WRvtqZrQLAR4COeyV++XS2Ewsb3a0PhggfHAD VHzxgKfjx5SZ8Vn8XvYmXA7QahkhUu/9P+zkZobfKx11C8WttVW9infzDz5mSQKpKYETvVP6U+C Nng3gAiKiJw== X-Google-Smtp-Source: AGHT+IElv9rsFOM3ePu7WcxiudoaJmlciEvfReOd45LNZWjcTIH+iNrkjFGLct1Xtx5g9/pH5/yAG1iz3G/n X-Received: from plbmz3.prod.google.com ([2002:a17:903:3503:b0:234:c104:43f1]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f68c:b0:223:619e:71da with SMTP id d9443c01a7336-23f981d3162mr75760735ad.49.1753312979629; Wed, 23 Jul 2025 16:22:59 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:06 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-6-irogers@google.com> Subject: [PATCH v8 05/16] perf tp_pmu: Add event APIs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add event APIs for the tracepoint PMU allowing things like perf list to function using it. For perf list add the tracepoint format in the long description (shown with -v). Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/pmu.c | 7 +++ tools/perf/util/tp_pmu.c | 115 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/tp_pmu.h | 7 +++ 3 files changed, 129 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b09b2ea2407a..dc05233e8232 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -24,6 +24,7 @@ #include "hwmon_pmu.h" #include "pmus.h" #include "tool_pmu.h" +#include "tp_pmu.h" #include #include #include "parse-events.h" @@ -1983,6 +1984,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) return false; if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(name)) return false; + if (perf_pmu__is_tracepoint(pmu)) + return tp_pmu__have_event(pmu, name); if (perf_pmu__is_hwmon(pmu)) return hwmon_pmu__have_event(pmu, name); if (perf_pmu__is_drm(pmu)) @@ -1998,6 +2001,8 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; =20 + if (perf_pmu__is_tracepoint(pmu)) + return tp_pmu__num_events(pmu); if (perf_pmu__is_hwmon(pmu)) return hwmon_pmu__num_events(pmu); if (perf_pmu__is_drm(pmu)) @@ -2068,6 +2073,8 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, struct hashmap_entry *entry; size_t bkt; =20 + if (perf_pmu__is_tracepoint(pmu)) + return tp_pmu__for_each_event(pmu, state, cb); if (perf_pmu__is_hwmon(pmu)) return hwmon_pmu__for_each_event(pmu, state, cb); if (perf_pmu__is_drm(pmu)) diff --git a/tools/perf/util/tp_pmu.c b/tools/perf/util/tp_pmu.c index 42bd967a4530..e7534a973247 100644 --- a/tools/perf/util/tp_pmu.c +++ b/tools/perf/util/tp_pmu.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) #include "tp_pmu.h" +#include "pmus.h" #include #include #include @@ -93,3 +94,117 @@ int tp_pmu__for_each_tp_sys(void *state, tp_sys_callbac= k cb) close(events_dir.dirfd); return ret; } + +bool perf_pmu__is_tracepoint(const struct perf_pmu *pmu) +{ + return pmu->type =3D=3D PERF_TYPE_TRACEPOINT; +} + +struct for_each_event_args { + void *state; + pmu_event_callback cb; + const struct perf_pmu *pmu; +}; + +static int for_each_event_cb(void *state, const char *sys_name, const char= *evt_name) +{ + struct for_each_event_args *args =3D state; + char name[2 * FILENAME_MAX + 2]; + /* 16 possible hex digits and 22 other characters and \0. */ + char encoding[16 + 22]; + char *format =3D NULL; + size_t format_size; + struct pmu_event_info info =3D { + .pmu =3D args->pmu, + .pmu_name =3D args->pmu->name, + .event_type_desc =3D "Tracepoint event", + }; + char *tp_dir =3D get_events_file(sys_name); + char path[PATH_MAX]; + int id, err; + + if (!tp_dir) + return -1; + + scnprintf(path, sizeof(path), "%s/%s/id", tp_dir, evt_name); + err =3D filename__read_int(path, &id); + if (err =3D=3D 0) { + snprintf(encoding, sizeof(encoding), "tracepoint/config=3D0x%x/", id); + info.encoding_desc =3D encoding; + } + + scnprintf(path, sizeof(path), "%s/%s/format", tp_dir, evt_name); + put_events_file(tp_dir); + err =3D filename__read_str(path, &format, &format_size); + if (err =3D=3D 0) { + info.long_desc =3D format; + for (size_t i =3D 0 ; i < format_size; i++) { + /* Swap tabs to spaces due to some rendering issues. */ + if (format[i] =3D=3D '\t') + format[i] =3D ' '; + } + } + snprintf(name, sizeof(name), "%s:%s", sys_name, evt_name); + info.name =3D name; + err =3D args->cb(args->state, &info); + free(format); + return err; +} + +static int for_each_event_sys_cb(void *state, const char *sys_name) +{ + return tp_pmu__for_each_tp_event(sys_name, state, for_each_event_cb); +} + +int tp_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_ca= llback cb) +{ + struct for_each_event_args args =3D { + .state =3D state, + .cb =3D cb, + .pmu =3D pmu, + }; + + return tp_pmu__for_each_tp_sys(&args, for_each_event_sys_cb); +} + +static int num_events_cb(void *state, const char *sys_name __maybe_unused, + const char *evt_name __maybe_unused) +{ + size_t *count =3D state; + + (*count)++; + return 0; +} + +static int num_events_sys_cb(void *state, const char *sys_name) +{ + return tp_pmu__for_each_tp_event(sys_name, state, num_events_cb); +} + +size_t tp_pmu__num_events(struct perf_pmu *pmu __maybe_unused) +{ + size_t count =3D 0; + + tp_pmu__for_each_tp_sys(&count, num_events_sys_cb); + return count; +} + +bool tp_pmu__have_event(struct perf_pmu *pmu __maybe_unused, const char *n= ame) +{ + char *dup_name, *colon; + int id; + + colon =3D strchr(name, ':'); + if (colon =3D=3D NULL) + return false; + + dup_name =3D strdup(name); + if (!dup_name) + return false; + + colon =3D dup_name + (colon - name); + *colon =3D '\0'; + id =3D tp_pmu__id(dup_name, colon + 1); + free(dup_name); + return id >=3D 0; +} diff --git a/tools/perf/util/tp_pmu.h b/tools/perf/util/tp_pmu.h index 49537303bd73..30456bd6943d 100644 --- a/tools/perf/util/tp_pmu.h +++ b/tools/perf/util/tp_pmu.h @@ -2,6 +2,8 @@ #ifndef __TP_PMU_H #define __TP_PMU_H =20 +#include "pmu.h" + typedef int (*tp_sys_callback)(void *state, const char *sys_name); typedef int (*tp_event_callback)(void *state, const char *sys_name, const = char *evt_name); =20 @@ -9,4 +11,9 @@ int tp_pmu__id(const char *sys, const char *name); int tp_pmu__for_each_tp_event(const char *sys, void *state, tp_event_callb= ack cb); int tp_pmu__for_each_tp_sys(void *state, tp_sys_callback cb); =20 +bool perf_pmu__is_tracepoint(const struct perf_pmu *pmu); +int tp_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_ca= llback cb); +size_t tp_pmu__num_events(struct perf_pmu *pmu); +bool tp_pmu__have_event(struct perf_pmu *pmu, const char *name); + #endif /* __TP_PMU_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 0EF162586DA for ; Wed, 23 Jul 2025 23:23:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312985; cv=none; b=YLzqxkl5pfsryKHE1flQdoN0WyMSa++smDg6Wj4FTHQZrZ4a+d5Uz3lK0wSYmg8QCDG9DefcNhO51eeKovGyCojpcUUpmHH/0IUnh0CP1mgkotaP6cWm7d4ZHpcW0mWwfHrewcMYeYTNVt1/SZwsAIpFTlvgHQKlE2yKCJDSvH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312985; c=relaxed/simple; bh=ITH+WGnIDk5Syvv1E7DWgL8Gj28bdzS/hdWom7U5GlY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UktHeyAojGRH2VBv90dYh8q8UBFlSKNMcylG1dduUz7k8qvTDAKdL28IT2icG928OvMie+49/eD++UpjffIMtBHagTKRF9qV2HkxBYLlj8Nf84ws0pEvJRlF4+zGeTmv0hkrphgL4D7F9l2LlJIZw4Cf1GNR8bCHHa56AROW5/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=N+Qyj7MX; arc=none smtp.client-ip=209.85.210.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N+Qyj7MX" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-748f30d56d1so162538b3a.3 for ; Wed, 23 Jul 2025 16:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312983; x=1753917783; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PRH6HZKDKoaKwPBOk/dUfxHlkHKgENKAsBPm6OWaIbk=; b=N+Qyj7MXYz6fXP75H75woRUm6AIKp8mRpJ75x4bK47Bb7FpyhuSVFXotDo5PiyPwkG TqqHFHkFDfmRztF1jwwmbo9XnNp1ES2G0FxOAjQ/lu64hKzoQQf5GT0SCqg8ZZyEQKja FzoSXCUEaPWx7qHQeCUoKBDibERz5nh05Vk/2byCetilPjXo+2ju2wT17RjtTr7I9r/6 9YncYdz5OOP9+OraErMYADOpWQ6ePVS702OBqxpRYJCjBwhS+oZ73zP00c5QcjBaTcsZ 352lZFgx5P2ONpRpQy4iD35Zj9UHcnJ/qBeQ0TFh2bCAAyL1Dnxf43dAL1Cr8fFDoFdn ArCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312983; x=1753917783; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PRH6HZKDKoaKwPBOk/dUfxHlkHKgENKAsBPm6OWaIbk=; b=YoXbaevSxb9R2QI0Cdk6YvUsQ+qK5kF99sdvqM6eswLDFfcWFxU3XLys2pX5F8Dt0/ dQw5O50QuQz34TQ+/VfxSuT6F8fI81WKzEFclCcEpxHmhwBiMY6Q1Mp1x6uJIDRyJofO k+pr30rVHVIJCh1JUktPjxSY+g54Sm5lGic0YiKvxAdKnO+BI9oO4doDmOWuASi8zGwm PFX4P5fKF22cRiMMOItWYU6GSA9WTWXYl1hJYXtAMwmcXKe2JQqyoMuhpjwTs4bZnw4w It5rKreXEInkNJkVIcKmQciUd1gnbTnglX3XcWtmyye5kLVaRhWTwkibsZ0VnmCksnuI 7ljQ== X-Forwarded-Encrypted: i=1; AJvYcCVvoJEt7MgYBDiQ6jg/2oYyYqdkF4IEbGmzmedRieHwrkYcHE0ET+Evl86jN8ToWanPm9iS49QveKUCvb4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw29bdkWQOwePp66hWOmf0IZxIKdLchkZE3OURBSnX7/0YZbEBZ rE8vk/YtXgXDNWXQh7Ib3BX0/W5KXkObFiVaQ+/wI6dDqA/hxzSvoFxYkWsyj0doy/Bt8niI86y i2bsH2fOzaw== X-Google-Smtp-Source: AGHT+IEBQmFOYJpk7Vc0ebapw8BkruPXjwGsNAnot1LFhemYBwzPPibAyobqm5RTp2kHLpNHNEWBdbUQkP6O X-Received: from pftb15.prod.google.com ([2002:a05:6a00:2cf:b0:746:2d8f:cac1]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1a91:b0:757:51d:9dd9 with SMTP id d2e1a72fcca58-76035de66bdmr6476770b3a.17.1753312983098; Wed, 23 Jul 2025 16:23:03 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:07 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-7-irogers@google.com> Subject: [PATCH v8 06/16] perf list: Remove tracepoint printing code From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the tp_pmu can iterate and describe events remove the custom tracepoint printing logic, this avoids perf list showing the tracepoint events twice. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-list.c | 29 ++++++++--- tools/perf/util/print-events.c | 93 ---------------------------------- tools/perf/util/print-events.h | 2 - 3 files changed, 23 insertions(+), 101 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 674bb0afbf93..3a4061d02f6c 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -614,9 +614,18 @@ int cmd_list(int argc, const char **argv) for (i =3D 0; i < argc; ++i) { char *sep, *s; =20 - if (strcmp(argv[i], "tracepoint") =3D=3D 0) - print_tracepoint_events(&print_cb, ps); - else if (strcmp(argv[i], "hw") =3D=3D 0 || + if (strcmp(argv[i], "tracepoint") =3D=3D 0) { + char *old_pmu_glob =3D default_ps.pmu_glob; + + default_ps.pmu_glob =3D strdup("tracepoint"); + if (!default_ps.pmu_glob) { + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + zfree(&default_ps.pmu_glob); + default_ps.pmu_glob =3D old_pmu_glob; + } else if (strcmp(argv[i], "hw") =3D=3D 0 || strcmp(argv[i], "hardware") =3D=3D 0) print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE, event_symbols_hw, PERF_COUNT_HW_MAX); @@ -658,6 +667,7 @@ int cmd_list(int argc, const char **argv) #endif else if ((sep =3D strchr(argv[i], ':')) !=3D NULL) { char *old_pmu_glob =3D default_ps.pmu_glob; + char *old_event_glob =3D default_ps.event_glob; =20 default_ps.event_glob =3D strdup(argv[i]); if (!default_ps.event_glob) { @@ -665,13 +675,21 @@ int cmd_list(int argc, const char **argv) goto out; } =20 - print_tracepoint_events(&print_cb, ps); + default_ps.pmu_glob =3D strdup("tracepoint"); + if (!default_ps.pmu_glob) { + zfree(&default_ps.event_glob); + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + zfree(&default_ps.pmu_glob); + default_ps.pmu_glob =3D old_pmu_glob; print_sdt_events(&print_cb, ps); default_ps.metrics =3D true; default_ps.metricgroups =3D true; metricgroup__print(&print_cb, ps); zfree(&default_ps.event_glob); - default_ps.pmu_glob =3D old_pmu_glob; + default_ps.event_glob =3D old_event_glob; } else { if (asprintf(&s, "*%s*", argv[i]) < 0) { printf("Critical: Not enough memory! Trying to continue...\n"); @@ -682,7 +700,6 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX); print_hwcache_events(&print_cb, ps); perf_pmus__print_pmu_events(&print_cb, ps); - print_tracepoint_events(&print_cb, ps); print_sdt_events(&print_cb, ps); default_ps.metrics =3D true; default_ps.metricgroups =3D true; diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index c1a8708b55ab..3a5e5e7bae13 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -44,97 +44,6 @@ static const char * const event_type_descriptors[] =3D { "Hardware breakpoint", }; =20 -/* - * Print the events from /tracing/events - */ -void print_tracepoint_events(const struct print_callbacks *print_cb __mayb= e_unused, void *print_state __maybe_unused) -{ - char *events_path =3D get_tracing_file("events"); - int events_fd =3D open(events_path, O_PATH); - struct dirent **sys_namelist =3D NULL; - int sys_items; - - if (events_fd < 0) { - pr_err("Error: failed to open tracing events directory\n"); - pr_err("%s: %s\n", events_path, strerror(errno)); - return; - } - put_tracing_file(events_path); - - sys_items =3D tracing_events__scandir_alphasort(&sys_namelist); - - for (int i =3D 0; i < sys_items; i++) { - struct dirent *sys_dirent =3D sys_namelist[i]; - struct dirent **evt_namelist =3D NULL; - int dir_fd; - int evt_items; - - if (sys_dirent->d_type !=3D DT_DIR || - !strcmp(sys_dirent->d_name, ".") || - !strcmp(sys_dirent->d_name, "..")) - goto next_sys; - - dir_fd =3D openat(events_fd, sys_dirent->d_name, O_PATH); - if (dir_fd < 0) - goto next_sys; - - evt_items =3D scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NU= LL, alphasort); - for (int j =3D 0; j < evt_items; j++) { - /* - * Buffer sized at twice the max filename length + 1 - * separator + 1 \0 terminator. - */ - char buf[NAME_MAX * 2 + 2]; - /* 16 possible hex digits and 22 other characters and \0. */ - char encoding[16 + 22]; - struct dirent *evt_dirent =3D evt_namelist[j]; - struct io id; - __u64 config; - - if (evt_dirent->d_type !=3D DT_DIR || - !strcmp(evt_dirent->d_name, ".") || - !strcmp(evt_dirent->d_name, "..")) - goto next_evt; - - snprintf(buf, sizeof(buf), "%s/id", evt_dirent->d_name); - io__init(&id, openat(dir_fd, buf, O_RDONLY), buf, sizeof(buf)); - - if (id.fd < 0) - goto next_evt; - - if (io__get_dec(&id, &config) < 0) { - close(id.fd); - goto next_evt; - } - close(id.fd); - - snprintf(buf, sizeof(buf), "%s:%s", - sys_dirent->d_name, evt_dirent->d_name); - snprintf(encoding, sizeof(encoding), "tracepoint/config=3D0x%llx/", con= fig); - print_cb->print_event(print_state, - /*topic=3D*/NULL, - /*pmu_name=3D*/NULL, /* really "tracepoint" */ - /*event_name=3D*/buf, - /*event_alias=3D*/NULL, - /*scale_unit=3D*/NULL, - /*deprecated=3D*/false, - "Tracepoint event", - /*desc=3D*/NULL, - /*long_desc=3D*/NULL, - encoding); -next_evt: - free(evt_namelist[j]); - } - close(dir_fd); - free(evt_namelist); -next_sys: - free(sys_namelist[i]); - } - - free(sys_namelist); - close(events_fd); -} - void print_sdt_events(const struct print_callbacks *print_cb, void *print_= state) { struct strlist *bidlist, *sdtlist; @@ -552,8 +461,6 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) /*long_desc=3D*/NULL, /*encoding_desc=3D*/NULL); =20 - print_tracepoint_events(print_cb, print_state); - print_sdt_events(print_cb, print_state); =20 metricgroup__print(print_cb, print_state); diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index 48682e2d166d..4d95b8257e23 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -37,8 +37,6 @@ void print_sdt_events(const struct print_callbacks *print= _cb, void *print_state) void print_symbol_events(const struct print_callbacks *print_cb, void *pri= nt_state, unsigned int type, const struct event_symbol *syms, unsigned int max); - -void print_tracepoint_events(const struct print_callbacks *print_cb, void = *print_state); void metricgroup__print(const struct print_callbacks *print_cb, void *prin= t_state); bool is_event_supported(u8 type, u64 config); =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 34AE92749CA for ; Wed, 23 Jul 2025 23:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312990; cv=none; b=ZYKRKTGv7pVkjC1iJYIqQ49ERwPS+v1MlcNN6hOi4Xv2MQmP0oltH6MampVH3pNp1vOlpbCfMlNHUaHsttI6amerZCDL3O4uo1fZAkBpQC/vP0bnAROWiTpyYutrBSn1JOLXAKabjQAndYnqgKb0psYJGbnDuaeKznwU2/7CW2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312990; c=relaxed/simple; bh=IsJcOq3wGalG+joiiKDrUg/a4tf1pjR+BiJdR4fqGv4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l9vFXCIKistwkpU5QUplK4TBPZBslp05QJb/ZevrsZoZ/0yGm0uGX7wa9IYVW240iQlPOv8CP67dXFYZv0ivXaBrqTAtmLIr08oTMQ3gwYg4HW+7wMRM9sV5xFKRTwGsPLxBLfE7DUjp2uOR7paWLTNHEZDNidtIPvu1T8l+uJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=X90Os1hc; arc=none smtp.client-ip=209.85.216.74 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X90Os1hc" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-31215090074so499409a91.0 for ; Wed, 23 Jul 2025 16:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312988; x=1753917788; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oVItISMGBRXYY23ho5sLW0N44o7z13JmOf4xsnODe64=; b=X90Os1hchJtIRN/I4VgolNtj2knBOnCX7qy2wqeTBePfKZZG/n1Jk8XnXnA5ZEQbKY Raoq903MVAnt9QmvoSP2hcd8o4lBbCiqYXBVHbe2hTRmTIf803u3CJLg1H9LR0Lbx+WL vv+RAaJ4P6UxKoIOSykmwnYGrhJGbbybfbCvyzw2GFDBzH6rxsmd2HRxtLx/JqTS0d+u 3jjNtvugDZF9DZDsQim4BV79bnR2A0Y6iL1oAuHtm3hk/M5RhKJ/biN78mTq0JnKnAhZ 85gOvMRNL36lr3ccnw3qJ6gyplL8QLIC7V42h6El1t5DqHcggv/PXa+TrZ6S9dHrb8xU mDxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312988; x=1753917788; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oVItISMGBRXYY23ho5sLW0N44o7z13JmOf4xsnODe64=; b=eTwcYWKsppWB/bwE8M1g97lJuccqly4MgBwS10Zbdwb0xxxQA5dkWwWHnSDQ70ruW1 y3/HdxyEHgBb4ccsTpOFe0Z9zpfEIX/3B3i++tQh2P9G1que+1+sb71hP5ZFbjO6Mpge /5Ct/o9Ndpo+vKrLtMlUqpc+iljX96rLGWqtT1lsxvxtwktnQGtYaGvXBJfzKu28XrrV GifTCDuoOtxMgVL8qd2qZhg4rhkOSr2TOu9DG9ezORt8LqOIrb2OJYQ/6aJtuiDbqS3d jDXewC0d+gnycpnZGAyqQFC7RsPsDzHyhgVwqi9kiE91kyDwZ/7iT1SxMFNDCpLnGn9L gyfw== X-Forwarded-Encrypted: i=1; AJvYcCW1ZcA5u46YFvcvcLyjsQS+GVk8/LZTxFQnFHe7PI8uEz8gjjNmH1R4nHW3zl+hhS4DE4iCNu/92MjqGOs=@vger.kernel.org X-Gm-Message-State: AOJu0YyYyBAO6MO9aqmYJvG/pBctgXt5v4uCezNUf34uN9QoWsntIHh7 Ws791ouKL2QVw8z2Tw92yMhjeiJ8JDFZs5pxLvVBaiOnIg+KHXlBOPvh8dCmGoCCnMJxEyoGV7L ddfiGIT/K3w== X-Google-Smtp-Source: AGHT+IFcDcN5IzqZxloQ0osGicyNu7AlkEa73gtmuy+1tLDPEMcAP8QkQFM73JpvcXCs7KLVVeNAZNHAxlyb X-Received: from pjbse12.prod.google.com ([2002:a17:90b:518c:b0:31c:2fe4:33b5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:184d:b0:313:1769:eb49 with SMTP id 98e67ed59e1d1-31e50735c36mr7658032a91.8.1753312988654; Wed, 23 Jul 2025 16:23:08 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:08 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-8-irogers@google.com> Subject: [PATCH v8 07/16] perf list: Skip ABI PMUs when printing pmu values From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid printing tracepoint, legacy and software events when listing for the pmu option. Add the PMU type to the print_event callbacks to ease detection. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-list.c | 17 +++++++++++++---- tools/perf/util/pfm.c | 2 ++ tools/perf/util/pmus.c | 2 ++ tools/perf/util/print-events.c | 5 +++++ tools/perf/util/print-events.h | 2 +- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 3a4061d02f6c..caf42276bd0f 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -58,6 +58,8 @@ struct print_state { bool metrics; /** @metricgroups: Controls printing of metric and metric groups. */ bool metricgroups; + /** @exclude_abi: Exclude PMUs with types less than PERF_TYPE_MAX except = PERF_TYPE_RAW. */ + bool exclude_abi; /** @last_topic: The last printed event topic. */ char *last_topic; /** @last_metricgroups: The last printed metric group. */ @@ -113,7 +115,8 @@ static void wordwrap(FILE *fp, const char *s, int start= , int max, int corr) } } =20 -static void default_print_event(void *ps, const char *topic, const char *p= mu_name, +static void default_print_event(void *ps, const char *topic, + const char *pmu_name, u32 pmu_type, const char *event_name, const char *event_alias, const char *scale_unit __maybe_unused, bool deprecated, const char *event_type_desc, @@ -130,6 +133,9 @@ static void default_print_event(void *ps, const char *t= opic, const char *pmu_nam if (print_state->pmu_glob && pmu_name && !strglobmatch(pmu_name, print_st= ate->pmu_glob)) return; =20 + if (print_state->exclude_abi && pmu_type < PERF_TYPE_MAX && pmu_type !=3D= PERF_TYPE_RAW) + return; + if (print_state->event_glob && (!event_name || !strglobmatch(event_name, print_state->event_glob)) && (!event_alias || !strglobmatch(event_alias, print_state->event_glob))= && @@ -354,7 +360,8 @@ static void fix_escape_fprintf(FILE *fp, struct strbuf = *buf, const char *fmt, .. fputs(buf->buf, fp); } =20 -static void json_print_event(void *ps, const char *topic, const char *pmu_= name, +static void json_print_event(void *ps, const char *topic, + const char *pmu_name, u32 pmu_type __maybe_unused, const char *event_name, const char *event_alias, const char *scale_unit, bool deprecated, const char *event_type_desc, @@ -647,9 +654,11 @@ int cmd_list(int argc, const char **argv) } else if (strcmp(argv[i], "cache") =3D=3D 0 || strcmp(argv[i], "hwcache") =3D=3D 0) print_hwcache_events(&print_cb, ps); - else if (strcmp(argv[i], "pmu") =3D=3D 0) + else if (strcmp(argv[i], "pmu") =3D=3D 0) { + default_ps.exclude_abi =3D true; perf_pmus__print_pmu_events(&print_cb, ps); - else if (strcmp(argv[i], "sdt") =3D=3D 0) + default_ps.exclude_abi =3D false; + } else if (strcmp(argv[i], "sdt") =3D=3D 0) print_sdt_events(&print_cb, ps); else if (strcmp(argv[i], "metric") =3D=3D 0 || strcmp(argv[i], "metrics"= ) =3D=3D 0) { default_ps.metricgroups =3D false; diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c index 0dacc133ed39..15fc3898ec83 100644 --- a/tools/perf/util/pfm.c +++ b/tools/perf/util/pfm.c @@ -234,6 +234,7 @@ print_libpfm_event(const struct print_callbacks *print_= cb, void *print_state, =20 if (is_libpfm_event_supported(name, cpus, threads)) { print_cb->print_event(print_state, topic, pinfo->name, + /*pmu_type=3D*/PERF_TYPE_RAW, name, info->equiv, /*scale_unit=3D*/NULL, /*deprecated=3D*/NULL, "PFM event", @@ -269,6 +270,7 @@ print_libpfm_event(const struct print_callbacks *print_= cb, void *print_state, print_cb->print_event(print_state, topic, pinfo->name, + /*pmu_type=3D*/PERF_TYPE_RAW, name, /*alias=3D*/NULL, /*scale_unit=3D*/NULL, /*deprecated=3D*/NULL, "PFM event", diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 409b909cfa02..004f5f0c621f 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -645,6 +645,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p print_cb->print_event(print_state, aliases[j].topic, aliases[j].pmu_name, + aliases[j].pmu->type, aliases[j].name, aliases[j].alias, aliases[j].scale_unit, @@ -749,6 +750,7 @@ void perf_pmus__print_raw_pmu_events(const struct print= _callbacks *print_cb, voi print_cb->print_event(print_state, /*topic=3D*/NULL, /*pmu_name=3D*/NULL, + pmu->type, format_args.short_string.buf, /*event_alias=3D*/NULL, /*scale_unit=3D*/NULL, diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 3a5e5e7bae13..4153124a9948 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -121,6 +121,7 @@ void print_sdt_events(const struct print_callbacks *pri= nt_cb, void *print_state) print_cb->print_event(print_state, /*topic=3D*/NULL, /*pmu_name=3D*/NULL, + PERF_TYPE_TRACEPOINT, evt_name ?: sdt_name->s, /*event_alias=3D*/NULL, /*deprecated=3D*/false, @@ -222,6 +223,7 @@ int print_hwcache_events(const struct print_callbacks *= print_cb, void *print_sta print_cb->print_event(print_state, "cache", pmu->name, + pmu->type, name, alias_name, /*scale_unit=3D*/NULL, @@ -278,6 +280,7 @@ void print_symbol_events(const struct print_callbacks *= print_cb, void *print_sta print_cb->print_event(print_state, /*topic=3D*/NULL, /*pmu_name=3D*/NULL, + type, nd->s, alias, /*scale_unit=3D*/NULL, @@ -438,6 +441,7 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) print_cb->print_event(print_state, /*topic=3D*/NULL, /*pmu_name=3D*/NULL, + PERF_TYPE_RAW, "rNNN", /*event_alias=3D*/NULL, /*scale_unit=3D*/NULL, @@ -452,6 +456,7 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) print_cb->print_event(print_state, /*topic=3D*/NULL, /*pmu_name=3D*/NULL, + PERF_TYPE_BREAKPOINT, "mem:[/len][:access]", /*scale_unit=3D*/NULL, /*event_alias=3D*/NULL, diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index 4d95b8257e23..d6ba384f0c66 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -12,7 +12,7 @@ struct print_callbacks { void (*print_start)(void *print_state); void (*print_end)(void *print_state); void (*print_event)(void *print_state, const char *topic, - const char *pmu_name, + const char *pmu_name, u32 pmu_type, const char *event_name, const char *event_alias, const char *scale_unit, bool deprecated, const char *event_type_desc, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 57F372749D1 for ; Wed, 23 Jul 2025 23:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312992; cv=none; b=NAU9xZ8hPcLGdfrZGQKFZUikzxLP82FLNsNT9PhLF6sXk3mRlgm4LSBkZ69c1twfe7Ioq0BYnUhe+iz7DWctVL0gqSEfjaIKNEd686u23qwOzbC+RCn4fE7Z1yHg1WfjHxNoBT8ulVsJkTKxdWirB2y6iFdQNhGZ51lEgqzSMHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312992; c=relaxed/simple; bh=Vo6tbVjdJL4lzlTuKJJDRAwcz+98CMZF7SiPUqEkxLQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pf1/fjHd7zc6qwjD4NqS45L3rlqGOiA+j673CokfNYdaUdfuRuZosNeFmB/YdinuU5ofeCMCMzBDZgnZLg62qttW2hHavpAL+y3AqnYPQ2gGxGtmTb5o1Yqz/rOP7/ff3JIkhaK2sMZHDo38jWR9iXdwm6a4d7KDlKvzM/HAzj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HfMyHg8A; arc=none smtp.client-ip=209.85.215.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HfMyHg8A" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b1ffc678adfso287553a12.0 for ; Wed, 23 Jul 2025 16:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312991; x=1753917791; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MrcDIPxORzR9yt+tgwZuFcuDMoj49Q8f2loh+BQfr6I=; b=HfMyHg8AnryrejuqlYZ3nvVg4UrDCPjxb0+3bYZZIZEJJJWcCj6LH8uy4cs47KrBx0 TthGBXS+dEUx1uwMUr9EFofSMZo4XIIN6meDTY0Bs2BglwJlgZITByy9vcSPJUJbU6Zb ekURDrV76YfSY+wQslBS14bIabRg5br15wQ5IyV3p+RAn/35qoe/YuoTYZaoD+hTCG6C 3vEA7rla9KgO3EFWGlS7lJlzc84tXfGVxoHZcYeM62Dnz2wKWyNwrQqkX/0Je4JH12K/ KAeSZ6Yijb4kaYi9mre4IU7JpgbRvYZknNMPMjDg8HkTsHAInFw0ONwKHjhUua+++63f +Dew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312991; x=1753917791; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MrcDIPxORzR9yt+tgwZuFcuDMoj49Q8f2loh+BQfr6I=; b=unQMMpPKWj42RdHthcsvgk+VmuPQQPaiajcPJnuIPjFxnIb+9Y8iOZZbMclfIs9vW6 kYfN+Ln3BqydhkuSJRDW9FGlzg7rnJdfF2E9jl16eZHJZYh37AlYUww8wG0CMMk3nkGN bGqsaNckwO/OE7rlOslMjPSEACl82M+nI19SiuwI7hO7g8X78lr1iDc13CK5Auujwwwj crI1Z8wCwvAfHaQWo/L/Dmw/I4qHOh54wffcls8RG3P0Gem2vmW9Q0UAiKca6yXorSci B4odGLQQjQjNRNELXkqHdBHX4041Qq6DrEGq18uCzFGD4Q1j/cOPECpZ9dLIHQ3abcFr uuEg== X-Forwarded-Encrypted: i=1; AJvYcCUKF7ScPaTyf9Ya5I7KXVW/IXvB7go1+D6SlH++IRvzgLvLwPZ7jKHUJy9QLqSotbK2kuc6DRYpBHP28cM=@vger.kernel.org X-Gm-Message-State: AOJu0YxnVltTIjtI4fc17sK3LdBYs9+hZK1Hg1AvTpA0xVtCiadqYkXo /2LAi9NTcU9UWG36zu5glG83bVLyc+p6/OFghnDpXDp2f7chCxuOF7wcIQGtcOxfpLj4io+3g8n /RnlMnRc1gQ== X-Google-Smtp-Source: AGHT+IFDE+kBOJYEVOILaCtT1VmDeMx0V3Sfa2nJ010p8G2+kgJm6eS0vfB2ty7mGIzMy5/ZPafr7Cv05stm X-Received: from pjvf3.prod.google.com ([2002:a17:90a:da83:b0:312:ea08:fa64]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5483:b0:313:d79d:87eb with SMTP id 98e67ed59e1d1-31e50800129mr7366836a91.35.1753312990676; Wed, 23 Jul 2025 16:23:10 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:09 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-9-irogers@google.com> Subject: [PATCH v8 08/16] perf python: Improve the tracepoint function if no libtraceevent From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The tracepoint function just returns the tracepoint id, this doesn't require libtraceevent which is only used for parsing the event format data. Implement the function using the id function in tp_pmu. No current code in perf is using this, the previous code migrated to perf.parse_events, but it feels good to have less ifdef HAVE_LIBTRACEEVENT. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 3affde0ad15a..9c9972d77d1e 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -18,6 +18,7 @@ #include "record.h" #include "strbuf.h" #include "thread_map.h" +#include "tp_pmu.h" #include "trace-event.h" #include "metricgroup.h" #include "mmap.h" @@ -1544,10 +1545,6 @@ static const struct perf_constant perf__constants[] = =3D { static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel, PyObject *args, PyObject *kwargs) { -#ifndef HAVE_LIBTRACEEVENT - return NULL; -#else - struct tep_event *tp_format; static char *kwlist[] =3D { "sys", "name", NULL }; char *sys =3D NULL; char *name =3D NULL; @@ -1556,12 +1553,7 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel = *pevsel, &sys, &name)) return NULL; =20 - tp_format =3D trace_event__tp_format(sys, name); - if (IS_ERR(tp_format)) - return PyLong_FromLong(-1); - - return PyLong_FromLong(tp_format->id); -#endif // HAVE_LIBTRACEEVENT + return PyLong_FromLong(tp_pmu__id(sys, name)); } =20 static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel) --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 C1E3E273D6E for ; Wed, 23 Jul 2025 23:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312998; cv=none; b=g/OMXl3PngjfQH+0wyKjylfYWeSydHujF4f8SAiALoDbVFI7d7tBrHfMf9zGDv2IghPaxhgT60xoQHsxK+sd7fQOpG6r/FXysgk3C+R6TMGsgp/Gin26Hab8AQM12SQPqsIS/Q7BJy2LY3HPCsRfrN5QZPl3skuS7xwFu+daliM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753312998; c=relaxed/simple; bh=Z/+V08XVG6YryTmJn6c7T1URaUgSv2I6HyIn21jzYQ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FUB6I1SHn/6pOyKWYmGnKI6ILQGFF9Q5Le6d1AyA7tEiWzVpW7hHogmeTDyV5KaEQK22qbSKv64Igwpw0RqgVMg7VsTVbCRM833PGMTQ8uf8r5o7kCNjg0t63vG8aK7bEJ7Z71BckAszBUdIj6irj3Elwg16XtYdD9/UM8Xp5gc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=w8/kJ6dh; arc=none smtp.client-ip=209.85.216.73 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="w8/kJ6dh" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-313d6d671ffso364712a91.2 for ; Wed, 23 Jul 2025 16:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312996; x=1753917796; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cdjlRlqcaaWl92SvJhsMHCXMRGPAo2TCVGBK4bniCoY=; b=w8/kJ6dhNhGcsIgAIcto62ozQ9u2ovlOkV7fa25qPOTq9XFOfkJboq06BBLxamp0TT tCDLG7WVukfQL9J6Tp46DosVWBpuwacDtR1G9TYL8L78i6+G07BgGNaMmXrluNzDymZ2 HvqH306DJod13Kwj4SHOFjrmGL/C0Dy5ThnipoxewHOCg0NC2olV8YJsLtDULxOOdRd4 ky3g2/LVgHpbe1Pm9hi3Skv3jHWZ/qgf+hUoVA59VdwWXyt7BC5uCTVyXLolvqCXxKwU AVnil80kn1aA+kYcIu/Ygtt3L6NuvGvv/m8b0rJ0V2hEXmLuTajUy0iOmPk1bsw/8odp zb9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312996; x=1753917796; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cdjlRlqcaaWl92SvJhsMHCXMRGPAo2TCVGBK4bniCoY=; b=ZWqHuUl24tow1vEgnlIKIW+7W3f1VwygLpKoiyJX6OsvIrGz2vSG1bO40YGV+312qq FVMO3jH5olba5bZzK6FHcVWnXqEL5ViFmtna6ZgN4usZg4Ojs/UpsDMytX4kgZkrNrex pvuQuPgmLSFqGyR6ys7IHxG4x3tgtMXdie7HxCKjYuOEdUTn1LinkTIhz9UrquLQttAH 8rVhMqbAZwkg8p7jYDFvXeZ8noEZJmyxrEb63nkDTvUTrISR1+tmREBOdGkD2odrwyVq 2V9YRNWDeT5QXqWKwgx3gsYIJY3ttomjcNpERZnvOdKCFTrRr5tzIwncTwe6aSCfDZBi TJ9g== X-Forwarded-Encrypted: i=1; AJvYcCVcdMG5wiWqzTH5U0/xc3oHNTB+TrTsOXIZjRQrpyX+PwCkT0CI8PqaW1wjK9pJlkmi1bCVVVgf+TZlhio=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1CP5lKItpzh/o9qbQrLly2H1AftedJjkrZ0Ue/1QwSW0m1Kx2 EeCPN2S+18jp9Y2FbxMoPtG9PHPxTJiXTuSQsWl3z3J6zVkBCNK1ZT6QgdQjKm1tkreq60j5UdU 65XNJnpqIAQ== X-Google-Smtp-Source: AGHT+IHT6Yev26RC90YfzMfnzP3PbAYr9CxK1jbMxB7Z8IIbdYP59V9Rv/RmXqz2mIPJoxn4nStyu/gZufvF X-Received: from pjvf6.prod.google.com ([2002:a17:90a:da86:b0:311:c197:70a4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2e0d:b0:31e:3bbc:e9e6 with SMTP id 98e67ed59e1d1-31e507e61a5mr7085372a91.19.1753312996032; Wed, 23 Jul 2025 16:23:16 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:10 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-10-irogers@google.com> Subject: [PATCH v8 09/16] perf python: Add basic PMU abstraction and pmus sequence From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an ability to iterate over PMUs and a basic PMU type then can just show the PMU's name. An example usage: ``` $ python Python 3.12.9 (main, Feb 5 2025, 01:31:18) [GCC 14.2.0] on linux >>> import perf >>> list(perf.pmus()) [pmu(cpu), pmu(breakpoint), pmu(cstate_core), pmu(cstate_pkg), pmu(hwmon_acpitz), pmu(hwmon_ac), pmu(hwmon_bat0), pmu(hwmon_coretemp), pmu(hwmon_iwlwifi_1), pmu(hwmon_nvme), pmu(hwmon_thinkpad), pmu(hwmon_ucsi_source_psy_usbc000_0), pmu(hwmon_ucsi_source_psy_usbc000_0), pmu(i915), pmu(intel_bts), pmu(intel_pt), pmu(kprobe), pmu(msr), pmu(power), pmu(software), pmu(tool), pmu(tracepoint), pmu(uncore_arb), pmu(uncore_cbox_0), pmu(uncore_cbox_1), pmu(uncore_cbox_2), pmu(uncore_cbox_3), pmu(uncore_cbox_4), pmu(uncore_cbox_5), pmu(uncore_cbox_6), pmu(uncore_cbox_7), pmu(uncore_clock), pmu(uncore_imc_free_running_0), pmu(uncore_imc_free_running_1), pmu(uprobe)] ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 140 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 9c9972d77d1e..ddcb5d40ff14 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -639,6 +639,138 @@ static int pyrf_thread_map__setup_types(void) return PyType_Ready(&pyrf_thread_map__type); } =20 +/** + * A python wrapper for perf_pmus that are globally owned by the pmus.c co= de. + */ +struct pyrf_pmu { + PyObject_HEAD + + struct perf_pmu *pmu; +}; + +static void pyrf_pmu__delete(struct pyrf_pmu *ppmu) +{ + Py_TYPE(ppmu)->tp_free((PyObject *)ppmu); +} + +static PyObject *pyrf_pmu__name(PyObject *self) +{ + struct pyrf_pmu *ppmu =3D (void *)self; + + return PyUnicode_FromString(ppmu->pmu->name); +} + +static PyObject *pyrf_pmu__repr(PyObject *self) +{ + struct pyrf_pmu *ppmu =3D (void *)self; + + return PyUnicode_FromFormat("pmu(%s)", ppmu->pmu->name); +} + +static const char pyrf_pmu__doc[] =3D PyDoc_STR("perf Performance Monitori= ng Unit (PMU) object."); + +static PyMethodDef pyrf_pmu__methods[] =3D { + { + .ml_name =3D "name", + .ml_meth =3D (PyCFunction)pyrf_pmu__name, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("Name of the PMU including suffixes.") + }, + { .ml_name =3D NULL, } +}; + +/** The python type for a perf.pmu. */ +static PyTypeObject pyrf_pmu__type =3D { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name =3D "perf.pmu", + .tp_basicsize =3D sizeof(struct pyrf_pmu), + .tp_dealloc =3D (destructor)pyrf_pmu__delete, + .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_doc =3D pyrf_pmu__doc, + .tp_methods =3D pyrf_pmu__methods, + .tp_str =3D pyrf_pmu__name, + .tp_repr =3D pyrf_pmu__repr, +}; + +static int pyrf_pmu__setup_types(void) +{ + pyrf_pmu__type.tp_new =3D PyType_GenericNew; + return PyType_Ready(&pyrf_pmu__type); +} + + +/** A python iterator for pmus that has no equivalent in the C code. */ +struct pyrf_pmu_iterator { + PyObject_HEAD + struct perf_pmu *pmu; +}; + +static void pyrf_pmu_iterator__dealloc(struct pyrf_pmu_iterator *self) +{ + Py_TYPE(self)->tp_free((PyObject *) self); +} + +static PyObject *pyrf_pmu_iterator__new(PyTypeObject *type, PyObject *args= __maybe_unused, + PyObject *kwds __maybe_unused) +{ + struct pyrf_pmu_iterator *itr =3D (void *)type->tp_alloc(type, 0); + + if (itr !=3D NULL) + itr->pmu =3D perf_pmus__scan(/*pmu=3D*/NULL); + + return (PyObject *) itr; +} + +static PyObject *pyrf_pmu_iterator__iter(PyObject *self) +{ + Py_INCREF(self); + return self; +} + +static PyObject *pyrf_pmu_iterator__iternext(PyObject *self) +{ + struct pyrf_pmu_iterator *itr =3D (void *)self; + struct pyrf_pmu *ppmu; + + if (itr->pmu =3D=3D NULL) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + // Create object to return. + ppmu =3D PyObject_New(struct pyrf_pmu, &pyrf_pmu__type); + if (ppmu) { + ppmu->pmu =3D itr->pmu; + // Advance iterator. + itr->pmu =3D perf_pmus__scan(itr->pmu); + } + return (PyObject *)ppmu; +} + +/** The python type for the PMU iterator. */ +static PyTypeObject pyrf_pmu_iterator__type =3D { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name =3D "pmus.iterator", + .tp_doc =3D "Iterator for the pmus string sequence.", + .tp_basicsize =3D sizeof(struct pyrf_pmu_iterator), + .tp_itemsize =3D 0, + .tp_flags =3D Py_TPFLAGS_DEFAULT, + .tp_new =3D pyrf_pmu_iterator__new, + .tp_dealloc =3D (destructor) pyrf_pmu_iterator__dealloc, + .tp_iter =3D pyrf_pmu_iterator__iter, + .tp_iternext =3D pyrf_pmu_iterator__iternext, +}; + +static int pyrf_pmu_iterator__setup_types(void) +{ + return PyType_Ready(&pyrf_pmu_iterator__type); +} + +static PyObject *pyrf__pmus(PyObject *self, PyObject *args) +{ + // Calling the class creates an instance of the iterator. + return PyObject_CallObject((PyObject *) &pyrf_pmu_iterator__type, /*args= =3D*/NULL); +} + struct pyrf_counts_values { PyObject_HEAD =20 @@ -1691,6 +1823,12 @@ static PyMethodDef perf__methods[] =3D { .ml_flags =3D METH_VARARGS, .ml_doc =3D PyDoc_STR("Parse a string of events and return an evlist.") }, + { + .ml_name =3D "pmus", + .ml_meth =3D (PyCFunction) pyrf__pmus, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("Returns a sequence of pmus.") + }, { .ml_name =3D NULL, } }; =20 @@ -1718,6 +1856,8 @@ PyMODINIT_FUNC PyInit_perf(void) pyrf_evsel__setup_types() < 0 || pyrf_thread_map__setup_types() < 0 || pyrf_cpu_map__setup_types() < 0 || + pyrf_pmu_iterator__setup_types() < 0 || + pyrf_pmu__setup_types() < 0 || pyrf_counts_values__setup_types() < 0) return module; =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 02754274FC8 for ; Wed, 23 Jul 2025 23:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313000; cv=none; b=YcP/D11FfbrVB7HTvNA1xGq0tYUPULsovW2I1jfDo4hI3U1MwiiJHI0V3LnCBUhq2bus8KF73kwj9nz4Q5ZIFmcaow9D/p7t5Hom06jqEWhopHO8BJERp3xoK0uWZ0QmPhWIzyWt/fVqfc/YPqgKef7DzjOnLQBX5s9Ak4XfDi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313000; c=relaxed/simple; bh=7W2OwNvCKl5AjDEGsRcKdkWux7FNfF8gWFpHCiwbOTw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hGSHQX5Ogncd63uJpKzeH8mi3KaVUvLhTJG+DCdHkOV135HQtT5jIq/A4iYcw1TqfY/+EIisgdvRsK0+RGeypKUrEYfJaqIsUNZ/rx6UbAKUgAmtGeoaZsFOhtmK0yO7nBa9g7e+jQC3SAy38pNs/ECahJC+cMWObbCH5GEqmBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ByWB/+m+; arc=none smtp.client-ip=209.85.215.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ByWB/+m+" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b34abbcdcf3so258947a12.1 for ; Wed, 23 Jul 2025 16:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753312998; x=1753917798; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vQX6HKbYgS42p2L0uks7UqDqcpdHxytIA9YuMYrF0ZQ=; b=ByWB/+m+3e0EfRFVLROa9m97JajdscK1t9e7EXArnPMjQnq47QvHKmYMJMgVPolZu6 8tb0oFfrHt8Rz9TFbwp3cEKqA1OAShxHc0z97OS1NkWZ0PCIJJNhj+vmolLDh6VgZbY/ upO+Yeuy8WTJlcFNqzO8hMWh/NiW33UVt6GfwdJkxkpetbxzDlNsXZC7YGkun5vKW5Ek AY5mcNEfurd1F9vbGdPFlG+b/UPmqFCaicuWUd99/I0vat3zK6HZE9sfFBMQsrb2XHe3 qVpi0hOiOYdtlheoSBNR76Je8RkYx9NN007BN4C8ygj7TZPh8dQ96pUa4Tx87XXoXgHH fAlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753312998; x=1753917798; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vQX6HKbYgS42p2L0uks7UqDqcpdHxytIA9YuMYrF0ZQ=; b=t00LoUjAVfVFjg2qcMz5OYBN0fTWvh1CaDWFInVJJxm4ZrKeqslKJvdg+BaaO0o640 Y6HoVaw/wWKGWCUCGcsftcK3YwZltlC6OJ8E+5mO5xULtu/SDf8r1P7e5c2lcCNTaUP5 +Jfhi0nLefVEW8cvrCdPZG24ltU3RUATa8pYQXTw9ab1A7aONIdj0Im3hFQxqtSNCzU5 If1J95mqxWr74UdSVH5jNgoRY0ozLkN9uoaSDUgSgp6zXRTg6GzaI3vJf2aLsTNFRudh VwvzJcG0S4s+cJk2WuKhA0ANI+Bf/NeLvuNex4XWCVFIpWob12t6ZH23E/SZs5a/Akct ExFQ== X-Forwarded-Encrypted: i=1; AJvYcCU/dxzf5baUGwOZqXlFZrLzS/SB8zQAHSI0EvdEPiZnAK16lMRauao9JCzhzsTRw5sljcVAAkWle9SDnf8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywl8NdEiDd2jBnHS0kbGVn01NRuFM55SiAjB9oX4I4GZFNYU6cT +YKEE9jVzNalZrU88J6q1IbUXmI6u+a7MBSQLcyWsq9Huc0N9xrP0LFWOOV07kyeYWuCT5ABIb6 qlek3wzBzGw== X-Google-Smtp-Source: AGHT+IGPQ7QbY0ypIIaymwMZ5McrQ2xp90w71N7CCBFAjq64ioImo5NRcvUbrvOuvM8F7hqeZbUr7vGKhlz0 X-Received: from pga3.prod.google.com ([2002:a05:6a02:4f83:b0:b2d:aac5:e874]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:99a2:b0:238:3f54:78f1 with SMTP id adf61e73a8af0-23d4916e98dmr7794433637.43.1753312998305; Wed, 23 Jul 2025 16:23:18 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:11 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-11-irogers@google.com> Subject: [PATCH v8 10/16] perf python: Add function returning dictionary of all events on a PMU From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow all events on a PMU to be gathered, similar to how perf list gathers event information. An example usage: ``` $ python Python 3.12.9 (main, Feb 5 2025, 01:31:18) [GCC 14.2.0] on linux >>> import perf >>> for pmu in perf.pmus(): ... print(pmu.events()) ... [{'name': 'mem_load_retired.l3_hit', 'desc': 'Retired load instructions... ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index ddcb5d40ff14..d49b4401ab7e 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -660,6 +660,71 @@ static PyObject *pyrf_pmu__name(PyObject *self) return PyUnicode_FromString(ppmu->pmu->name); } =20 +static bool add_to_dict(PyObject *dict, const char *key, const char *value) +{ + PyObject *pkey, *pvalue; + bool ret; + + if (value =3D=3D NULL) + return true; + + pkey =3D PyUnicode_FromString(key); + pvalue =3D PyUnicode_FromString(value); + + ret =3D pkey && pvalue && PyDict_SetItem(dict, pkey, pvalue) =3D=3D 0; + Py_XDECREF(pkey); + Py_XDECREF(pvalue); + return ret; +} + +static int pyrf_pmu__events_cb(void *state, struct pmu_event_info *info) +{ + PyObject *py_list =3D state; + PyObject *dict =3D PyDict_New(); + + if (!dict) + return -ENOMEM; + + if (!add_to_dict(dict, "name", info->name) || + !add_to_dict(dict, "alias", info->alias) || + !add_to_dict(dict, "scale_unit", info->scale_unit) || + !add_to_dict(dict, "desc", info->desc) || + !add_to_dict(dict, "long_desc", info->long_desc) || + !add_to_dict(dict, "encoding_desc", info->encoding_desc) || + !add_to_dict(dict, "topic", info->topic) || + !add_to_dict(dict, "event_type_desc", info->event_type_desc) || + !add_to_dict(dict, "str", info->str) || + !add_to_dict(dict, "deprecated", info->deprecated ? "deprecated" : NU= LL) || + PyList_Append(py_list, dict) !=3D 0) { + Py_DECREF(dict); + return -ENOMEM; + } + Py_DECREF(dict); + return 0; +} + +static PyObject *pyrf_pmu__events(PyObject *self) +{ + struct pyrf_pmu *ppmu =3D (void *)self; + PyObject *py_list =3D PyList_New(0); + int ret; + + if (!py_list) + return NULL; + + ret =3D perf_pmu__for_each_event(ppmu->pmu, + /*skip_duplicate_pmus=3D*/false, + py_list, + pyrf_pmu__events_cb); + if (ret) { + Py_DECREF(py_list); + errno =3D -ret; + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + return py_list; +} + static PyObject *pyrf_pmu__repr(PyObject *self) { struct pyrf_pmu *ppmu =3D (void *)self; @@ -670,6 +735,12 @@ static PyObject *pyrf_pmu__repr(PyObject *self) static const char pyrf_pmu__doc[] =3D PyDoc_STR("perf Performance Monitori= ng Unit (PMU) object."); =20 static PyMethodDef pyrf_pmu__methods[] =3D { + { + .ml_name =3D "events", + .ml_meth =3D (PyCFunction)pyrf_pmu__events, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("Name of the PMU including suffixes.") + }, { .ml_name =3D "name", .ml_meth =3D (PyCFunction)pyrf_pmu__name, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 DFCF4273D87 for ; Wed, 23 Jul 2025 23:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313008; cv=none; b=btns1F3H8KN7M47Jf4vqyOHJ8DKp0tusE1iMRHczlMkrvWTxyYA694hUxfXZEFfqEewFgRArFKyK+0mSjDRiiA/5cckGxCpxdp3CA6cIkg9RqgaUpA9vBCaFkPolXR+IvCk/ZAtck91Ic655ztxJqZ8RkH4s3Ax0Sy4xpi/ZW1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313008; c=relaxed/simple; bh=i/uCDsv8+rOSTJnGyZbQeVsFKofa773YiArLZA/dxKs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=a0qUrXLRMEF0xjNXLyADHNtNKOFX765nzMt8mp5qG3De3MdJA5WN0jna5JOeaWpdbiDJF9ZZLpl0T6hpamqJJEyzgcQ5mBgYOIqnlyqiwY8matOjT4JozE7tCD93WrvSF5+lj7k9Btc2fCkT3qlAT83Cjfd9qAV/WBB8pbo9jLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nlnsIEN3; arc=none smtp.client-ip=209.85.214.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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nlnsIEN3" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-23536f7c2d7so4948095ad.2 for ; Wed, 23 Jul 2025 16:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753313006; x=1753917806; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HFi3zgFb8jCVzoCsFCtApWIwcY3tmhaoiYYQjloOwb0=; b=nlnsIEN3hwY2dTCBfrBuLEicchEArRTqtcuEXvBT6nfl+xxL30JaaSl4Fc1ftJvhIi qvMPPhmSAktXxwiCd+c04HFoceANdsrA+SVX3F/m3RvDUJt7Eia/cquHXXAwuP6w3bl8 5LfG7O4T+Lu46VB6y/AG3iC26BSlfmciGFu+JVxz5Xguuxw4Im1ZyPQR8/wNkQNURxvV vTz3NPjjc+ZO1kvlZ9Kr31lfm2rNvTpZeP5Z9V8vcEnOx68IoTivhyx/6X9nwUzTkpzZ 1BZoEcgTOHicIEw68cKZeufh9HwZnbmVrVWEwsR7axHb5rUbLkI8Z6qTYlNTO7iCpY5U px+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753313006; x=1753917806; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HFi3zgFb8jCVzoCsFCtApWIwcY3tmhaoiYYQjloOwb0=; b=QzXMRCLP6LKP8JrTIC59trI9taq7kLNQwUTSipOD2l4RrJ9sPx/d7NBiUuJucmUgjw KTsSqkn00M9YZKvg/4MmQJ2kNb0oeWceU9VqoxkKdsXNS9PdG93XQH83UzU/leTIyq2m 3YHKfD5djcptOI7m3FP5QDoGvW2j+dixeAIFcW8xeqTdNZd5zgiKlA27qUUznR+JB7eR RFiWRebkLMZSnDP7e/NWCSz4OM0HYWgM064Rrt6pXEyljgI/G54FqidBa+HOlsmAJgxu 8VoUgKwxcw6o1gtsGwKR49nxvUjwpyO4PMTVaRjH3ppj2hb6am/fxb4j6NzGJcHGteGS SSNg== X-Forwarded-Encrypted: i=1; AJvYcCVQ/DmUQ3GB1xKZL6tHGol9sPT2VRaDjLL0TrRoxJXlRnDGFnhtHMUSnMamqBKDrfWB2Qlai/P67QlUtWA=@vger.kernel.org X-Gm-Message-State: AOJu0YyD3hpyOwCr3Fff0TEc5vd3iEcb/LQNf58Cnzj4NQ6XmDfe52IF 7K9wUyh2GfPA6K6NtxG6cWOhh3xqj8yXzlPjhD6qesm0rWRTV/Rimfyvh3BXNqaFJhi3EPkDsi9 Y+pHoq9lVhA== X-Google-Smtp-Source: AGHT+IGVdfeZ+Pwsnfg+ZbNjdEVHjGtn6mbUyWIBVc67NxJCND3TdB5RrP5AGtmvoeXHPfNi+ShZEZbsFZOt X-Received: from plbkw6.prod.google.com ([2002:a17:902:f906:b0:234:4c97:1e84]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:c40c:b0:234:b422:7120 with SMTP id d9443c01a7336-23f9812b3e8mr66440065ad.9.1753313006368; Wed, 23 Jul 2025 16:23:26 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:12 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-12-irogers@google.com> Subject: [PATCH v8 11/16] perf ilist: Add new python ilist command From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The perf ilist command is a textual app [1] similar to perf list. In the top-left pane a tree of PMUs is displayed. Selecting a PMU expands the events within it. Selecting an event displays the `perf list` style event information in the top-right pane. When an event is selected it is opened and the counters on each CPU the event is for are periodically read. The bottom of the screen contains a scrollable set of sparklines showing the events in total and on each CPU. Scrolling below the sparklines shows the same data as raw counts. The sparklines are small graphs where the height of the bar is in relation to maximum of the other counts in the graph. By default the counts are read with an interval of 0.1 seconds (10 times per second). A -I/--interval command line option allows the interval to be changed. The oldest read counts are dropped when the counts fill the line causing the sparkline to move from right to left. A search box can be pulled up with the 's' key. 'n' and 'p' iterate through the search results. As some PMUs have hundreds of events a 'c' key will collapse the events in the current PMU to make navigating the PMUs easier. [1] https://textual.textualize.io/ Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/python/ilist.py | 392 +++++++++++++++++++++++++++++++++++++ 1 file changed, 392 insertions(+) create mode 100755 tools/perf/python/ilist.py diff --git a/tools/perf/python/ilist.py b/tools/perf/python/ilist.py new file mode 100755 index 000000000000..b21f4c93247e --- /dev/null +++ b/tools/perf/python/ilist.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +"""Interactive perf list.""" + +import argparse +from typing import Any, Dict, Tuple +import perf +from textual import on +from textual.app import App, ComposeResult +from textual.binding import Binding +from textual.containers import Horizontal, HorizontalGroup, Vertical, Vert= icalScroll +from textual.command import SearchIcon +from textual.screen import ModalScreen +from textual.widgets import Button, Footer, Header, Input, Label, Sparklin= e, Static, Tree +from textual.widgets.tree import TreeNode + +class ErrorScreen(ModalScreen[bool]): + """Pop up dialog for errors.""" + + CSS=3D""" + ErrorScreen { + align: center middle; + } + """ + def __init__(self, error: str): + self.error =3D error + super().__init__() + + def compose(self) -> ComposeResult: + yield Button(f"Error: {self.error}", variant=3D"primary", id=3D"er= ror") + + def on_button_pressed(self, event: Button.Pressed) -> None: + self.dismiss(True) + + +class SearchScreen(ModalScreen[str]): + """Pop up dialog for search.""" + + CSS=3D""" + SearchScreen Horizontal { + align: center middle; + margin-top: 1; + } + SearchScreen Input { + width: 1fr; + } + """ + def compose(self) -> ComposeResult: + yield Horizontal(SearchIcon(), Input(placeholder=3D"Event name")) + + def on_input_submitted(self, event: Input.Submitted) -> None: + """Handle the user pressing Enter in the input field.""" + self.dismiss(event.value) + + +class Counter(HorizontalGroup): + """Two labels for a CPU and its counter value.""" + + CSS=3D""" + Label { + gutter: 1; + } + """ + + def __init__(self, cpu: int) -> None: + self.cpu =3D cpu + super().__init__() + + def compose(self) -> ComposeResult: + label =3D f"cpu{self.cpu}" if self.cpu >=3D 0 else "total" + yield Label(label + " ") + yield Label("0", id=3Df"counter_{label}") + + +class CounterSparkline(HorizontalGroup): + """A Sparkline for a performance counter.""" + + def __init__(self, cpu: int) -> None: + self.cpu =3D cpu + super().__init__() + + def compose(self) -> ComposeResult: + label =3D f"cpu{self.cpu}" if self.cpu >=3D 0 else "total" + yield Label(label) + yield Sparkline([], summary_function=3Dmax, id=3Df"sparkline_{labe= l}") + + +class IListApp(App): + TITLE =3D "Interactive Perf List" + + BINDINGS =3D [ + Binding(key=3D"s", action=3D"search", description=3D"Search", + tooltip=3D"Search events and PMUs"), + Binding(key=3D"n", action=3D"next", description=3D"Next", + tooltip=3D"Next search result or item"), + Binding(key=3D"p", action=3D"prev", description=3D"Previous", + tooltip=3D"Previous search result or item"), + Binding(key=3D"c", action=3D"collapse", description=3D"Collapse", + tooltip=3D"Collapse the current PMU"), + Binding(key=3D"^q", action=3D"quit", description=3D"Quit", + tooltip=3D"Quit the app"), + ] + + CSS =3D """ + /* Make the 'total' sparkline a different color. */ + #sparkline_total > .sparkline--min-color { + color: $accent; + } + #sparkline_total > .sparkline--max-color { + color: $accent 30%; + } + /* + * Make the active_search initially not displayed with the text in + * the middle of the line. + */ + #active_search { + display: none; + width: 100%; + text-align: center; + } + """ + + def __init__(self, interval: float) -> None: + self.interval =3D interval + self.evlist =3D None + self.search_results: list[TreeNode[str]] =3D [] + self.cur_search_result: TreeNode[str] | None =3D None + super().__init__() + + + + def expand_and_select(self, node: TreeNode[Any]) -> None: + """Expand select a node in the tree.""" + if node.parent: + node.parent.expand() + if node.parent.parent: + node.parent.parent.expand() + node.expand() + node.tree.select_node(node) + node.tree.scroll_to_node(node) + + + def set_searched_tree_node(self, previous: bool) -> None: + """Set the cur_search_result node to either the next or previous."= "" + l =3D len(self.search_results) + + if l < 1: + tree: Tree[str] =3D self.query_one("#pmus", Tree) + if previous: + tree.action_cursor_up() + else: + tree.action_cursor_down() + return + + if self.cur_search_result: + idx =3D self.search_results.index(self.cur_search_result) + if previous: + idx =3D idx - 1 if idx > 0 else l - 1 + else: + idx =3D idx + 1 if idx < l - 1 else 0 + else: + idx =3D l - 1 if previous else 0 + + node =3D self.search_results[idx] + if node =3D=3D self.cur_search_result: + return + + self.cur_search_result =3D node + self.expand_and_select(node) + + def action_search(self) -> None: + """Search was chosen.""" + def set_initial_focus(event: str | None) -> None: + """Sets the focus after the SearchScreen is dismissed.""" + + search_label =3D self.query_one("#active_search", Label) + search_label.display =3D True if event else False + if not event: + return + event =3D event.lower() + search_label.update(f'Searching for events matching "{event}"') + + tree: Tree[str] =3D self.query_one("#pmus", Tree) + def find_search_results(event: str, node: TreeNode[str], \ + cursor_seen: bool =3D False, \ + match_after_cursor: TreeNode[str] | No= ne =3D None) \ + -> Tuple[bool, TreeNode[str] | None]: + """Find nodes that match the search remembering the one af= ter the cursor.""" + if not cursor_seen and node =3D=3D tree.cursor_node: + cursor_seen =3D True + if node.data and event in node.data: + if cursor_seen and not match_after_cursor: + match_after_cursor =3D node + self.search_results.append(node) + + if node.children: + for child in node.children: + (cursor_seen, match_after_cursor) =3D \ + find_search_results(event, child, cursor_seen,= match_after_cursor) + return (cursor_seen, match_after_cursor) + + self.search_results.clear() + (_ , self.cur_search_result) =3D find_search_results(event, tr= ee.root) + if len(self.search_results) < 1: + self.push_screen(ErrorScreen(f"Failed to find pmu/event {e= vent}")) + search_label.display =3D False + elif self.cur_search_result: + self.expand_and_select(self.cur_search_result) + else: + self.set_searched_tree_node(previous=3DFalse) + + self.push_screen(SearchScreen(), set_initial_focus) + + + def action_next(self) -> None: + """Next was chosen.""" + self.set_searched_tree_node(previous=3DFalse) + + + def action_prev(self) -> None: + """Previous was chosen.""" + self.set_searched_tree_node(previous=3DTrue) + + + def action_collapse(self) -> None: + """Collapse the potentially large number of events under a PMU.""" + tree: Tree[str] =3D self.query_one("#pmus", Tree) + node =3D tree.cursor_node + if node and node.parent and node.parent.parent: + node.parent.collapse_all() + node.tree.scroll_to_node(node.parent) + + + def update_counts(self) -> None: + """Called every interval to update counts.""" + if not self.evlist: + return + + def update_count(cpu: int, count: int): + # Update the raw count display. + counter: Label =3D self.query(f"#counter_cpu{cpu}" if cpu >=3D= 0 else "#counter_total") + if not counter: + return + counter =3D counter.first(Label) + counter.update(str(count)) + + # Update the sparkline. + line: Sparkline =3D self.query(f"#sparkline_cpu{cpu}" if cpu >= =3D 0 else "#sparkline_total") + if not line: + return + line =3D line.first(Sparkline) + # If there are more events than the width, remove the front ev= ent. + if len(line.data) > line.size.width: + line.data.pop(0) + line.data.append(count) + line.mutate_reactive(Sparkline.data) + + # Update the total and each CPU counts, assume there's just 1 evse= l. + total =3D 0 + self.evlist.disable() + for evsel in self.evlist: + for cpu in evsel.cpus(): + aggr =3D 0 + for thread in evsel.threads(): + counts =3D evsel.read(cpu, thread) + aggr +=3D counts.val + update_count(cpu, aggr) + total +=3D aggr + update_count(-1, total) + self.evlist.enable() + + + def on_mount(self) -> None: + """When App starts set up periodic event updating.""" + self.update_counts() + self.set_interval(self.interval, self.update_counts) + + + def set_pmu_and_event(self, pmu: str, event: str) -> None: + """Updates the event/description and starts the counters.""" + # Remove previous event information. + if self.evlist: + self.evlist.disable() + self.evlist.close() + lines =3D self.query(CounterSparkline) + for line in lines: + line.remove() + lines =3D self.query(Counter) + for line in lines: + line.remove() + + def pmu_event_description(pmu: str, event: str) -> str: + """Find and format event description for {pmu}/{event}/.""" + def get_info(info: Dict[str, str], key: str): + return (info[key] + "\n") if key in info else "" + + for p in perf.pmus(): + if p.name() !=3D pmu: + continue + for info in p.events(): + if "name" not in info or info["name"] !=3D event: + continue + + desc =3D get_info(info, "topic") + desc +=3D get_info(info, "event_type_desc") + desc +=3D get_info(info, "desc") + desc +=3D get_info(info, "long_desc") + desc +=3D get_info(info, "encoding_desc") + return desc + return "description" + + # Parse event, update event text and description. + full_name =3D event if event.startswith(pmu) or ':' in event else = f"{pmu}/{event}/" + self.query_one("#event_name", Label).update(full_name) + self.query_one("#event_description", Static).update(pmu_event_desc= ription(pmu, event)) + + # Open the event. + try: + self.evlist =3D perf.parse_events(full_name) + if self.evlist: + self.evlist.open() + self.evlist.enable() + except: + self.evlist =3D None + + if not self.evlist: + self.push_screen(ErrorScreen(f"Failed to open {full_name}")) + return + + # Add spark lines for all the CPUs. Note, must be done after + # open so that the evlist CPUs have been computed by propagate + # maps. + lines =3D self.query_one("#lines") + line =3D CounterSparkline(cpu=3D-1) + lines.mount(line) + for cpu in self.evlist.all_cpus(): + line =3D CounterSparkline(cpu) + lines.mount(line) + line =3D Counter(cpu=3D-1) + lines.mount(line) + for cpu in self.evlist.all_cpus(): + line =3D Counter(cpu) + lines.mount(line) + + + def compose(self) -> ComposeResult: + """Draws the app.""" + def pmu_event_tree() -> Tree: + """Create tree of PMUs with events under.""" + tree: Tree[str] =3D Tree("PMUs", id=3D"pmus") + tree.root.expand() + for pmu in perf.pmus(): + pmu_name =3D pmu.name().lower() + pmu_node =3D tree.root.add(pmu_name, data=3Dpmu_name) + try: + for event in sorted(pmu.events(), key=3Dlambda x: x["n= ame"]): + if "name" in event: + e =3D event["name"].lower() + if "alias" in event: + pmu_node.add_leaf(f'{e} ({event["alias"]})= ', data=3De) + else: + pmu_node.add_leaf(e, data=3De) + except: + # Reading events may fail with EPERM, ignore. + pass + return tree + + yield Header(id=3D"header") + yield Horizontal(Vertical(pmu_event_tree(), id=3D"events"), + Vertical(Label("event name", id=3D"event_name"), + Static("description", markup=3DFalse, id= =3D"event_description"), + )) + yield Label(id=3D"active_search") + yield VerticalScroll(id=3D"lines") + yield Footer(id=3D"footer") + + + @on(Tree.NodeSelected) + def on_tree_node_selected(self, event: Tree.NodeSelected[str]) -> None: + """Called when a tree node is selected, selecting the event.""" + if event.node.parent and event.node.parent.parent: + assert event.node.parent.data is not None + assert event.node.data is not None + self.set_pmu_and_event(event.node.parent.data, event.node.data) + + +if __name__ =3D=3D "__main__": + ap =3D argparse.ArgumentParser() + ap.add_argument('-I', '--interval', help=3D"Counter update interval in= seconds", default=3D0.1) + args =3D ap.parse_args() + app =3D IListApp(float(args.interval)) + app.run() --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 7B28D2750FD for ; Wed, 23 Jul 2025 23:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313014; cv=none; b=kuqgRtwxmw/9941GRouQlDG0jxeIiJ94jcO3suiSO0TgoNWasWfkJ2ucd/tP4fvPMMaq/nmD5tmgoPnIUj1tNG6NLNo/FYjSFK9S5RyV04HCoiU0QGvrz74bRxMM/27LU5OHCZ2ZCM2VOfrMIHwEYtuiJt+jOYXSLX7PM9AVSm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313014; c=relaxed/simple; bh=/himY3eC7Z230jJ9df7QB/QiKXUXmGuN5KAZQf/rp6M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CKkmDVfQ6NyRO/idH+j4MmnSGwa5TOCl7RKYbLW2vEs16sFSKpcd7MDt3dhOxzDrrPZkdtnjSN579xcR4ZzCZYDRqbXUSoHHQu9AUqZ10cba/kkDGPYXYYHhndZd792IDTEbucAgt2HLcYAWuK428gr5nltVBhdBjRHqy8z+Mx0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U/vxKKkA; arc=none smtp.client-ip=209.85.216.73 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U/vxKKkA" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-31315427249so291824a91.1 for ; Wed, 23 Jul 2025 16:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753313012; x=1753917812; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DG/WMio8wVCpnUQBjwF3J5hHGj8AkOoD74Vnrlwpzz4=; b=U/vxKKkADIG2raZyehZvQuTA6tpnEJ0IUY6vWCYYkLVzHVEIOVPhnhA6omYUZbBW94 OmJI53luhsDiN6SaHlpUqt7FsdvSKx/PXniVdiPXYMowPxxK9GCjWGU0YA0OkDxLMnZn EF1sxO1e1gA+Kg9HSrZ9MtSlIAH0BVRucjqLVHOyh7A8tHQL/jnlrfVNiINA+HN/xzdU Ek34WCfTgiB/FUbrwkAXJuf9tXCGaj3FSdBKHAcGYj3dK9ne4GiTmD+UizqU3NOHWXdO W2DJjWSxuTsUD1LwzuqzUYuOxRLjMPDBE3WRRQJLvfmVy7bG5y8l/USK5q8Ho1+yPhN2 3OvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753313012; x=1753917812; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DG/WMio8wVCpnUQBjwF3J5hHGj8AkOoD74Vnrlwpzz4=; b=UQwenQoUjVF1MpNqwDeBf+ALYlwKJhoRr1oF6rHhdvgwzh2ku7WGxHRL/CQ37Qgm3+ 10WDou6x3w9S1ugYh3KUMqGqip6TNiI5U5VleAVHwDoP7qLti86E3KqGC1OzrilOtonn bDUDiV9UKVYK2lyrRhDFmwk4I/rYChUT5Qimj0wz9MjD9TrBpXaBFmBl+rVKc1mxAzak 7DOQSfIDGyCVfxZjQRzORLqWCkD6P8owsP3HhypybtIc3kn9Vijg6CpCf5VgMs8zkugP RLYsoenn+YZPAHTdDTTX+Cpb4HP4eQM26FpfbTrHR2ti5yXBQQV8kaBRJ24sLvnGfO5c /5Tw== X-Forwarded-Encrypted: i=1; AJvYcCUVjP1nZcsw1nhmpKa7XrlLG+DIhf4k1dK4WDC+KYwPjf2YVrDtXj2QeOSeXRUg1srf5weF7eo5TutFo0M=@vger.kernel.org X-Gm-Message-State: AOJu0YwYJbkFOpaHqBWMAHQ/R86CILqqXfihKvqDFlRFnQ/+n5v1SpfV X7phe4CPL17HZNdbwuDR2XcQhWwTwnZn8iEt8FPXwWt41pA1jC6l7g3ifipuLZUjq0jEHStGIfx stV8Agldo6Q== X-Google-Smtp-Source: AGHT+IEIcgmHXPNBSG6BQ36NaMOBP7BbcFIM4B+zrx3GD0vSuUDAyeqf9MFMWze7IE4f03SMmi0lIAe3GQvx X-Received: from pjbqj14.prod.google.com ([2002:a17:90b:28ce:b0:313:2213:1f54]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2d0e:b0:312:f88d:25f9 with SMTP id 98e67ed59e1d1-31e5073f879mr7422728a91.7.1753313011856; Wed, 23 Jul 2025 16:23:31 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:13 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-13-irogers@google.com> Subject: [PATCH v8 12/16] perf python: Add parse_metrics function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add parse_metrics function that takes a string of metrics and/or metric groups and returns the evlist containing the events and metrics. For example: ``` >>> import perf >>> perf.parse_metrics("TopdownL1") evlist([cpu/TOPDOWN.SLOTS/,cpu/topdown-retiring/,cpu/topdown-fe-bound/, cpu/topdown-be-bound/,cpu/topdown-bad-spec/,cpu/INT_MISC.CLEARS_COUNT/, cpu/INT_MISC.UOP_DROPPING/]) ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index d49b4401ab7e..3a58080bab24 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1881,6 +1881,40 @@ static PyObject *pyrf__parse_events(PyObject *self, = PyObject *args) return result; } =20 +static PyObject *pyrf__parse_metrics(PyObject *self, PyObject *args) +{ + const char *input; + struct evlist evlist =3D {}; + PyObject *result; + PyObject *pcpus =3D NULL, *pthreads =3D NULL; + struct perf_cpu_map *cpus; + struct perf_thread_map *threads; + int ret; + + if (!PyArg_ParseTuple(args, "s|OO", &input, &pcpus, &pthreads)) + return NULL; + + threads =3D pthreads ? ((struct pyrf_thread_map *)pthreads)->threads : NU= LL; + cpus =3D pcpus ? ((struct pyrf_cpu_map *)pcpus)->cpus : NULL; + + evlist__init(&evlist, cpus, threads); + ret =3D metricgroup__parse_groups(&evlist, /*pmu=3D*/"all", input, + /*metric_no_group=3D*/ false, + /*metric_no_merge=3D*/ false, + /*metric_no_threshold=3D*/ true, + /*user_requested_cpu_list=3D*/ NULL, + /*system_wide=3D*/true, + /*hardware_aware_grouping=3D*/ false); + if (ret) { + errno =3D -ret; + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + result =3D pyrf_evlist__from_evlist(&evlist); + evlist__exit(&evlist); + return result; +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "tracepoint", @@ -1894,6 +1928,13 @@ static PyMethodDef perf__methods[] =3D { .ml_flags =3D METH_VARARGS, .ml_doc =3D PyDoc_STR("Parse a string of events and return an evlist.") }, + { + .ml_name =3D "parse_metrics", + .ml_meth =3D (PyCFunction) pyrf__parse_metrics, + .ml_flags =3D METH_VARARGS, + .ml_doc =3D PyDoc_STR( + "Parse a string of metics or metric groups and return an evlist.") + }, { .ml_name =3D "pmus", .ml_meth =3D (PyCFunction) pyrf__pmus, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) (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 5F5982737FF for ; Wed, 23 Jul 2025 23:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313020; cv=none; b=uA0VzwXugeLbVWlstfFUOvMmABPO1aZRR7IlZ7ipO/M9Rg0iteQJCh2JAWUAjtIuAEuE5ECTzQYWVHOQmVYvXPFq2MaRp/eLosadZy/4JHahBFoj/ROwIDP+XTZ2ES8vzAubgpKS1ncgSFeNm//2rHIUX1EVyt3Jj06jv6Xtop0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313020; c=relaxed/simple; bh=Sxav3zDD0U0Gg/+clfnyl2vd++/wAcjd/MiMe5A6hwM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aZLqnKYBwZ7RcoOAAGqT4BF9Gz64sJbJ3DnqFl0xtuVU5PrDDmT0dYP/JerDki3ucGYvtZHi1voNj/xczZeTdlwNPnZJPuitYlMxEV7BzRR1MeYMoOI8ZetUEhyMfzOnsG7Hn1ZC3wVDTUZcSQvN7t7fRqbo5LL9aoi5VOz0u/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=L4b0IuFu; arc=none smtp.client-ip=209.85.222.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L4b0IuFu" Received: by mail-qk1-f202.google.com with SMTP id af79cd13be357-7e33f7a58f6so63705585a.3 for ; Wed, 23 Jul 2025 16:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753313017; x=1753917817; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=v96KHBG+xnk8h1wczuNITcFFd9n/85CgWkXy1c40Fug=; b=L4b0IuFugtYSEzDSSRreFDsDpnF9xwnOntjYB8vJlLZFJAF/1l8Y8yVEbCtZjBrOJH UZVH8oRvpW2NJrcQ2fBTz4k4cO4fxznZXk/FQK6Zuc6mFQhhDHKOJYDWCIPG1RHOZyKK 5pmNz3J2p9HB2wUQWljtOpuxLqQYPwHm8wwl63oNAGfLv92GYqtFLwE7fmxrkScOHEHD 79uM/aascGATsb2tZIMk/EeogzkH6vtnJcmV15iFTq0tGObe2blcvI3BIlxGyT7Q12// UPp7QB0FoKqZWvQPuHW2lYZwmfkCbLNg7X3enwCl4XB4LWWYH5HG2RoBU8bEg6z8S4NP f7uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753313017; x=1753917817; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=v96KHBG+xnk8h1wczuNITcFFd9n/85CgWkXy1c40Fug=; b=phPpPZpBWN5UtWj2Hnyfb3QtVGWtDrZ3RfeoEPHYffPd73z8gzQOREJCa6xwOUVJaT xsVjJBM9En3ri6vXlCplmRr7RCuUxOk4e0drZWB/yeW3oU4Z5iQAJretVqcJCvUAcmYt iyLdZVDZfi45adQbww7uuLZ33f6L39KDQesAJzLAp/n0mCwBqMccopLI1vKbfuEt4ncM 8cXWj+YaZC119MrfKCu9UVi0a3OunwANJBKwLvdApov+QOuQTmnqiDD0468nNZHVe6zd n8BVQSNwg83Iy1G3m0dVIsriYPiONF3pHNext17PdJGSEFcbM1EVc0RhPK+0msinv3YQ eb8Q== X-Forwarded-Encrypted: i=1; AJvYcCUE69lEb+v2D6I8aSzwYEl3f+UfwEijsdv/uTKEE8uWxjyFT+b8Ci/4EmmewY0f56y2UIkp0iNIsxA0Neg=@vger.kernel.org X-Gm-Message-State: AOJu0YwFGiybIlfJ771244W3Tkkw9hmeeVFhbP1vu3xwoNo/q/TdnjQ5 zc8AxFWvJAq1vVR4OZPIIQkGpncdrKeRLWLN+8iJ4UIqDfNH5wt/hJKkXx/CZBwVMILOn3vBNLs sxBItsGgwng== X-Google-Smtp-Source: AGHT+IFITYad3KgDe7X8tbLUFDJuJhFhSRxKrRCTY7rZfyUjflk9lqEUUE//mQnXdlw4KoxYLec69qUS7oaW X-Received: from qkpu10.prod.google.com ([2002:a05:620a:454a:b0:7d4:4ab:49a7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:400d:b0:7e3:3cbc:786d with SMTP id af79cd13be357-7e62a17ec2emr533579385a.28.1753313017256; Wed, 23 Jul 2025 16:23:37 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:14 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-14-irogers@google.com> Subject: [PATCH v8 13/16] perf python: Add evlist metrics function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function returns a list of the names of metrics within the evlist. For example: ``` >>> import perf >>> perf.parse_metrics("TopdownL1").metrics() ['tma_bad_speculation', 'tma_frontend_bound', 'tma_backend_bound', 'tma_ret= iring'] ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 3a58080bab24..ccfa1ac4ad4b 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1293,6 +1293,33 @@ static PyObject *pyrf_evlist__all_cpus(struct pyrf_e= vlist *pevlist) return (PyObject *)pcpu_map; } =20 +static PyObject *pyrf_evlist__metrics(struct pyrf_evlist *pevlist) +{ + PyObject *list =3D PyList_New(/*len=3D*/0); + struct rb_node *node; + + if (!list) + return NULL; + + for (node =3D rb_first_cached(&pevlist->evlist.metric_events.entries); no= de; + node =3D rb_next(node)) { + struct metric_event *me =3D container_of(node, struct metric_event, nd); + struct list_head *pos; + + list_for_each(pos, &me->head) { + struct metric_expr *expr =3D container_of(pos, struct metric_expr, nd); + PyObject *str =3D PyUnicode_FromString(expr->metric_name); + + if (!str || PyList_Append(list, str) !=3D 0) { + Py_DECREF(list); + return NULL; + } + Py_DECREF(str); + } + } + return list; +} + static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { @@ -1521,6 +1548,12 @@ static PyMethodDef pyrf_evlist__methods[] =3D { .ml_flags =3D METH_NOARGS, .ml_doc =3D PyDoc_STR("CPU map union of all evsel CPU maps.") }, + { + .ml_name =3D "metrics", + .ml_meth =3D (PyCFunction)pyrf_evlist__metrics, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("List of metric names within the evlist.") + }, { .ml_name =3D "mmap", .ml_meth =3D (PyCFunction)pyrf_evlist__mmap, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 ED0312741CE for ; Wed, 23 Jul 2025 23:23:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313027; cv=none; b=rQVVVqvJE6J0lxVijwROmUoxpZoy86lDpz0qUopDjKGD3uXx7pHRYRsplWwbk6x5NC1GjUWjYqiNcQwTTcLEM9Y+Z+v32reyJIp8OM0i6Vv6q5F0YLg+NhN5lF5RfmNKjktajulPbOyPo0ijnb0zNsfRxPYqBedAFPEDmf29rtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313027; c=relaxed/simple; bh=Mgnwz7tYBZGZtrHCiH33hqMzlku6c07RTsVF4TfpqV0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OVhh/YTZcWpiW0bgXdMNHzEwXMmzoRGPq2b6WPjUtK8t1p3/hqdjzknSAeCxVi+detxrywACBcAtglTnkH3KQxTJjOlkVWzpJbZkNBr1Upk60CrQ7qFFaYM6vMtsUzQB8JGPqSJJ+/6pmetCimnqrixok0OHglWahdeYWuMIkec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=huJOdEQv; arc=none smtp.client-ip=209.85.215.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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="huJOdEQv" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b31bc3128fcso650360a12.0 for ; Wed, 23 Jul 2025 16:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753313025; x=1753917825; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dXoQMIXLmOQx7GzKmUg+IZLE7vwXUCwLlnreH79TGAE=; b=huJOdEQv3YwQgt7q9xArbp+JzEIFe2Rlms3omyb2rr7ioE9vrJiQ5+jj31PTfLMB+5 LYEE7CCkJ8DzEAQo8yyCpCNhUHVoFH5Wjo4uB+T3vGCYigT5RSH8QwAFk0K4OUZBXYqP zBeEyJ2PisLhnq27J90EXuM9y9wepcmH3ReklL/sJLQnI1nX4wjngCjcQBNRrvi9QZTV hdHp+uC44uICjvtcFNmNaOamCYWSShl86FGfl+WiZ94mxFkws92kwzY5cOH2aYm4Ie2e sqMzOZwzyBv74v56LaEVuS0xWH1R0Qld/re5gbEs+urQ5DKep5MxYK9/PrSOnQvnbe5Q m3QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753313025; x=1753917825; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dXoQMIXLmOQx7GzKmUg+IZLE7vwXUCwLlnreH79TGAE=; b=Z2MJAl3m2ZMmBwsnddpJ7vIE58dI35Q8U4X/vgsq/jtK2ERHOJ9pIsP5tU0ixMvrt5 mXOyEGvye4HeDh6Mx+z+x8R8s6a3SuTliretmS17bNUPYdGoP9m7jqI5cNvIpDYA2Hzd 0gV5OVbJPhNoHWe0qcuLvV+N04BGkDJQEufxWe7XDUTINTXm0P36MP7dqf4nmalft8eM yBxQRweB1g3WiFDAxnxhVI6lrBwj3p3LryDTFuiLMmWFWYESCqF9X0GOjusYVRxES5Ck aTNHJ5jo8YuI/6j7tcctfb7uxzMwX/bP7ehZiykM/FYs7ral/GR6oGu6UQRlGdtIcnP1 w9PA== X-Forwarded-Encrypted: i=1; AJvYcCWqEtmTGIBqqpP1cAbVMbQhKR65O3iX4r0THnzqQXkbaSZimsee6F8mccFDc8dYY9ifbNNyjCtb1fKGucg=@vger.kernel.org X-Gm-Message-State: AOJu0YxHzmW1Tl8Ztmz8oQ28JUu/5WGRRbO2h59ZFWn9sGb9PNFvyrgT 4DgFlwH7Lk5AVAv+SoODw80ra3YH67SHHWXIF3mchkZSPaPl3lT/Wdf/VL/XDhvcpX3lZiQgYnn n87ISIVCX/A== X-Google-Smtp-Source: AGHT+IFtdvT3aNmFUHt5YINly7Vy0cLTn97EegffebvDI2ypJ+kicBsJYj7RJKtP6hObpFKcW3UuNuJHRROu X-Received: from pfks17.prod.google.com ([2002:a05:6a00:1951:b0:748:e72f:1148]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:68e:b0:239:c5f:62a1 with SMTP id adf61e73a8af0-23d491bfe15mr6732120637.33.1753313025270; Wed, 23 Jul 2025 16:23:45 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:15 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-15-irogers@google.com> Subject: [PATCH v8 14/16] perf python: Add evlist compute_metric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a compute_metric function that computes a metric double value for a given evlist, metric name, CPU and thread. For example: ``` >>> import perf >>> x =3D perf.parse_metrics("TopdownL1") >>> x.open() >>> x.enable() >>> x.disable() >>> x.metrics() ['tma_bad_speculation', 'tma_frontend_bound', 'tma_backend_bound', 'tma_ret= iring'] >>> x.compute_metric('tma_bad_speculation', 0, -1) 0.08605342847131037 ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 125 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index ccfa1ac4ad4b..bee7c8a69bad 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -14,6 +14,7 @@ #include "evlist.h" #include "evsel.h" #include "event.h" +#include "expr.h" #include "print_binary.h" #include "record.h" #include "strbuf.h" @@ -1320,6 +1321,124 @@ static PyObject *pyrf_evlist__metrics(struct pyrf_e= vlist *pevlist) return list; } =20 +static int prepare_metric(const struct metric_expr *mexp, + const struct evsel *evsel, + struct expr_parse_ctx *pctx, + int cpu_idx, int thread_idx) +{ + struct evsel * const *metric_events =3D mexp->metric_events; + struct metric_ref *metric_refs =3D mexp->metric_refs; + + for (int i =3D 0; metric_events[i]; i++) { + char *n =3D strdup(evsel__metric_id(metric_events[i])); + double val, ena, run; + int source_count =3D evsel__source_count(metric_events[i]); + int ret; + struct perf_counts_values *old_count, *new_count; + + if (!n) + return -ENOMEM; + + if (source_count =3D=3D 0) + source_count =3D 1; + + ret =3D evsel__ensure_counts(metric_events[i]); + if (ret) + return ret; + + /* Set up pointers to the old and newly read counter values. */ + old_count =3D perf_counts(metric_events[i]->prev_raw_counts, cpu_idx, th= read_idx); + new_count =3D perf_counts(metric_events[i]->counts, cpu_idx, thread_idx); + /* Update the value in metric_events[i]->counts. */ + evsel__read_counter(metric_events[i], cpu_idx, thread_idx); + + val =3D new_count->val - old_count->val; + ena =3D new_count->ena - old_count->ena; + run =3D new_count->run - old_count->run; + + if (ena !=3D run && run !=3D 0) + val =3D val * ena / run; + ret =3D expr__add_id_val_source_count(pctx, n, val, source_count); + if (ret) + return ret; + } + + for (int i =3D 0; metric_refs && metric_refs[i].metric_name; i++) { + int ret =3D expr__add_ref(pctx, &metric_refs[i]); + + if (ret) + return ret; + } + + return 0; +} + +static PyObject *pyrf_evlist__compute_metric(struct pyrf_evlist *pevlist, + PyObject *args, PyObject *kwargs) +{ + int ret, cpu =3D 0, cpu_idx, thread =3D 0, thread_idx; + const char *metric; + struct rb_node *node; + struct metric_expr *mexp =3D NULL; + struct expr_parse_ctx *pctx; + double result =3D 0; + + if (!PyArg_ParseTuple(args, "sii", &metric, &cpu, &thread)) + return NULL; + + for (node =3D rb_first_cached(&pevlist->evlist.metric_events.entries); + mexp =3D=3D NULL && node; + node =3D rb_next(node)) { + struct metric_event *me =3D container_of(node, struct metric_event, nd); + struct list_head *pos; + + list_for_each(pos, &me->head) { + struct metric_expr *e =3D container_of(pos, struct metric_expr, nd); + + if (strcmp(e->metric_name, metric)) + continue; + + if (e->metric_events[0] =3D=3D NULL) + continue; + + cpu_idx =3D perf_cpu_map__idx(e->metric_events[0]->core.cpus, + (struct perf_cpu){.cpu =3D cpu}); + if (cpu_idx < 0) + continue; + + thread_idx =3D perf_thread_map__idx(e->metric_events[0]->core.threads, + thread); + if (thread_idx < 0) + continue; + + mexp =3D e; + break; + } + } + if (!mexp) { + PyErr_Format(PyExc_TypeError, "Unknown metric '%s' for CPU '%d' and thre= ad '%d'", + metric, cpu, thread); + return NULL; + } + + pctx =3D expr__ctx_new(); + if (!pctx) + return PyErr_NoMemory(); + + ret =3D prepare_metric(mexp, mexp->metric_events[0], pctx, cpu_idx, threa= d_idx); + if (ret) { + expr__ctx_free(pctx); + errno =3D -ret; + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + if (expr__parse(&result, pctx, mexp->metric_expr)) + result =3D 0.0; + + expr__ctx_free(pctx); + return PyFloat_FromDouble(result); +} + static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { @@ -1554,6 +1673,12 @@ static PyMethodDef pyrf_evlist__methods[] =3D { .ml_flags =3D METH_NOARGS, .ml_doc =3D PyDoc_STR("List of metric names within the evlist.") }, + { + .ml_name =3D "compute_metric", + .ml_meth =3D (PyCFunction)pyrf_evlist__compute_metric, + .ml_flags =3D METH_VARARGS | METH_KEYWORDS, + .ml_doc =3D PyDoc_STR("compute metric for given name, cpu and thread") + }, { .ml_name =3D "mmap", .ml_meth =3D (PyCFunction)pyrf_evlist__mmap, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 1C472275AFA for ; Wed, 23 Jul 2025 23:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313030; cv=none; b=jaf6BqdTplK5atRCKOLtv58jfuEuOAy/SDk7pkJGMKD/QhuC5iLPJsCngMYvDk+3EUelwCrvwvpzowCVC29OOZ5C9VGrvnwVA+YjqmzejdPNWUC6rvLfFH4DmUPBxZYD/mQR8LTsRo1IAQmbTkyc0SQsOrAY5ls9ytC6YCqKw5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313030; c=relaxed/simple; bh=6qy4zQxJd9iObH44/TfA2kLJQsc7FZcMvNtC6t4qI70=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KH6U3wNYYqII+HbyGkhtrDLY8tzv9GY7cNFFpBNui0vVDESF04S56gkBHdmaHer4gQeNrVnrCte8M3JkzvgKZLgvusaVSP40sjem57LQN9kE3L7SlX2kU4O/Hl8mgtElVxkYWH8XkC2deELaf7x0ZY5eYT1yz0F8RLxH3973Nww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ziQdxrP2; arc=none smtp.client-ip=209.85.216.74 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ziQdxrP2" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-31366819969so293605a91.0 for ; Wed, 23 Jul 2025 16:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753313028; x=1753917828; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=P7L/9iYbbAfbCiLjp07E+9VacBofe7FyIakYtK/wA24=; b=ziQdxrP2T/+6sfA55WalwgbnqecKPcn40+CsMLQI6NW95LdnALO42EQnorfelzWtOm YZxKLSPPeRY6GaqRRSGIeLiVgLhe5s630Hl1BheYsq4AoGxx6YGmBrQxSJz0I1Y2w4hh v10vNMitCMcpsdkNpUTO8TbaBDfti+erGqOS1e++JFEA+lbgBr6ZvxJIYGEluuEVdv+N cB/pF96llH35mPBOycfdFHGuXpTeFPYru4UtDwi6qSy4mi9tQC+MwakcWzjgU2dbxkMQ TMGRhLtvGCRM87UiZJ49zD2gt7voxWpZ8KPw5xsv3rQPUqSygbD+O5K1yMfB2/NDAvsN QSrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753313028; x=1753917828; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P7L/9iYbbAfbCiLjp07E+9VacBofe7FyIakYtK/wA24=; b=vaXEoXn4z42gx6iOSxC2qg9e2bwXygatTH05m4ORFoNXADD0jZ/yDOhY4m+lyq39h9 ozt4c0cIZvLYs94lf4EkRahxSXFZtxwJDk4tO5yV5nK1Xu6gADNr905+OEpYZeoCelHi /qPHLDzsz2flMOOx9LH8WezLfnGX3t4QkqGmRByi0rH0Q5rsSYmXl06CXAPo12E5QAYg BFSCLuONIkbHHiOwbVo8GDc1DfpOITgMR0iLqcyD2rpWJhbciJPi29/G2zh83SwsvNmo MpO84CHCuNREELr6P5UCM/Z7Eg7bmIzkPWBDKdLWYsZ9RFxTtryqFng5YHl97cvNvXV6 vUUA== X-Forwarded-Encrypted: i=1; AJvYcCWUjFqpe5TABT+XE99oRDAcJt1k46F7/jmJwVKisNoIOpKemmfCng6mwgqG5FPcGqT35eQmaNs9Q5BT/QY=@vger.kernel.org X-Gm-Message-State: AOJu0YxTpYNCffroTfWyU8VEKxQ8htRNN7gGJ2bngN5MeNXdLxn2AnGK L5ZC7pagLX2lyFrU4JaMvY8QSeTzBxVcnXXJ4dsWdq24FQGsB25W9dlbPQW6CkHpX8PXY4/J+0P 2+H8EDsgsAw== X-Google-Smtp-Source: AGHT+IE/D7PzYjCG9Zlx+Bga7Nh7Tq9VRp0u+XmJK7AFAItxnBwTSW1JYcGN5IoLTTGlCI8VUqfQw2yWYG2l X-Received: from pjbee12.prod.google.com ([2002:a17:90a:fc4c:b0:31c:2fe4:33b8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2e0d:b0:31e:3bbc:e9e6 with SMTP id 98e67ed59e1d1-31e507e61a5mr7087139a91.19.1753313028432; Wed, 23 Jul 2025 16:23:48 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:16 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-16-irogers@google.com> Subject: [PATCH v8 15/16] perf python: Add metrics function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The metrics function returns a list dictionaries describing metrics as strings mapping to strings, except for metric groups that are a string mapping to a list of strings. For example: ``` >>> import perf >>> perf.metrics()[0] {'MetricGroup': ['Power'], 'MetricName': 'C10_Pkg_Residency', 'PMU': 'default_core', 'MetricExpr': 'cstate_pkg@c10\\-residency@ / TSC', 'ScaleUnit': '100%', 'BriefDescription': 'C10 residency percent per packag= e'} ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index bee7c8a69bad..a8ba1379cf21 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -2073,7 +2073,90 @@ static PyObject *pyrf__parse_metrics(PyObject *self,= PyObject *args) return result; } =20 +static PyObject *pyrf__metrics_groups(const struct pmu_metric *pm) +{ + PyObject *groups =3D PyList_New(/*len=3D*/0); + const char *mg =3D pm->metric_group; + + if (!groups) + return NULL; + + while (mg) { + PyObject *val =3D NULL; + const char *sep =3D strchr(mg, ';'); + size_t len =3D sep ? (size_t)(sep - mg) : strlen(mg); + + if (len > 0) { + val =3D PyUnicode_FromStringAndSize(mg, len); + if (val) + PyList_Append(groups, val); + + Py_XDECREF(val); + } + mg =3D sep ? sep + 1 : NULL; + } + return groups; +} + +static int pyrf__metrics_cb(const struct pmu_metric *pm, + const struct pmu_metrics_table *table __maybe_unused, + void *vdata) +{ + PyObject *py_list =3D vdata; + PyObject *dict =3D PyDict_New(); + PyObject *key =3D dict ? PyUnicode_FromString("MetricGroup") : NULL; + PyObject *value =3D key ? pyrf__metrics_groups(pm) : NULL; + + if (!value || PyDict_SetItem(dict, key, value) !=3D 0) { + Py_XDECREF(key); + Py_XDECREF(value); + Py_XDECREF(dict); + return -ENOMEM; + } + + if (!add_to_dict(dict, "MetricName", pm->metric_name) || + !add_to_dict(dict, "PMU", pm->pmu) || + !add_to_dict(dict, "MetricExpr", pm->metric_expr) || + !add_to_dict(dict, "MetricThreshold", pm->metric_threshold) || + !add_to_dict(dict, "ScaleUnit", pm->unit) || + !add_to_dict(dict, "Compat", pm->compat) || + !add_to_dict(dict, "BriefDescription", pm->desc) || + !add_to_dict(dict, "PublicDescription", pm->long_desc) || + PyList_Append(py_list, dict) !=3D 0) { + Py_DECREF(dict); + return -ENOMEM; + } + Py_DECREF(dict); + return 0; +} + +static PyObject *pyrf__metrics(PyObject *self, PyObject *args) +{ + const struct pmu_metrics_table *table =3D pmu_metrics_table__find(); + PyObject *list =3D PyList_New(/*len=3D*/0); + int ret; + + if (!list) + return NULL; + + ret =3D pmu_metrics_table__for_each_metric(table, pyrf__metrics_cb, list); + if (ret) { + Py_DECREF(list); + errno =3D -ret; + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + return list; +} + static PyMethodDef perf__methods[] =3D { + { + .ml_name =3D "metrics", + .ml_meth =3D (PyCFunction) pyrf__metrics, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR( + "Returns a list of metrics represented as string values in dictionaries= .") + }, { .ml_name =3D "tracepoint", .ml_meth =3D (PyCFunction) pyrf__tracepoint, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Mon Oct 6 06:29:00 2025 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 C25DEA95C for ; Wed, 23 Jul 2025 23:23:55 +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=1753313037; cv=none; b=MaWMNnGUom3a9cwkB6GLwExZaL9WfeR/wWraq9Pi+4jJjqns9Ms77Ln8xy7YzkqlWTeapH0dKnkAUcsnN5E+JPF0ysWORRlOesdsHNW4XSM2lJXyKrPoatvisn0045hg0K2JKyUlE9bejUjkq2dpzTRB0YrxnRVOyqQfKUanH5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753313037; c=relaxed/simple; bh=0p2VZhsqQDr6Aw2LuSDZ/RNj1w9ofDx+04KMdddf5DA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=a8ycYCp3/Myc/KQQ3o+hfOxqsbO8BG8CC8ujwkvJw5hYHXunblb5/pkVWkhVJDI8nGLKDyLk6oXoDHBlVzEpOXXaTCuXZf6PDzD1q7z7fYaz1CotIt64S1ewOaxalNRbXOszUw6QK95HONcLhEz6vIR0xAL+tlafOI+fmZcpiHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jbAd1ZAq; 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jbAd1ZAq" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-74927be2ec0so581040b3a.0 for ; Wed, 23 Jul 2025 16:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753313035; x=1753917835; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6NNH/8/lvsRr+ontcNP33Y53kfjTOg19B0JPdMFPpCw=; b=jbAd1ZAqnV7xcoF64uriKfOWJDZH0WWpi0809lrlGyDtGbbhmbkbGuSMCQzcef/AfY MOXMsqtw3eJBwxnVll66qNJyAZW5u2AYHDHPiv2LX/iHx9nr40AEWQLTz7Y0Fl5zBPyG 8Iq3niGsAKUjq7ZZQYLJLmyHPuXwtUgSQnPiHYpyzy8uYepoBeSaokpKfWW7xrz8KVHJ OKB0h876kHQgQ5rgu4ovchI9FVPDCgYvLKRR6jlvFFjKi3Ut2Q/8xkah9mvU0nBC42Cs 7ryUa/UCvUHTglk3Ror3o7jC7keMeNMy3vdVKVQ7DXYyRa8X6juYfGB9jCDP5Szwy9Fb pPZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753313035; x=1753917835; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6NNH/8/lvsRr+ontcNP33Y53kfjTOg19B0JPdMFPpCw=; b=OqSutfmPYkEB++lwa/G1txhasp5F4AD1POjvmzSSGzKk+k2AP2c0FbCW2zR5mzf/H8 WfPvqS3cQlXhQwepK7rKYGGzJKefmcNWdtb9aUlf9wIwpq+vu9/sDsRuwDgAnEcnRWVP Rv0hfcgVTUmMstt/qB58tHPuqMgkT6yrPW8BW78xG0+gslrPaDXUNbJzUKdjdGHvhXB3 2vCiXFLAkeBGfCZYFWWXP0aN0r8HAMR8ityWUdLKIeQceZJHrkcYhHw2Qw157QXl+rpO bfRFWCnmr0crq7tRlVkl4qYhVusCEgdG/iSHzlPWulOjCpCaVHviDNNmeoAV7Yx7rbjm EcNQ== X-Forwarded-Encrypted: i=1; AJvYcCWLo2rLDVRMoOOOsZmJIX7PIq2zup7QblXcd6tEqHOkaoVsT7tQcWV8YgkhJbQzIYSokEBitaZSsGLVdHo=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5MpbESBDpwYmYDbuzUGJkttQR9hxt/JwEVrI4euO903g8gF8V JuyKZ5UnQBXtM7GvXbGqd1Gl0aVj90hh711EPxdYZPY3YcFyAvq1/kuhkHDz6hFtV5Z9y/mUjI8 Tgv81ycr7Ng== X-Google-Smtp-Source: AGHT+IE5/7Km/7y6LL7ZC1nZ1dlArFXrF9Rs15E8zp+UuKlziJbybSsz1F41qW+3osOWRyTHFJkvampGYN5J X-Received: from pfbde7.prod.google.com ([2002:a05:6a00:4687:b0:748:ed01:df48]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2182:b0:736:35d4:f03f with SMTP id d2e1a72fcca58-76034c4cbadmr6204564b3a.6.1753313034970; Wed, 23 Jul 2025 16:23:54 -0700 (PDT) Date: Wed, 23 Jul 2025 16:22:17 -0700 In-Reply-To: <20250723232217.516179-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250723232217.516179-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250723232217.516179-17-irogers@google.com> Subject: [PATCH v8 16/16] perf ilist: Add support for metrics From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , "Masami Hiramatsu (Google)" , Collin Funk , Howard Chu , Weilin Wang , Andi Kleen , "Dr. David Alan Gilbert" , Thomas Richter , Tiezhu Yang , Gautam Menghani , Thomas Falcon , Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change tree nodes to having a value of either Metric or PmuEvent, these values have the ability to match searches, be parsed to create evlists and to give a value per CPU and per thread to display. Use perf.metrics to generate a tree of metrics. Most metrics are placed under their metric group, if the metric group name ends with '_group' then the metric group is placed next to the associated metric. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/python/ilist.py | 232 +++++++++++++++++++++++++++---------- 1 file changed, 170 insertions(+), 62 deletions(-) diff --git a/tools/perf/python/ilist.py b/tools/perf/python/ilist.py index b21f4c93247e..8ecd4a9f5034 100755 --- a/tools/perf/python/ilist.py +++ b/tools/perf/python/ilist.py @@ -2,18 +2,119 @@ # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) """Interactive perf list.""" =20 +from abc import ABC, abstractmethod import argparse -from typing import Any, Dict, Tuple +from dataclasses import dataclass +from typing import Any, Dict, Optional, Tuple +import math import perf from textual import on from textual.app import App, ComposeResult from textual.binding import Binding from textual.containers import Horizontal, HorizontalGroup, Vertical, Vert= icalScroll +from textual.css.query import NoMatches from textual.command import SearchIcon from textual.screen import ModalScreen from textual.widgets import Button, Footer, Header, Input, Label, Sparklin= e, Static, Tree from textual.widgets.tree import TreeNode =20 +def get_info(info: Dict[str, str], key: str): + return (info[key] + "\n") if key in info else "" + +class TreeValue(ABC): + """Abstraction for the data of value in the tree.""" + + @abstractmethod + def name(self) -> str: + pass + + @abstractmethod + def description(self) -> str: + pass + + @abstractmethod + def matches(self, query: str) -> bool: + pass + + @abstractmethod + def parse(self) -> perf.evlist: + pass + + @abstractmethod + def value(self, evlist: perf.evlist, evsel: perf.evsel, cpu: int, thre= ad: int) -> float: + pass + + +@dataclass +class Metric(TreeValue): + """A metric in the tree.""" + metric_name: str + + def name(self) -> str: + return self.metric_name + + def description(self) -> str: + """Find and format metric description.""" + for metric in perf.metrics(): + if metric["MetricName"] !=3D self.metric_name: + continue + desc =3D get_info(metric, "BriefDescription") + desc +=3D get_info(metric, "PublicDescription") + desc +=3D get_info(metric, "MetricExpr") + desc +=3D get_info(metric, "MetricThreshold") + return desc + return "description" + + def matches(self, query: str) -> bool: + return query in self.metric_name + + def parse(self) -> perf.evlist: + return perf.parse_metrics(self.metric_name) + + def value(self, evlist: perf.evlist, evsel: perf.evsel, cpu: int, thre= ad: int) -> float: + val =3D evlist.compute_metric(self.metric_name, cpu, thread) + return 0 if math.isnan(val) else val + + +@dataclass +class PmuEvent(TreeValue): + """A PMU and event within the tree.""" + pmu: str + event: str + + def name(self) -> str: + if self.event.startswith(self.pmu) or ':' in self.event: + return self.event + else: + return f"{self.pmu}/{self.event}/" + + def description(self) -> str: + """Find and format event description for {pmu}/{event}/.""" + for p in perf.pmus(): + if p.name() !=3D self.pmu: + continue + for info in p.events(): + if "name" not in info or info["name"] !=3D self.event: + continue + + desc =3D get_info(info, "topic") + desc +=3D get_info(info, "event_type_desc") + desc +=3D get_info(info, "desc") + desc +=3D get_info(info, "long_desc") + desc +=3D get_info(info, "encoding_desc") + return desc + return "description" + + def matches(self, query: str) -> bool: + return query in self.pmu or query in self.event + + def parse(self) -> perf.evlist: + return perf.parse_events(self.name()) + + def value(self, evlist: perf.evlist, evsel: perf.evsel, cpu: int, thre= ad: int) -> float: + return evsel.read(cpu, thread).val + + class ErrorScreen(ModalScreen[bool]): """Pop up dialog for errors.""" =20 @@ -123,8 +224,9 @@ class IListApp(App): def __init__(self, interval: float) -> None: self.interval =3D interval self.evlist =3D None - self.search_results: list[TreeNode[str]] =3D [] - self.cur_search_result: TreeNode[str] | None =3D None + self.selected: Optional[TreeValue] =3D None + self.search_results: list[TreeNode[TreeValue]] =3D [] + self.cur_search_result: TreeNode[TreeValue] | None =3D None super().__init__() =20 =20 @@ -145,7 +247,7 @@ class IListApp(App): l =3D len(self.search_results) =20 if l < 1: - tree: Tree[str] =3D self.query_one("#pmus", Tree) + tree: Tree[TreeValue] =3D self.query_one("#root", Tree) if previous: tree.action_cursor_up() else: @@ -180,15 +282,15 @@ class IListApp(App): event =3D event.lower() search_label.update(f'Searching for events matching "{event}"') =20 - tree: Tree[str] =3D self.query_one("#pmus", Tree) - def find_search_results(event: str, node: TreeNode[str], \ + tree: Tree[TreeValue] =3D self.query_one("#root", Tree) + def find_search_results(event: str, node: TreeNode[TreeValue],= \ cursor_seen: bool =3D False, \ - match_after_cursor: TreeNode[str] | No= ne =3D None) \ - -> Tuple[bool, TreeNode[str] | None]: + match_after_cursor: TreeNode[TreeValue= ] | None =3D None) \ + -> Tuple[bool, TreeNode[TreeValue] | None]: """Find nodes that match the search remembering the one af= ter the cursor.""" if not cursor_seen and node =3D=3D tree.cursor_node: cursor_seen =3D True - if node.data and event in node.data: + if node.data and node.data.matches(event): if cursor_seen and not match_after_cursor: match_after_cursor =3D node self.search_results.append(node) @@ -202,7 +304,7 @@ class IListApp(App): self.search_results.clear() (_ , self.cur_search_result) =3D find_search_results(event, tr= ee.root) if len(self.search_results) < 1: - self.push_screen(ErrorScreen(f"Failed to find pmu/event {e= vent}")) + self.push_screen(ErrorScreen(f"Failed to find pmu/event or= metric {event}")) search_label.display =3D False elif self.cur_search_result: self.expand_and_select(self.cur_search_result) @@ -223,17 +325,17 @@ class IListApp(App): =20 =20 def action_collapse(self) -> None: - """Collapse the potentially large number of events under a PMU.""" - tree: Tree[str] =3D self.query_one("#pmus", Tree) + """Collapse the part of the tree currently on.""" + tree: Tree[str] =3D self.query_one("#root", Tree) node =3D tree.cursor_node - if node and node.parent and node.parent.parent: + if node and node.parent: node.parent.collapse_all() node.tree.scroll_to_node(node.parent) =20 =20 def update_counts(self) -> None: """Called every interval to update counts.""" - if not self.evlist: + if not self.selected or not self.evlist: return =20 def update_count(cpu: int, count: int): @@ -262,8 +364,7 @@ class IListApp(App): for cpu in evsel.cpus(): aggr =3D 0 for thread in evsel.threads(): - counts =3D evsel.read(cpu, thread) - aggr +=3D counts.val + aggr +=3D self.selected.value(self.evlist, evsel, cpu,= thread) update_count(cpu, aggr) total +=3D aggr update_count(-1, total) @@ -276,47 +377,37 @@ class IListApp(App): self.set_interval(self.interval, self.update_counts) =20 =20 - def set_pmu_and_event(self, pmu: str, event: str) -> None: + def set_selected(self, value: TreeValue) -> None: """Updates the event/description and starts the counters.""" + try: + label_name =3D self.query_one("#event_name", Label) + event_description =3D self.query_one("#event_description", Sta= tic) + lines =3D self.query_one("#lines") + except NoMatches: + # A race with rendering, ignore the update as we can't + # mount the assumed output widgets. + return + + self.selected =3D value + # Remove previous event information. if self.evlist: self.evlist.disable() self.evlist.close() - lines =3D self.query(CounterSparkline) - for line in lines: - line.remove() - lines =3D self.query(Counter) - for line in lines: + old_lines =3D self.query(CounterSparkline) + for line in old_lines: line.remove() + old_counters =3D self.query(Counter) + for counter in old_counters: + counter.remove() =20 - def pmu_event_description(pmu: str, event: str) -> str: - """Find and format event description for {pmu}/{event}/.""" - def get_info(info: Dict[str, str], key: str): - return (info[key] + "\n") if key in info else "" - - for p in perf.pmus(): - if p.name() !=3D pmu: - continue - for info in p.events(): - if "name" not in info or info["name"] !=3D event: - continue - - desc =3D get_info(info, "topic") - desc +=3D get_info(info, "event_type_desc") - desc +=3D get_info(info, "desc") - desc +=3D get_info(info, "long_desc") - desc +=3D get_info(info, "encoding_desc") - return desc - return "description" - - # Parse event, update event text and description. - full_name =3D event if event.startswith(pmu) or ':' in event else = f"{pmu}/{event}/" - self.query_one("#event_name", Label).update(full_name) - self.query_one("#event_description", Static).update(pmu_event_desc= ription(pmu, event)) + # Update event/metric text and description. + label_name.update(value.name()) + event_description.update(value.description()) =20 # Open the event. try: - self.evlist =3D perf.parse_events(full_name) + self.evlist =3D value.parse() if self.evlist: self.evlist.open() self.evlist.enable() @@ -324,13 +415,12 @@ class IListApp(App): self.evlist =3D None =20 if not self.evlist: - self.push_screen(ErrorScreen(f"Failed to open {full_name}")) + self.push_screen(ErrorScreen(f"Failed to open {value.name()}")) return =20 # Add spark lines for all the CPUs. Note, must be done after # open so that the evlist CPUs have been computed by propagate # maps. - lines =3D self.query_one("#lines") line =3D CounterSparkline(cpu=3D-1) lines.mount(line) for cpu in self.evlist.all_cpus(): @@ -345,28 +435,48 @@ class IListApp(App): =20 def compose(self) -> ComposeResult: """Draws the app.""" - def pmu_event_tree() -> Tree: - """Create tree of PMUs with events under.""" - tree: Tree[str] =3D Tree("PMUs", id=3D"pmus") - tree.root.expand() + def metric_event_tree() -> Tree: + """Create tree of PMUs and metricgroups with events or metrics= under.""" + tree: Tree[TreeValue] =3D Tree("Root", id=3D"root") + pmus =3D tree.root.add("PMUs") for pmu in perf.pmus(): pmu_name =3D pmu.name().lower() - pmu_node =3D tree.root.add(pmu_name, data=3Dpmu_name) + pmu_node =3D pmus.add(pmu_name) try: for event in sorted(pmu.events(), key=3Dlambda x: x["n= ame"]): if "name" in event: e =3D event["name"].lower() if "alias" in event: - pmu_node.add_leaf(f'{e} ({event["alias"]})= ', data=3De) + pmu_node.add_leaf(f'{e} ({event["alias"]})= ', data=3DPmuEvent(pmu_name, e)) else: - pmu_node.add_leaf(e, data=3De) + pmu_node.add_leaf(e, data=3DPmuEvent(pmu_n= ame, e)) except: # Reading events may fail with EPERM, ignore. pass + metrics =3D tree.root.add("Metrics") + groups =3D set() + for metric in perf.metrics(): + groups.update(metric["MetricGroup"]) + + def add_metrics_to_tree(node: TreeNode[TreeValue], parent: str= ): + for metric in sorted(perf.metrics(), key=3Dlambda x: x["Me= tricName"]): + if parent in metric["MetricGroup"]: + name =3D metric["MetricName"] + node.add_leaf(name, data=3DMetric(name)) + child_group_name =3D f'{name}_group' + if child_group_name in groups: + add_metrics_to_tree(node.add(child_group_name)= , child_group_name) + + for group in sorted(groups): + if group.endswith('_group'): + continue + add_metrics_to_tree(metrics.add(group), group) + + tree.root.expand() return tree =20 yield Header(id=3D"header") - yield Horizontal(Vertical(pmu_event_tree(), id=3D"events"), + yield Horizontal(Vertical(metric_event_tree(), id=3D"events"), Vertical(Label("event name", id=3D"event_name"), Static("description", markup=3DFalse, id= =3D"event_description"), )) @@ -376,12 +486,10 @@ class IListApp(App): =20 =20 @on(Tree.NodeSelected) - def on_tree_node_selected(self, event: Tree.NodeSelected[str]) -> None: + def on_tree_node_selected(self, event: Tree.NodeSelected[TreeValue]) -= > None: """Called when a tree node is selected, selecting the event.""" - if event.node.parent and event.node.parent.parent: - assert event.node.parent.data is not None - assert event.node.data is not None - self.set_pmu_and_event(event.node.parent.data, event.node.data) + if event.node.data: + self.set_selected(event.node.data) =20 =20 if __name__ =3D=3D "__main__": --=20 2.50.0.727.gbf7dc18ff4-goog