When metrics are made with experimental events it is desirable the
metric description also carries this information in case of metric
inaccuracies.
Suggested-by: Perry Taylor <perry.taylor@intel.com>
---
tools/perf/pmu-events/metric.py | 44 +++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
index 62d1a1e1d458..2029b6e28365 100644
--- a/tools/perf/pmu-events/metric.py
+++ b/tools/perf/pmu-events/metric.py
@@ -10,11 +10,13 @@ from typing import Dict, List, Optional, Set, Tuple, Union
all_pmus = set()
all_events = set()
+experimental_events = set()
def LoadEvents(directory: str) -> None:
"""Populate a global set of all known events for the purpose of validating Event names"""
global all_pmus
global all_events
+ global experimental_events
all_events = {
"context\\-switches",
"cpu\\-cycles",
@@ -32,6 +34,8 @@ def LoadEvents(directory: str) -> None:
all_pmus.add(x["Unit"])
if "EventName" in x:
all_events.add(x["EventName"])
+ if "Experimental" in x and x["Experimental"] == "1":
+ experimental_events.add(x["EventName"])
elif "ArchStdEvent" in x:
all_events.add(x["ArchStdEvent"])
except json.decoder.JSONDecodeError:
@@ -61,6 +65,18 @@ def CheckEvent(name: str) -> bool:
return name in all_events
+def IsExperimentalEvent(name: str) -> bool:
+ global experimental_events
+ if ':' in name:
+ # Remove trailing modifier.
+ name = name[:name.find(':')]
+ elif '/' in name:
+ # Name could begin with a PMU or an event, for now assume it is not experimental.
+ return False
+
+ return name in experimental_events
+
+
class MetricConstraint(Enum):
GROUPED_EVENTS = 0
NO_GROUP_EVENTS = 1
@@ -82,6 +98,10 @@ class Expression:
"""Returns a simplified version of self."""
raise NotImplementedError()
+ def HasExperimentalEvents(self) -> bool:
+ """Are experimental events used in the expression?"""
+ raise NotImplementedError()
+
def Equals(self, other) -> bool:
"""Returns true when two expressions are the same."""
raise NotImplementedError()
@@ -249,6 +269,9 @@ class Operator(Expression):
return Operator(self.operator, lhs, rhs)
+ def HasExperimentalEvents(self) -> bool:
+ return self.lhs.HasExperimentalEvents() or self.rhs.HasExperimentalEvents()
+
def Equals(self, other: Expression) -> bool:
if isinstance(other, Operator):
return self.operator == other.operator and self.lhs.Equals(
@@ -297,6 +320,10 @@ class Select(Expression):
return Select(true_val, cond, false_val)
+ def HasExperimentalEvents(self) -> bool:
+ return (self.cond.HasExperimentalEvents() or self.true_val.HasExperimentalEvents() or
+ self.false_val.HasExperimentalEvents())
+
def Equals(self, other: Expression) -> bool:
if isinstance(other, Select):
return self.cond.Equals(other.cond) and self.false_val.Equals(
@@ -345,6 +372,9 @@ class Function(Expression):
return Function(self.fn, lhs, rhs)
+ def HasExperimentalEvents(self) -> bool:
+ return self.lhs.HasExperimentalEvents() or (self.rhs and self.rhs.HasExperimentalEvents())
+
def Equals(self, other: Expression) -> bool:
if isinstance(other, Function):
result = self.fn == other.fn and self.lhs.Equals(other.lhs)
@@ -384,6 +414,9 @@ class Event(Expression):
global all_events
raise Exception(f"No event {error} in:\n{all_events}")
+ def HasExperimentalEvents(self) -> bool:
+ return IsExperimentalEvent(self.name)
+
def ToPerfJson(self):
result = re.sub('/', '@', self.name)
return result
@@ -416,6 +449,9 @@ class MetricRef(Expression):
def Simplify(self) -> Expression:
return self
+ def HasExperimentalEvents(self) -> bool:
+ return False
+
def Equals(self, other: Expression) -> bool:
return isinstance(other, MetricRef) and self.name == other.name
@@ -443,6 +479,9 @@ class Constant(Expression):
def Simplify(self) -> Expression:
return self
+ def HasExperimentalEvents(self) -> bool:
+ return False
+
def Equals(self, other: Expression) -> bool:
return isinstance(other, Constant) and self.value == other.value
@@ -465,6 +504,9 @@ class Literal(Expression):
def Simplify(self) -> Expression:
return self
+ def HasExperimentalEvents(self) -> bool:
+ return False
+
def Equals(self, other: Expression) -> bool:
return isinstance(other, Literal) and self.value == other.value
@@ -527,6 +569,8 @@ class Metric:
self.name = name
self.description = description
self.expr = expr.Simplify()
+ if self.expr.HasExperimentalEvents():
+ self.description += " (metric should be considered experimental as it contains experimental events)."
# Workraound valid_only_metric hiding certain metrics based on unit.
scale_unit = scale_unit.replace('/sec', ' per sec')
if scale_unit[0].isdigit():
--
2.51.0.338.gd7d06c2dae-goog
On Wed, 2025-09-03 at 21:46 -0700, Ian Rogers wrote:
> When metrics are made with experimental events it is desirable the
> metric description also carries this information in case of metric
> inaccuracies.
>
> Suggested-by: Perry Taylor <perry.taylor@intel.com>
Does this need a Signed-off-by?
Thanks,
Tom
> ---
> tools/perf/pmu-events/metric.py | 44 +++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
>
> diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
> index 62d1a1e1d458..2029b6e28365 100644
> --- a/tools/perf/pmu-events/metric.py
> +++ b/tools/perf/pmu-events/metric.py
> @@ -10,11 +10,13 @@ from typing import Dict, List, Optional, Set, Tuple, Union
>
> all_pmus = set()
> all_events = set()
> +experimental_events = set()
>
> def LoadEvents(directory: str) -> None:
> """Populate a global set of all known events for the purpose of validating Event names"""
> global all_pmus
> global all_events
> + global experimental_events
> all_events = {
> "context\\-switches",
> "cpu\\-cycles",
> @@ -32,6 +34,8 @@ def LoadEvents(directory: str) -> None:
> all_pmus.add(x["Unit"])
> if "EventName" in x:
> all_events.add(x["EventName"])
> + if "Experimental" in x and x["Experimental"] == "1":
> + experimental_events.add(x["EventName"])
> elif "ArchStdEvent" in x:
> all_events.add(x["ArchStdEvent"])
> except json.decoder.JSONDecodeError:
> @@ -61,6 +65,18 @@ def CheckEvent(name: str) -> bool:
> return name in all_events
>
>
> +def IsExperimentalEvent(name: str) -> bool:
> + global experimental_events
> + if ':' in name:
> + # Remove trailing modifier.
> + name = name[:name.find(':')]
> + elif '/' in name:
> + # Name could begin with a PMU or an event, for now assume it is not experimental.
> + return False
> +
> + return name in experimental_events
> +
> +
> class MetricConstraint(Enum):
> GROUPED_EVENTS = 0
> NO_GROUP_EVENTS = 1
> @@ -82,6 +98,10 @@ class Expression:
> """Returns a simplified version of self."""
> raise NotImplementedError()
>
> + def HasExperimentalEvents(self) -> bool:
> + """Are experimental events used in the expression?"""
> + raise NotImplementedError()
> +
> def Equals(self, other) -> bool:
> """Returns true when two expressions are the same."""
> raise NotImplementedError()
> @@ -249,6 +269,9 @@ class Operator(Expression):
>
> return Operator(self.operator, lhs, rhs)
>
> + def HasExperimentalEvents(self) -> bool:
> + return self.lhs.HasExperimentalEvents() or self.rhs.HasExperimentalEvents()
> +
> def Equals(self, other: Expression) -> bool:
> if isinstance(other, Operator):
> return self.operator == other.operator and self.lhs.Equals(
> @@ -297,6 +320,10 @@ class Select(Expression):
>
> return Select(true_val, cond, false_val)
>
> + def HasExperimentalEvents(self) -> bool:
> + return (self.cond.HasExperimentalEvents() or self.true_val.HasExperimentalEvents() or
> + self.false_val.HasExperimentalEvents())
> +
> def Equals(self, other: Expression) -> bool:
> if isinstance(other, Select):
> return self.cond.Equals(other.cond) and self.false_val.Equals(
> @@ -345,6 +372,9 @@ class Function(Expression):
>
> return Function(self.fn, lhs, rhs)
>
> + def HasExperimentalEvents(self) -> bool:
> + return self.lhs.HasExperimentalEvents() or (self.rhs and self.rhs.HasExperimentalEvents())
> +
> def Equals(self, other: Expression) -> bool:
> if isinstance(other, Function):
> result = self.fn == other.fn and self.lhs.Equals(other.lhs)
> @@ -384,6 +414,9 @@ class Event(Expression):
> global all_events
> raise Exception(f"No event {error} in:\n{all_events}")
>
> + def HasExperimentalEvents(self) -> bool:
> + return IsExperimentalEvent(self.name)
> +
> def ToPerfJson(self):
> result = re.sub('/', '@', self.name)
> return result
> @@ -416,6 +449,9 @@ class MetricRef(Expression):
> def Simplify(self) -> Expression:
> return self
>
> + def HasExperimentalEvents(self) -> bool:
> + return False
> +
> def Equals(self, other: Expression) -> bool:
> return isinstance(other, MetricRef) and self.name == other.name
>
> @@ -443,6 +479,9 @@ class Constant(Expression):
> def Simplify(self) -> Expression:
> return self
>
> + def HasExperimentalEvents(self) -> bool:
> + return False
> +
> def Equals(self, other: Expression) -> bool:
> return isinstance(other, Constant) and self.value == other.value
>
> @@ -465,6 +504,9 @@ class Literal(Expression):
> def Simplify(self) -> Expression:
> return self
>
> + def HasExperimentalEvents(self) -> bool:
> + return False
> +
> def Equals(self, other: Expression) -> bool:
> return isinstance(other, Literal) and self.value == other.value
>
> @@ -527,6 +569,8 @@ class Metric:
> self.name = name
> self.description = description
> self.expr = expr.Simplify()
> + if self.expr.HasExperimentalEvents():
> + self.description += " (metric should be considered experimental as it contains experimental events)."
> # Workraound valid_only_metric hiding certain metrics based on unit.
> scale_unit = scale_unit.replace('/sec', ' per sec')
> if scale_unit[0].isdigit():
On Wed, Sep 17, 2025 at 11:02 AM Falcon, Thomas <thomas.falcon@intel.com> wrote:
>
> On Wed, 2025-09-03 at 21:46 -0700, Ian Rogers wrote:
> > When metrics are made with experimental events it is desirable the
> > metric description also carries this information in case of metric
> > inaccuracies.
> >
> > Suggested-by: Perry Taylor <perry.taylor@intel.com>
>
> Does this need a Signed-off-by?
It does, I'll fix in v7.
Thanks,
Ian
> Thanks,
> Tom
>
> > ---
> > tools/perf/pmu-events/metric.py | 44 +++++++++++++++++++++++++++++++++
> > 1 file changed, 44 insertions(+)
> >
> > diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
> > index 62d1a1e1d458..2029b6e28365 100644
> > --- a/tools/perf/pmu-events/metric.py
> > +++ b/tools/perf/pmu-events/metric.py
> > @@ -10,11 +10,13 @@ from typing import Dict, List, Optional, Set, Tuple, Union
> >
> > all_pmus = set()
> > all_events = set()
> > +experimental_events = set()
> >
> > def LoadEvents(directory: str) -> None:
> > """Populate a global set of all known events for the purpose of validating Event names"""
> > global all_pmus
> > global all_events
> > + global experimental_events
> > all_events = {
> > "context\\-switches",
> > "cpu\\-cycles",
> > @@ -32,6 +34,8 @@ def LoadEvents(directory: str) -> None:
> > all_pmus.add(x["Unit"])
> > if "EventName" in x:
> > all_events.add(x["EventName"])
> > + if "Experimental" in x and x["Experimental"] == "1":
> > + experimental_events.add(x["EventName"])
> > elif "ArchStdEvent" in x:
> > all_events.add(x["ArchStdEvent"])
> > except json.decoder.JSONDecodeError:
> > @@ -61,6 +65,18 @@ def CheckEvent(name: str) -> bool:
> > return name in all_events
> >
> >
> > +def IsExperimentalEvent(name: str) -> bool:
> > + global experimental_events
> > + if ':' in name:
> > + # Remove trailing modifier.
> > + name = name[:name.find(':')]
> > + elif '/' in name:
> > + # Name could begin with a PMU or an event, for now assume it is not experimental.
> > + return False
> > +
> > + return name in experimental_events
> > +
> > +
> > class MetricConstraint(Enum):
> > GROUPED_EVENTS = 0
> > NO_GROUP_EVENTS = 1
> > @@ -82,6 +98,10 @@ class Expression:
> > """Returns a simplified version of self."""
> > raise NotImplementedError()
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + """Are experimental events used in the expression?"""
> > + raise NotImplementedError()
> > +
> > def Equals(self, other) -> bool:
> > """Returns true when two expressions are the same."""
> > raise NotImplementedError()
> > @@ -249,6 +269,9 @@ class Operator(Expression):
> >
> > return Operator(self.operator, lhs, rhs)
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + return self.lhs.HasExperimentalEvents() or self.rhs.HasExperimentalEvents()
> > +
> > def Equals(self, other: Expression) -> bool:
> > if isinstance(other, Operator):
> > return self.operator == other.operator and self.lhs.Equals(
> > @@ -297,6 +320,10 @@ class Select(Expression):
> >
> > return Select(true_val, cond, false_val)
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + return (self.cond.HasExperimentalEvents() or self.true_val.HasExperimentalEvents() or
> > + self.false_val.HasExperimentalEvents())
> > +
> > def Equals(self, other: Expression) -> bool:
> > if isinstance(other, Select):
> > return self.cond.Equals(other.cond) and self.false_val.Equals(
> > @@ -345,6 +372,9 @@ class Function(Expression):
> >
> > return Function(self.fn, lhs, rhs)
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + return self.lhs.HasExperimentalEvents() or (self.rhs and self.rhs.HasExperimentalEvents())
> > +
> > def Equals(self, other: Expression) -> bool:
> > if isinstance(other, Function):
> > result = self.fn == other.fn and self.lhs.Equals(other.lhs)
> > @@ -384,6 +414,9 @@ class Event(Expression):
> > global all_events
> > raise Exception(f"No event {error} in:\n{all_events}")
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + return IsExperimentalEvent(self.name)
> > +
> > def ToPerfJson(self):
> > result = re.sub('/', '@', self.name)
> > return result
> > @@ -416,6 +449,9 @@ class MetricRef(Expression):
> > def Simplify(self) -> Expression:
> > return self
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + return False
> > +
> > def Equals(self, other: Expression) -> bool:
> > return isinstance(other, MetricRef) and self.name == other.name
> >
> > @@ -443,6 +479,9 @@ class Constant(Expression):
> > def Simplify(self) -> Expression:
> > return self
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + return False
> > +
> > def Equals(self, other: Expression) -> bool:
> > return isinstance(other, Constant) and self.value == other.value
> >
> > @@ -465,6 +504,9 @@ class Literal(Expression):
> > def Simplify(self) -> Expression:
> > return self
> >
> > + def HasExperimentalEvents(self) -> bool:
> > + return False
> > +
> > def Equals(self, other: Expression) -> bool:
> > return isinstance(other, Literal) and self.value == other.value
> >
> > @@ -527,6 +569,8 @@ class Metric:
> > self.name = name
> > self.description = description
> > self.expr = expr.Simplify()
> > + if self.expr.HasExperimentalEvents():
> > + self.description += " (metric should be considered experimental as it contains experimental events)."
> > # Workraound valid_only_metric hiding certain metrics based on unit.
> > scale_unit = scale_unit.replace('/sec', ' per sec')
> > if scale_unit[0].isdigit():
© 2016 - 2026 Red Hat, Inc.