mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:04:41 +01:00
perf jevents: Build support for generating metrics from python
Generate extra-metrics.json and extra-metricgroups.json from python architecture specific scripts. The metrics themselves will be added in later patches. If a build takes place in tools/perf/ then extra-metrics.json and extra-metricgroups.json are generated in that directory and so added to .gitignore. If there is an OUTPUT directory then the tools/perf/pmu-events/arch files are copied to it so the generated extra-metrics.json and extra-metricgroups.json can be added/generated there. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Thomas Falcon <thomas.falcon@intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Benjamin Gray <bgray@linux.ibm.com> Cc: Caleb Biggers <caleb.biggers@intel.com> Cc: Edward Baker <edward.baker@intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Leo Yan <leo.yan@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Perry Taylor <perry.taylor@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Weilin Wang <weilin.wang@intel.com> Cc: Xu Yang <xu.yang_2@nxp.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
7a0ba38911
commit
19eab0efe7
6 changed files with 185 additions and 1 deletions
5
tools/perf/.gitignore
vendored
5
tools/perf/.gitignore
vendored
|
|
@ -43,6 +43,11 @@ pmu-events/metric_test.log
|
|||
pmu-events/empty-pmu-events.log
|
||||
pmu-events/test-empty-pmu-events.c
|
||||
*.shellcheck_log
|
||||
pmu-events/arch/**/extra-metrics.json
|
||||
pmu-events/arch/**/extra-metricgroups.json
|
||||
tests/shell/*.shellcheck_log
|
||||
tests/shell/coresight/*.shellcheck_log
|
||||
tests/shell/lib/*.shellcheck_log
|
||||
feature/
|
||||
libapi/
|
||||
libbpf/
|
||||
|
|
|
|||
|
|
@ -1273,6 +1273,8 @@ ifeq ($(OUTPUT),)
|
|||
pmu-events/metric_test.log \
|
||||
pmu-events/test-empty-pmu-events.c \
|
||||
pmu-events/empty-pmu-events.log
|
||||
$(Q)find pmu-events/arch -name 'extra-metrics.json' -delete -o \
|
||||
-name 'extra-metricgroups.json' -delete
|
||||
else # When an OUTPUT directory is present, clean up the copied pmu-events/arch directory.
|
||||
$(call QUIET_CLEAN, pmu-events) $(RM) -r $(OUTPUT)pmu-events/arch \
|
||||
$(OUTPUT)pmu-events/pmu-events.c \
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ $(PMU_EVENTS_C): $(EMPTY_PMU_EVENTS_C)
|
|||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)cp $< $@
|
||||
else
|
||||
# Functions to extract the model from a extra-metrics.json or extra-metricgroups.json path.
|
||||
model_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/extra-metric.*\.json@\1@')
|
||||
vendor_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/[^/]*/extra-metric.*\.json@\1@')
|
||||
|
||||
# Copy checked-in json to OUTPUT for generation if it's an out of source build
|
||||
ifneq ($(OUTPUT),)
|
||||
# Remove all output directories when any source directory timestamp changes
|
||||
|
|
@ -48,7 +52,53 @@ $(LEGACY_CACHE_JSON): $(LEGACY_CACHE_PY) $(JSON_DIRS_ROOT)
|
|||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)$(PYTHON) $(LEGACY_CACHE_PY) > $@
|
||||
|
||||
GEN_JSON = $(patsubst %,$(OUTPUT)%,$(JSON)) $(LEGACY_CACHE_JSON) $(JSON_DIRS)
|
||||
GEN_METRIC_DEPS := pmu-events/metric.py
|
||||
|
||||
# Generate AMD Json
|
||||
ZENS = $(shell ls -d pmu-events/arch/x86/amdzen*)
|
||||
ZEN_METRICS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metrics.json)
|
||||
ZEN_METRICGROUPS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metricgroups.json)
|
||||
|
||||
$(ZEN_METRICS): pmu-events/amd_metrics.py $(GEN_METRIC_DEPS)
|
||||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)$(PYTHON) $< $(call model_name,$@) arch > $@
|
||||
|
||||
$(ZEN_METRICGROUPS): pmu-events/amd_metrics.py $(GEN_METRIC_DEPS)
|
||||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)$(PYTHON) $< -metricgroups $(call model_name,$@) arch > $@
|
||||
|
||||
# Generate ARM Json
|
||||
ARMS = $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn)
|
||||
ARM_METRICS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metrics.json)
|
||||
ARM_METRICGROUPS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metricgroups.json)
|
||||
|
||||
$(ARM_METRICS): pmu-events/arm64_metrics.py $(GEN_METRIC_DEPS)
|
||||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)$(PYTHON) $< $(call vendor_name,$@) $(call model_name,$@) arch > $@
|
||||
|
||||
$(ARM_METRICGROUPS): pmu-events/arm64_metrics.py $(GEN_METRIC_DEPS)
|
||||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)$(PYTHON) $< -metricgroups $(call vendor_name,$@) $(call model_name,$@) arch > $@
|
||||
|
||||
# Generate Intel Json
|
||||
INTELS = $(shell ls -d pmu-events/arch/x86/*|grep -v amdzen|grep -v mapfile.csv)
|
||||
INTEL_METRICS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metrics.json)
|
||||
INTEL_METRICGROUPS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metricgroups.json)
|
||||
|
||||
$(INTEL_METRICS): pmu-events/intel_metrics.py $(GEN_METRIC_DEPS)
|
||||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)$(PYTHON) $< $(call model_name,$@) arch > $@
|
||||
|
||||
$(INTEL_METRICGROUPS): pmu-events/intel_metrics.py $(GEN_METRIC_DEPS)
|
||||
$(call rule_mkdir)
|
||||
$(Q)$(call echo-cmd,gen)$(PYTHON) $< -metricgroups $(call model_name,$@) arch > $@
|
||||
|
||||
GEN_JSON = $(patsubst %,$(OUTPUT)%,$(JSON)) \
|
||||
$(LEGACY_CACHE_JSON) \
|
||||
$(JSON_DIRS) \
|
||||
$(ZEN_METRICS) $(ZEN_METRICGROUPS) \
|
||||
$(ARM_METRICS) $(ARM_METRICGROUPS) \
|
||||
$(INTEL_METRICS) $(INTEL_METRICGROUPS)
|
||||
|
||||
$(METRIC_TEST_LOG): $(METRIC_TEST_PY) $(METRIC_PY)
|
||||
$(call rule_mkdir)
|
||||
|
|
|
|||
42
tools/perf/pmu-events/amd_metrics.py
Executable file
42
tools/perf/pmu-events/amd_metrics.py
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
||||
import argparse
|
||||
import os
|
||||
from metric import (
|
||||
JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, MetricGroup)
|
||||
|
||||
# Global command line arguments.
|
||||
_args = None
|
||||
|
||||
|
||||
def main() -> None:
|
||||
global _args
|
||||
|
||||
def dir_path(path: str) -> str:
|
||||
"""Validate path is a directory for argparse."""
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
raise argparse.ArgumentTypeError(
|
||||
f'\'{path}\' is not a valid directory')
|
||||
|
||||
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(
|
||||
'events_path',
|
||||
type=dir_path,
|
||||
help='Root of tree containing architecture directories containing json files'
|
||||
)
|
||||
_args = parser.parse_args()
|
||||
|
||||
all_metrics = MetricGroup("", [])
|
||||
|
||||
if _args.metricgroups:
|
||||
print(JsonEncodeMetricGroupDescriptions(all_metrics))
|
||||
else:
|
||||
print(JsonEncodeMetric(all_metrics))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
43
tools/perf/pmu-events/arm64_metrics.py
Executable file
43
tools/perf/pmu-events/arm64_metrics.py
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
||||
import argparse
|
||||
import os
|
||||
from metric import (
|
||||
JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, MetricGroup)
|
||||
|
||||
# Global command line arguments.
|
||||
_args = None
|
||||
|
||||
|
||||
def main() -> None:
|
||||
global _args
|
||||
|
||||
def dir_path(path: str) -> str:
|
||||
"""Validate path is a directory for argparse."""
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
raise argparse.ArgumentTypeError(
|
||||
f'\'{path}\' is not a valid directory')
|
||||
|
||||
parser = argparse.ArgumentParser(description="ARM perf json generator")
|
||||
parser.add_argument(
|
||||
"-metricgroups", help="Generate metricgroups data", action='store_true')
|
||||
parser.add_argument("vendor", help="e.g. arm")
|
||||
parser.add_argument("model", help="e.g. neoverse-n1")
|
||||
parser.add_argument(
|
||||
'events_path',
|
||||
type=dir_path,
|
||||
help='Root of tree containing architecture directories containing json files'
|
||||
)
|
||||
_args = parser.parse_args()
|
||||
|
||||
all_metrics = MetricGroup("", [])
|
||||
|
||||
if _args.metricgroups:
|
||||
print(JsonEncodeMetricGroupDescriptions(all_metrics))
|
||||
else:
|
||||
print(JsonEncodeMetric(all_metrics))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
42
tools/perf/pmu-events/intel_metrics.py
Executable file
42
tools/perf/pmu-events/intel_metrics.py
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
||||
import argparse
|
||||
import os
|
||||
from metric import (
|
||||
JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, MetricGroup)
|
||||
|
||||
# Global command line arguments.
|
||||
_args = None
|
||||
|
||||
|
||||
def main() -> None:
|
||||
global _args
|
||||
|
||||
def dir_path(path: str) -> str:
|
||||
"""Validate path is a directory for argparse."""
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
raise argparse.ArgumentTypeError(
|
||||
f'\'{path}\' is not a valid directory')
|
||||
|
||||
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(
|
||||
'events_path',
|
||||
type=dir_path,
|
||||
help='Root of tree containing architecture directories containing json files'
|
||||
)
|
||||
_args = parser.parse_args()
|
||||
|
||||
all_metrics = MetricGroup("", [])
|
||||
|
||||
if _args.metricgroups:
|
||||
print(JsonEncodeMetricGroupDescriptions(all_metrics))
|
||||
else:
|
||||
print(JsonEncodeMetric(all_metrics))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue