Linux Perf Users
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Ian Rogers <irogers@google.com>
Subject: [PATCH 4/8] perf pmu-events: Batch metric generation and scope via mapfile.csv
Date: Sat,  5 Dec 2026 18:11:43 -0800	[thread overview]
Message-ID: <20261206021147.3036701-5-irogers@google.com> (raw)
In-Reply-To: <20261206021147.3036701-1-irogers@google.com>

Previously, each architectural metric generator (amd_metrics.py,
arm64_metrics.py, intel_metrics.py) generated a single file
(extra-metrics.json or extra-metricgroups.json) for one model per
process, and metric.LoadEvents() walked the entire parent directory
("..") on every invocation to populate all_events_all_models. On x86,
that meant every AMD model parsed all Intel JSONs and every Intel model
parsed all AMD JSONs, repeated across 136 separate Python invocations.

Add mapfile.csv vendor scoping and multi-model batch helpers to
metric.py:
- MapfileVendorModels() reads arch_dir/mapfile.csv and returns only
  models belonging to the same vendor (by vendor subdirectory prefix
  such as "arm/" on arm64, or by CPUID prefix such as "AuthenticAMD" /
  "GenuineIntel" on x86).
- LoadAllModelEvents() collects EventName/ArchStdEvent names across
  those vendor-scoped model directories so AMD and Intel no longer load
  each other's event tables.
- LoadEvents() clears all_pmus and experimental_events before loading a
  model so repeated calls in one process do not leak state, accepts an
  optional preloaded_all_events set, and automatically applies
  mapfile.csv vendor scoping when called standalone.
- WriteMetricsOutput() writes both extra-metrics.json and
  extra-metricgroups.json for a model in one pass.

Extend amd_metrics.py, arm64_metrics.py, and intel_metrics.py with an
--output-dir option accepting a comma-separated list of models while
preserving the existing single-model stdout CLI unchanged. Add unit
tests for mapfile vendor scoping and LoadEvents() state isolation in
metric_test.py.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/pmu-events/amd_metrics.py   |  70 ++++++++-----
 tools/perf/pmu-events/arm64_metrics.py |  45 +++++---
 tools/perf/pmu-events/intel_metrics.py |  87 ++++++++++------
 tools/perf/pmu-events/metric.py        | 139 +++++++++++++++++++++----
 tools/perf/pmu-events/metric_test.py   |  65 ++++++++++++
 5 files changed, 312 insertions(+), 94 deletions(-)

diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py
index 42569b9153f4..3768fa875cd5 100755
--- a/tools/perf/pmu-events/amd_metrics.py
+++ b/tools/perf/pmu-events/amd_metrics.py
@@ -6,8 +6,9 @@ import os
 from typing import Optional, Union
 from common_metrics import Cycles
 from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
-                    JsonEncodeMetricGroupDescriptions, Literal, LoadEvents,
-                    Metric, MetricGroup, Select)
+                    JsonEncodeMetricGroupDescriptions, Literal,
+                    LoadAllModelEvents, LoadEvents, Metric, MetricGroup,
+                    Select, WriteMetricsOutput)
 
 # Global command line arguments.
 _args = None
@@ -496,7 +497,6 @@ def UncoreL3():
 
 def main() -> None:
     global _args
-    global _zen_model
 
     def dir_path(path: str) -> str:
         """Validate path is a directory for argparse."""
@@ -508,37 +508,55 @@ def main() -> None:
     parser = argparse.ArgumentParser(description="AMD perf json generator")
     parser.add_argument(
         "-metricgroups", help="Generate metricgroups data", action='store_true')
-    parser.add_argument("model", help="e.g. amdzen[123]")
+    parser.add_argument(
+        "--output-dir",
+        default=None,
+        help="Write both extra-metrics.json and extra-metricgroups.json under this root directory")
+    parser.add_argument("model", help="e.g. amdzen[123] (comma-separated with --output-dir)")
     parser.add_argument(
         'events_path',
         type=dir_path,
         help='Root of tree containing architecture directories containing json files'
     )
     _args = parser.parse_args()
+    if _args.output_dir and _args.metricgroups:
+        parser.error("--output-dir cannot be combined with -metricgroups")
+    if not _args.output_dir and "," in _args.model:
+        parser.error("Multiple comma-separated models require --output-dir")
+
+    def generate_model(model: str, preloaded_all_events=None) -> MetricGroup:
+        global _zen_model
+        _args.model = model
+        directory = f"{_args.events_path}/x86/{model}/"
+        LoadEvents(directory, preloaded_all_events=preloaded_all_events)
+        _zen_model = int(model[6:])
+        return MetricGroup("", [
+            AmdBr(),
+            AmdCtxSw(),
+            AmdDtlb(),
+            AmdIotlb(),
+            AmdItlb(),
+            AmdLdSt(),
+            AmdUpc(),
+            Cycles(),
+            Idle(),
+            Rapl(),
+            UncoreL3(),
+        ])
 
-    directory = f"{_args.events_path}/x86/{_args.model}/"
-    LoadEvents(directory)
-
-    _zen_model = int(_args.model[6:])
-
-    all_metrics = MetricGroup("", [
-        AmdBr(),
-        AmdCtxSw(),
-        AmdDtlb(),
-        AmdIotlb(),
-        AmdItlb(),
-        AmdLdSt(),
-        AmdUpc(),
-        Cycles(),
-        Idle(),
-        Rapl(),
-        UncoreL3(),
-    ])
-
-    if _args.metricgroups:
-        print(JsonEncodeMetricGroupDescriptions(all_metrics))
+    if _args.output_dir:
+        models = [m.strip() for m in _args.model.split(",") if m.strip()]
+        if models:
+            preloaded = LoadAllModelEvents(f"{_args.events_path}/x86", models[0])
+            for model in models:
+                WriteMetricsOutput(_args.output_dir, f"x86/{model}",
+                                   generate_model(model, preloaded))
     else:
-        print(JsonEncodeMetric(all_metrics))
+        all_metrics = generate_model(_args.model)
+        if _args.metricgroups:
+            print(JsonEncodeMetricGroupDescriptions(all_metrics))
+        else:
+            print(JsonEncodeMetric(all_metrics))
 
 
 if __name__ == '__main__':
diff --git a/tools/perf/pmu-events/arm64_metrics.py b/tools/perf/pmu-events/arm64_metrics.py
index 4ecda96d11fa..6fb7068c0051 100755
--- a/tools/perf/pmu-events/arm64_metrics.py
+++ b/tools/perf/pmu-events/arm64_metrics.py
@@ -2,8 +2,9 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 import argparse
 import os
-from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, LoadEvents,
-                    MetricGroup)
+from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
+                    LoadAllModelEvents, LoadEvents, MetricGroup,
+                    WriteMetricsOutput)
 from common_metrics import Cycles
 
 # Global command line arguments.
@@ -23,26 +24,46 @@ def main() -> None:
     parser = argparse.ArgumentParser(description="ARM perf json generator")
     parser.add_argument(
         "-metricgroups", help="Generate metricgroups data", action='store_true')
+    parser.add_argument(
+        "--output-dir",
+        default=None,
+        help="Write both extra-metrics.json and extra-metricgroups.json under this root directory")
     parser.add_argument("vendor", help="e.g. arm")
-    parser.add_argument("model", help="e.g. neoverse-n1")
+    parser.add_argument("model", help="e.g. neoverse-n1 (comma-separated with --output-dir)")
     parser.add_argument(
         'events_path',
         type=dir_path,
         help='Root of tree containing architecture directories containing json files'
     )
     _args = parser.parse_args()
+    if _args.output_dir and _args.metricgroups:
+        parser.error("--output-dir cannot be combined with -metricgroups")
+    if not _args.output_dir and "," in _args.model:
+        parser.error("Multiple comma-separated models require --output-dir")
 
-    directory = f"{_args.events_path}/arm64/{_args.vendor}/{_args.model}/"
-    LoadEvents(directory)
-
-    all_metrics = MetricGroup("", [
-        Cycles(),
-    ])
+    def generate_model(model: str, preloaded_all_events=None) -> MetricGroup:
+        _args.model = model
+        directory = f"{_args.events_path}/arm64/{_args.vendor}/{model}/"
+        LoadEvents(directory, preloaded_all_events=preloaded_all_events)
+        return MetricGroup("", [
+            Cycles(),
+        ])
 
-    if _args.metricgroups:
-        print(JsonEncodeMetricGroupDescriptions(all_metrics))
+    if _args.output_dir:
+        models = [m.strip() for m in _args.model.split(",") if m.strip()]
+        if models:
+            preloaded = LoadAllModelEvents(
+                f"{_args.events_path}/arm64",
+                f"{_args.vendor}/{models[0]}")
+            for model in models:
+                WriteMetricsOutput(_args.output_dir, f"arm64/{_args.vendor}/{model}",
+                                   generate_model(model, preloaded))
     else:
-        print(JsonEncodeMetric(all_metrics))
+        all_metrics = generate_model(_args.model)
+        if _args.metricgroups:
+            print(JsonEncodeMetricGroupDescriptions(all_metrics))
+        else:
+            print(JsonEncodeMetric(all_metrics))
 
 
 if __name__ == '__main__':
diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
index 4fd5c1de4333..62881509d38c 100755
--- a/tools/perf/pmu-events/intel_metrics.py
+++ b/tools/perf/pmu-events/intel_metrics.py
@@ -9,8 +9,9 @@ from typing import Optional, Union
 from common_metrics import Cycles
 from metric import (d_ratio, has_event, max, aggr_nr, CheckPmu, Constant, Event,
                     Expression, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
-                    Literal, LoadEvents, Metric, MetricConstraint, MetricGroup,
-                    MetricRef, Select)
+                    Literal, LoadAllModelEvents, LoadEvents, Metric,
+                    MetricConstraint, MetricGroup, MetricRef, Select,
+                    WriteMetricsOutput)
 
 # Global command line arguments.
 _args = None
@@ -1139,46 +1140,64 @@ def main() -> None:
     parser = argparse.ArgumentParser(description="Intel perf json generator")
     parser.add_argument(
         "-metricgroups", help="Generate metricgroups data", action='store_true')
-    parser.add_argument("model", help="e.g. skylakex")
+    parser.add_argument(
+        "--output-dir",
+        default=None,
+        help="Write both extra-metrics.json and extra-metricgroups.json under this root directory")
+    parser.add_argument("model", help="e.g. skylakex (comma-separated with --output-dir)")
     parser.add_argument(
         'events_path',
         type=dir_path,
         help='Root of tree containing architecture directories containing json files'
     )
     _args = parser.parse_args()
+    if _args.output_dir and _args.metricgroups:
+        parser.error("--output-dir cannot be combined with -metricgroups")
+    if not _args.output_dir and "," in _args.model:
+        parser.error("Multiple comma-separated models require --output-dir")
+
+    def generate_model(model: str, preloaded_all_events=None) -> MetricGroup:
+        _args.model = model
+        directory = f"{_args.events_path}/x86/{model}/"
+        LoadEvents(directory, preloaded_all_events=preloaded_all_events)
+        return MetricGroup("", [
+            Cycles(),
+            Idle(),
+            Rapl(),
+            Smi(),
+            Tsx(),
+            IntelBr(),
+            IntelCtxSw(),
+            IntelFpu(),
+            IntelIlp(),
+            IntelIotlb(),
+            IntelL2(),
+            IntelLdSt(),
+            IntelMissLat(),
+            IntelMlp(),
+            IntelPorts(),
+            IntelSwpf(),
+            UncoreCState(),
+            UncoreDir(),
+            UncoreMem(),
+            UncoreMemBw(),
+            UncoreMemSat(),
+            UncoreUpiBw(),
+        ])
 
