2019-08-21 16:54:14 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2017-08-31 22:40:31 +03:00
# ifndef METRICGROUP_H
# define METRICGROUP_H 1
2019-08-21 16:54:14 +03:00
# include <linux/list.h>
# include <linux/rbtree.h>
# include <stdbool.h>
2020-09-07 09:41:32 +03:00
# include "pmu-events/pmu-events.h"
2019-08-21 16:54:14 +03:00
2020-09-24 15:44:53 +03:00
struct evlist ;
2019-08-21 16:54:14 +03:00
struct evsel ;
struct option ;
struct rblist ;
2020-06-03 00:47:36 +03:00
struct pmu_events_map ;
2020-09-24 15:44:53 +03:00
struct cgroup ;
2017-08-31 22:40:31 +03:00
2021-10-15 20:21:21 +03:00
/**
* A node in a rblist keyed by the evsel . The global rblist of metric events
* generally exists in perf_stat_config . The evsel is looked up in the rblist
* yielding a list of metric_expr .
*/
2017-08-31 22:40:31 +03:00
struct metric_event {
struct rb_node nd ;
2019-07-21 14:23:51 +03:00
struct evsel * evsel ;
2017-08-31 22:40:31 +03:00
struct list_head head ; /* list of metric_expr */
} ;
2021-10-15 20:21:21 +03:00
/**
* A metric referenced by a metric_expr . When parsing a metric expression IDs
* will be looked up , matching either a value ( from metric_events ) or a
* metric_ref . A metric_ref will then be parsed recursively . The metric_refs and
* metric_events need to be known before parsing so that their values may be
* placed in the parse context for lookup .
*/
2020-07-19 21:13:10 +03:00
struct metric_ref {
const char * metric_name ;
const char * metric_expr ;
} ;
2021-10-15 20:21:21 +03:00
/**
* One in a list of metric_expr associated with an evsel . The data is used to
* generate a metric value during stat output .
*/
2017-08-31 22:40:31 +03:00
struct metric_expr {
struct list_head nd ;
2021-10-15 20:21:21 +03:00
/** The expression to parse, for example, "instructions/cycles". */
2017-08-31 22:40:31 +03:00
const char * metric_expr ;
2021-10-15 20:21:21 +03:00
/** The name of the meric such as "IPC". */
2017-08-31 22:40:31 +03:00
const char * metric_name ;
2021-10-15 20:21:21 +03:00
/**
* The " ScaleUnit " that scales and adds a unit to the metric during
* output . For example , " 6.4e-05MiB " means to scale the resulting metric
* by 6.4e-05 ( typically converting a unit like cache lines to something
* more human intelligible ) and then add " MiB " afterward when displayed .
*/
perf metricgroup: Scale the metric result
Some metrics define the scale unit, such as
{
"BriefDescription": "Intel Optane DC persistent memory read latency (ns). Derived from unc_m_pmm_rpq_occupancy.all",
"Counter": "0,1,2,3",
"EventCode": "0xE0",
"EventName": "UNC_M_PMM_READ_LATENCY",
"MetricExpr": "UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS",
"MetricName": "UNC_M_PMM_READ_LATENCY",
"PerPkg": "1",
"ScaleUnit": "6000000000ns",
"UMask": "0x1",
"Unit": "iMC"
},
For above example, the ratio should be,
ratio = (UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS) * 6000000000
But in current code, the ratio is not scaled ( * 6000000000)
With this patch, the ratio is scaled and the unit (ns) is printed.
For example,
# 219.4 ns UNC_M_PMM_READ_LATENCY
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20190828055932.8269-4-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-28 08:59:31 +03:00
const char * metric_unit ;
2021-10-15 20:21:21 +03:00
/** Null terminated array of events used by the metric. */
2019-07-21 14:23:51 +03:00
struct evsel * * metric_events ;
2021-10-15 20:21:21 +03:00
/** Null terminated array of referenced metrics. */
2020-07-19 21:13:10 +03:00
struct metric_ref * metric_refs ;
2021-10-15 20:21:21 +03:00
/** A value substituted for '?' during parsing. */
perf metricgroups: Enhance JSON/metric infrastructure to handle "?"
Patch enhances current metric infrastructure to handle "?" in the metric
expression. The "?" can be use for parameters whose value not known
while creating metric events and which can be replace later at runtime
to the proper value. It also add flexibility to create multiple events
out of single metric event added in JSON file.
Patch adds function 'arch_get_runtimeparam' which is a arch specific
function, returns the count of metric events need to be created. By
default it return 1.
This infrastructure needed for hv_24x7 socket/chip level events.
"hv_24x7" chip level events needs specific chip-id to which the data is
requested. Function 'arch_get_runtimeparam' implemented in header.c
which extract number of sockets from sysfs file "sockets" under
"/sys/devices/hv_24x7/interface/".
With this patch basically we are trying to create as many metric events
as define by runtime_param.
For that one loop is added in function 'metricgroup__add_metric', which
create multiple events at run time depend on return value of
'arch_get_runtimeparam' and merge that event in 'group_list'.
To achieve that we are actually passing this parameter value as part of
`expr__find_other` function and changing "?" present in metric
expression with this value.
As in our JSON file, there gonna be single metric event, and out of
which we are creating multiple events.
To understand which data count belongs to which parameter value,
we also printing param value in generic_metric function.
For example,
command:# ./perf stat -M PowerBUS_Frequency -C 0 -I 1000
1.000101867 9,356,933 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
1.000101867 9,366,134 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
2.000314878 9,365,868 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
2.000314878 9,366,092 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
So, here _0 and _1 after PowerBUS_Frequency specify parameter value.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lore.kernel.org/lkml/20200401203340.31402-5-kjain@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-04-01 23:33:37 +03:00
int runtime ;
2017-08-31 22:40:31 +03:00
} ;
struct metric_event * metricgroup__lookup ( struct rblist * metric_events ,
2019-07-21 14:23:51 +03:00
struct evsel * evsel ,
2017-08-31 22:40:31 +03:00
bool create ) ;
int metricgroup__parse_groups ( const struct option * opt ,
2020-05-20 21:20:10 +03:00
const char * str ,
bool metric_no_group ,
bool metric_no_merge ,
struct rblist * metric_events ) ;
2021-10-15 20:21:15 +03:00
const struct pmu_event * metricgroup__find_metric ( const char * metric ,
const struct pmu_events_map * map ) ;
2020-06-03 00:47:36 +03:00
int metricgroup__parse_groups_test ( struct evlist * evlist ,
2021-10-15 20:21:13 +03:00
const struct pmu_events_map * map ,
2020-06-03 00:47:36 +03:00
const char * str ,
bool metric_no_group ,
bool metric_no_merge ,
struct rblist * metric_events ) ;
2019-02-13 15:32:41 +03:00
void metricgroup__print ( bool metrics , bool groups , char * filter ,
2021-09-03 05:52:39 +03:00
bool raw , bool details , const char * pmu_name ) ;
2018-06-26 10:17:01 +03:00
bool metricgroup__has_metric ( const char * metric ) ;
2021-10-15 20:21:15 +03:00
int arch_get_runtimeparam ( const struct pmu_event * pe __maybe_unused ) ;
2020-06-03 00:47:38 +03:00
void metricgroup__rblist_exit ( struct rblist * metric_events ) ;
2020-09-24 15:44:53 +03:00
int metricgroup__copy_metric_events ( struct evlist * evlist , struct cgroup * cgrp ,
struct rblist * new_metric_events ,
struct rblist * old_metric_events ) ;
2017-08-31 22:40:31 +03:00
# endif