mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
perf jevents: Don't rewrite metrics across PMUs
Don't rewrite metrics across PMUs as the result events likely won't be found. Identify metrics with a pair of PMU name and metric name. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Kan Liang <kan.liang@linux.intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ahmad Yasin <ahmad.yasin@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Caleb Biggers <caleb.biggers@intel.com> Cc: Edward Baker <edward.baker@intel.com> Cc: Florian Fischer <florian.fischer@muhq.space> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kang Minchul <tegongkang@gmail.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Perry Taylor <perry.taylor@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Rob Herring <robh@kernel.org> Cc: Samantha Alt <samantha.alt@intel.com> Cc: Stephane Eranian <eranian@google.com> Cc: Sumanth Korikkar <sumanthk@linux.ibm.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Weilin Wang <weilin.wang@intel.com> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: Yang Jihong <yangjihong1@huawei.com> Link: https://lore.kernel.org/r/20230502223851.2234828-42-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
1b8012b26f
commit
d6b7dd1107
@@ -391,11 +391,11 @@ def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
|
|||||||
except BaseException as err:
|
except BaseException as err:
|
||||||
print(f"Exception processing {path}")
|
print(f"Exception processing {path}")
|
||||||
raise
|
raise
|
||||||
metrics: list[Tuple[str, metric.Expression]] = []
|
metrics: list[Tuple[str, str, metric.Expression]] = []
|
||||||
for event in events:
|
for event in events:
|
||||||
event.topic = topic
|
event.topic = topic
|
||||||
if event.metric_name and '-' not in event.metric_name:
|
if event.metric_name and '-' not in event.metric_name:
|
||||||
metrics.append((event.metric_name, event.metric_expr))
|
metrics.append((event.pmu, event.metric_name, event.metric_expr))
|
||||||
updates = metric.RewriteMetricsInTermsOfOthers(metrics)
|
updates = metric.RewriteMetricsInTermsOfOthers(metrics)
|
||||||
if updates:
|
if updates:
|
||||||
for event in events:
|
for event in events:
|
||||||
|
@@ -552,28 +552,34 @@ def ParsePerfJson(orig: str) -> Expression:
|
|||||||
return _Constify(eval(compile(parsed, orig, 'eval')))
|
return _Constify(eval(compile(parsed, orig, 'eval')))
|
||||||
|
|
||||||
|
|
||||||
def RewriteMetricsInTermsOfOthers(metrics: List[Tuple[str, Expression]]
|
def RewriteMetricsInTermsOfOthers(metrics: List[Tuple[str, str, Expression]]
|
||||||
)-> Dict[str, Expression]:
|
)-> Dict[Tuple[str, str], Expression]:
|
||||||
"""Shorten metrics by rewriting in terms of others.
|
"""Shorten metrics by rewriting in terms of others.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
metrics (list): pairs of metric names and their expressions.
|
metrics (list): pmus, metric names and their expressions.
|
||||||
Returns:
|
Returns:
|
||||||
Dict: mapping from a metric name to a shortened expression.
|
Dict: mapping from a pmu, metric name pair to a shortened expression.
|
||||||
"""
|
"""
|
||||||
updates: Dict[str, Expression] = dict()
|
updates: Dict[Tuple[str, str], Expression] = dict()
|
||||||
for outer_name, outer_expression in metrics:
|
for outer_pmu, outer_name, outer_expression in metrics:
|
||||||
|
if outer_pmu is None:
|
||||||
|
outer_pmu = 'cpu'
|
||||||
updated = outer_expression
|
updated = outer_expression
|
||||||
while True:
|
while True:
|
||||||
for inner_name, inner_expression in metrics:
|
for inner_pmu, inner_name, inner_expression in metrics:
|
||||||
|
if inner_pmu is None:
|
||||||
|
inner_pmu = 'cpu'
|
||||||
|
if inner_pmu.lower() != outer_pmu.lower():
|
||||||
|
continue
|
||||||
if inner_name.lower() == outer_name.lower():
|
if inner_name.lower() == outer_name.lower():
|
||||||
continue
|
continue
|
||||||
if inner_name in updates:
|
if (inner_pmu, inner_name) in updates:
|
||||||
inner_expression = updates[inner_name]
|
inner_expression = updates[(inner_pmu, inner_name)]
|
||||||
updated = updated.Substitute(inner_name, inner_expression)
|
updated = updated.Substitute(inner_name, inner_expression)
|
||||||
if updated.Equals(outer_expression):
|
if updated.Equals(outer_expression):
|
||||||
break
|
break
|
||||||
if outer_name in updates and updated.Equals(updates[outer_name]):
|
if (outer_pmu, outer_name) in updates and updated.Equals(updates[(outer_pmu, outer_name)]):
|
||||||
break
|
break
|
||||||
updates[outer_name] = updated
|
updates[(outer_pmu, outer_name)] = updated
|
||||||
return updates
|
return updates
|
||||||
|
@@ -158,9 +158,9 @@ class TestMetricExpressions(unittest.TestCase):
|
|||||||
|
|
||||||
def test_RewriteMetricsInTermsOfOthers(self):
|
def test_RewriteMetricsInTermsOfOthers(self):
|
||||||
Expression.__eq__ = lambda e1, e2: e1.Equals(e2)
|
Expression.__eq__ = lambda e1, e2: e1.Equals(e2)
|
||||||
before = [('m1', ParsePerfJson('a + b + c + d')),
|
before = [('cpu', 'm1', ParsePerfJson('a + b + c + d')),
|
||||||
('m2', ParsePerfJson('a + b + c'))]
|
('cpu', 'm2', ParsePerfJson('a + b + c'))]
|
||||||
after = {'m1': ParsePerfJson('m2 + d')}
|
after = {('cpu', 'm1'): ParsePerfJson('m2 + d')}
|
||||||
self.assertEqual(RewriteMetricsInTermsOfOthers(before), after)
|
self.assertEqual(RewriteMetricsInTermsOfOthers(before), after)
|
||||||
Expression.__eq__ = None
|
Expression.__eq__ = None
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user