-    directory = f"{_args.events_path}/x86/{_args.model}/"
-    LoadEvents(directory)
-
-    all_metrics = MetricGroup("", [
-        Cycles(),
-        Idle(),
-        Rapl(),
-        Smi(),
-        Tsx(),
-        IntelBr(),
-        IntelCtxSw(),
-        IntelFpu(),
-        IntelIlp(),
-        IntelIotlb(),
-        IntelL2(),
-        IntelLdSt(),
-        IntelMissLat(),
-        IntelMlp(),
-        IntelPorts(),
-        IntelSwpf(),
-        UncoreCState(),
-        UncoreDir(),
-        UncoreMem(),
-        UncoreMemBw(),
-        UncoreMemSat(),
-        UncoreUpiBw(),
-    ])
-
-    if _args.metricgroups:
-        print(JsonEncodeMetricGroupDescriptions(all_metrics))
+    if _args.output_dir:
+        models = [m.strip() for m in _args.model.split(",") if m.strip()]
+        if models:
+            preloaded = LoadAllModelEvents(f"{_args.events_path}/x86", models[0])
+            for model in models:
+                WriteMetricsOutput(_args.output_dir, f"x86/{model}",
+                                   generate_model(model, preloaded))
     else:
-        print(JsonEncodeMetric(all_metrics))
+        all_metrics = generate_model(_args.model)
+        if _args.metricgroups:
+            print(JsonEncodeMetricGroupDescriptions(all_metrics))
+        else:
+            print(JsonEncodeMetric(all_metrics))
 
 
 if __name__ == '__main__':
diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
index f7d5ab6143ee..5608d4464579 100644
--- a/tools/perf/pmu-events/metric.py
+++ b/tools/perf/pmu-events/metric.py
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 """Parse or generate representations of perf metrics."""
 import ast
+import csv
 import decimal
 import json
 import os
@@ -32,10 +33,98 @@ def _is_valid_event_json(filename: str) -> bool:
   return True
 
 
-def LoadEvents(directory: str) -> None:
+def _read_mapfile_rows(arch_dir: str) -> List[Tuple[str, str]]:
+  """Return (cpuid, model_relpath) pairs from arch_dir/mapfile.csv."""
+  mapfile = os.path.join(arch_dir, "mapfile.csv")
+  if not os.path.isfile(mapfile):
+    return []
+  rows: List[Tuple[str, str]] = []
+  with open(mapfile, encoding="utf-8") as f:
+    reader = csv.reader(f)
+    first = True
+    for row in reader:
+      if first:
+        first = False
+        continue
+      if not row or row[0].startswith("#") or len(row) < 3:
+        continue
+      rows.append((row[0], row[2]))
+  return rows
+
+
+def MapfileVendorModels(arch_dir: str, model_rel: str) -> List[str]:
+  """Return model paths in arch_dir/mapfile.csv sharing model_rel's vendor.
+
+  For vendor-subdirectory architectures (e.g. arm64 "arm/neoverse-n1"),
+  matches models under the same vendor directory prefix. For flat
+  architectures (e.g. x86 "skylake" or "amdzen4"), matches models whose
+  CPUID prefix (e.g. "GenuineIntel" or "AuthenticAMD") matches model_rel.
+  """
+  rows = _read_mapfile_rows(arch_dir)
+  if not rows:
+    return []
+  if "/" in model_rel:
+    vendor_prefix = model_rel.split("/", 1)[0] + "/"
+    return sorted({m for _, m in rows if m.startswith(vendor_prefix)})
+  vendors = {cpuid.split("-", 1)[0] for cpuid, m in rows if m == model_rel}
+  if not vendors:
+    return []
+  return sorted({m for cpuid, m in rows if cpuid.split("-", 1)[0] in vendors})
+
+
+def _load_event_names_in_dir(path_root: str) -> Set[str]:
+  """Collect EventName/ArchStdEvent entries from valid JSON files under path_root."""
+  events: Set[str] = set()
+  for root, dirs, files in os.walk(path_root):
+    dirs[:] = [d for d in dirs if not d.startswith('.') and '.' not in d]
+    for filename in files:
+      path = f"{root}/{filename}"
+      if _is_valid_event_json(filename) and os.path.isfile(path):
+        try:
+          with open(path, encoding="utf-8") as f:
+            data = json.load(f)
+        except json.decoder.JSONDecodeError:
+          # Ignore partially written JSON files if present.
+          continue
+        if not isinstance(data, list):
+          continue
+        for x in data:
+          if not isinstance(x, dict):
+            continue
+          if "EventName" in x:
+            events.add(x["EventName"])
+          elif "ArchStdEvent" in x:
+            events.add(x["ArchStdEvent"])
+  return events
+
+
+def LoadAllModelEvents(arch_dir: str,
+                       model_rel: Optional[str] = None) -> Set[str]:
+  """Collect all event names across relevant models under arch_dir.
+
+  When model_rel is given and arch_dir/mapfile.csv lists models for that
+  vendor, only those vendor model directories are scanned (avoiding loading
+  AMD models on Intel and vice versa). Otherwise scans all of arch_dir.
+  """
+  if model_rel:
+    models = MapfileVendorModels(arch_dir, model_rel)
+    if models:
+      events: Set[str] = set()
+      for model in models:
+        model_dir = os.path.join(arch_dir, model)
+        if os.path.isdir(model_dir):
+          events |= _load_event_names_in_dir(model_dir)
+      return events
+  return _load_event_names_in_dir(arch_dir)
+
+
+def LoadEvents(directory: str,
+               preloaded_all_events: Optional[Set[str]] = None) -> None:
   """Populate a global set of all known events for the purpose of validating Event names"""
   global all_events
   global all_events_all_models
+  all_pmus.clear()
+  experimental_events.clear()
   all_events = {
       "context\\-switches",
       "cpu\\-cycles",
@@ -66,27 +155,20 @@ def LoadEvents(directory: str) -> None:
             experimental_events.add(x["EventName"])
         elif "ArchStdEvent" in x:
           all_events.add(x["ArchStdEvent"])
-  all_events_all_models = all_events.copy()
-  for root, dirs, files in os.walk(directory + ".."):
-    dirs[:] = [d for d in dirs if not d.startswith('.') and '.' not in d]
-    for filename in files:
-      path = f"{root}/{filename}"
-      if _is_valid_event_json(filename) and os.path.isfile(path):
-        try:
-          with open(path, encoding="utf-8") as f:
-            data = json.load(f)
-        except json.decoder.JSONDecodeError:
-          # Ignore partially written JSON files if present.
-          continue
-        if not isinstance(data, list):
-          continue
-        for x in data:
-          if not isinstance(x, dict):
-            continue
-          if "EventName" in x:
-            all_events_all_models.add(x["EventName"])
-          elif "ArchStdEvent" in x:
-            all_events_all_models.add(x["ArchStdEvent"])
+  if preloaded_all_events is not None:
+    all_events_all_models = all_events | preloaded_all_events
+  else:
+    norm_dir = os.path.normpath(directory)
+    parent = os.path.dirname(norm_dir)
+    grandparent = os.path.dirname(parent)
+    if os.path.isfile(os.path.join(parent, "mapfile.csv")):
+      model_rel = os.path.basename(norm_dir)
+      all_events_all_models = all_events | LoadAllModelEvents(parent, model_rel)
+    elif os.path.isfile(os.path.join(grandparent, "mapfile.csv")):
+      model_rel = f"{os.path.basename(parent)}/{os.path.basename(norm_dir)}"
+      all_events_all_models = all_events | LoadAllModelEvents(grandparent, model_rel)
+    else:
+      all_events_all_models = all_events | LoadAllModelEvents(parent)
 
 
 def CheckPmu(name: str) -> bool:
@@ -748,6 +830,19 @@ def JsonEncodeMetricGroupDescriptions(x: MetricGroup):
   return json.dumps(x.ToMetricGroupDescriptions(), indent=2)
 
 
+def WriteMetricsOutput(output_dir: str, rel_model_dir: str,
+                       all_metrics: MetricGroup) -> None:
+  """Write extra-metrics.json and extra-metricgroups.json for a model."""
+  model_out = os.path.join(output_dir, rel_model_dir)
+  os.makedirs(model_out, exist_ok=True)
+  with open(os.path.join(model_out, 'extra-metrics.json'), 'w',
+            encoding='utf-8') as f:
+    f.write(JsonEncodeMetric(all_metrics) + '\n')
+  with open(os.path.join(model_out, 'extra-metricgroups.json'), 'w',
+            encoding='utf-8') as f:
+    f.write(JsonEncodeMetricGroupDescriptions(all_metrics) + '\n')
+
+
 class _RewriteIfExpToSelect(ast.NodeTransformer):
   """Transformer to convert if-else nodes to Select expressions."""
 
diff --git a/tools/perf/pmu-events/metric_test.py b/tools/perf/pmu-events/metric_test.py
index 8acfe4652b55..6fe53a9dc824 100755
--- a/tools/perf/pmu-events/metric_test.py
+++ b/tools/perf/pmu-events/metric_test.py
@@ -1,9 +1,15 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+import os
+import tempfile
 import unittest
+import metric
 from metric import Constant
 from metric import Event
 from metric import Expression
+from metric import LoadAllModelEvents
+from metric import LoadEvents
+from metric import MapfileVendorModels
 from metric import ParsePerfJson
 from metric import RewriteMetricsInTermsOfOthers
 
@@ -168,5 +174,64 @@ class TestMetricExpressions(unittest.TestCase):
     self.assertEqual(RewriteMetricsInTermsOfOthers(before), after)
     Expression.__eq__ = None
 
+  def test_MapfileVendorScoping(self):
+    with tempfile.TemporaryDirectory() as tmp:
+      x86 = os.path.join(tmp, 'x86')
+      for d in ('amdzen1', 'amdzen2', 'skylake', 'icelake'):
+        os.makedirs(os.path.join(x86, d))
+      with open(os.path.join(x86, 'mapfile.csv'), 'w', encoding='utf-8') as f:
+        f.write('Family-model,Version,Filename,EventType\n')
+        f.write('AuthenticAMD-23-01,v1,amdzen1,core\n')
+        f.write('AuthenticAMD-23-31,v1,amdzen2,core\n')
+        f.write('GenuineIntel-6-4E,v1,skylake,core\n')
+        f.write('GenuineIntel-6-6A,v1,icelake,core\n')
+      with open(os.path.join(x86, 'amdzen1', 'core.json'), 'w', encoding='utf-8') as f:
+        f.write('[{"EventName": "AMD_EVT_1", "Unit": "amd_pmu", "Experimental": "1"}]\n')
+      with open(os.path.join(x86, 'amdzen2', 'core.json'), 'w', encoding='utf-8') as f:
+        f.write('[{"EventName": "AMD_EVT_2"}]\n')
+      with open(os.path.join(x86, 'skylake', 'core.json'), 'w', encoding='utf-8') as f:
+        f.write('[{"EventName": "INTEL_EVT_1", "Unit": "intel_pmu"}]\n')
+      with open(os.path.join(x86, 'icelake', 'core.json'), 'w', encoding='utf-8') as f:
+        f.write('[{"EventName": "INTEL_EVT_2"}]\n')
+
+      self.assertEqual(MapfileVendorModels(x86, 'amdzen1'), ['amdzen1', 'amdzen2'])
+      self.assertEqual(MapfileVendorModels(x86, 'skylake'), ['icelake', 'skylake'])
+      self.assertEqual(LoadAllModelEvents(x86, 'amdzen1'), {'AMD_EVT_1', 'AMD_EVT_2'})
+      self.assertEqual(LoadAllModelEvents(x86, 'skylake'), {'INTEL_EVT_1', 'INTEL_EVT_2'})
+
+      arm64 = os.path.join(tmp, 'arm64')
+      for d in ('arm/neoverse-n1', 'arm/neoverse-v1', 'ampere/ampereone'):
+        os.makedirs(os.path.join(arm64, d))
+      with open(os.path.join(arm64, 'mapfile.csv'), 'w', encoding='utf-8') as f:
+        f.write('MIDR,Version,JSON/file/pathname,Type\n')
+        f.write('0x410fd0c0,v1,arm/neoverse-n1,core\n')
+        f.write('0x410fd400,v1,arm/neoverse-v1,core\n')
+        f.write('0xc00fac30,v1,ampere/ampereone,core\n')
+      self.assertEqual(
+          MapfileVendorModels(arm64, 'arm/neoverse-n1'),
+          ['arm/neoverse-n1', 'arm/neoverse-v1'])
+
+      saved = (metric.all_events, metric.all_events_all_models,
+               set(metric.all_pmus), set(metric.experimental_events))
+      try:
+        LoadEvents(os.path.join(x86, 'amdzen1'))
+        self.assertIn('AMD_EVT_2', metric.all_events_all_models)
+        self.assertNotIn('INTEL_EVT_1', metric.all_events_all_models)
+        self.assertIn('amd_pmu', metric.all_pmus)
+        self.assertIn('AMD_EVT_1', metric.experimental_events)
+
+        LoadEvents(os.path.join(x86, 'skylake'))
+        self.assertIn('INTEL_EVT_2', metric.all_events_all_models)
+        self.assertNotIn('AMD_EVT_1', metric.all_events_all_models)
+        self.assertNotIn('amd_pmu', metric.all_pmus)
+        self.assertIn('intel_pmu', metric.all_pmus)
+        self.assertEqual(metric.experimental_events, set())
+      finally:
+        metric.all_events, metric.all_events_all_models = saved[0], saved[1]
+        metric.all_pmus.clear()
+        metric.all_pmus.update(saved[2])
+        metric.experimental_events.clear()
+        metric.experimental_events.update(saved[3])
+
 if __name__ == '__main__':
   unittest.main()
-- 
2.56.1.915.g69d5ec7298-goog


  parent reply	other threads:[~2026-12-06  2:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  2:11 [PATCH 0/8] perf build: Avoid pmu-events copies and improve build parallelism Ian Rogers
2026-12-06  2:11 ` [PATCH 1/8] perf pmu-events: Ignore backup and non-event JSON files in metric.py Ian Rogers
2026-12-06  2:22   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 2/8] perf jevents: Support --gen-dir/--gen-manifest overlay and ignore backups Ian Rogers
2026-12-06  2:23   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 3/8] perf build: Avoid copying pmu-events JSON files into OUTPUT Ian Rogers
2026-12-06  2:26   ` sashiko-bot
2026-12-06  2:11 ` Ian Rogers [this message]
2026-12-06  2:28   ` [PATCH 4/8] perf pmu-events: Batch metric generation and scope via mapfile.csv sashiko-bot
2026-12-06  2:11 ` [PATCH 5/8] perf build: Batch metric JSON generation in pmu-events/Build Ian Rogers
2026-12-06  2:26   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 6/8] perf build: Run pmu-events tests in parallel with jevents.py Ian Rogers
2026-12-06  2:11 ` [PATCH 7/8] perf build: Depend on lib*-headers instead of archives in prepare Ian Rogers
2026-12-06  2:11 ` [PATCH 8/8] perf tests make: Only run shellcheck, mypy and pylint in pure builds Ian Rogers
2026-12-06  2:22   ` sashiko-bot
2026-12-06  2:28 ` [PATCH 0/8] perf build: Avoid pmu-events copies and improve build parallelism sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206021147.3036701-5-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox