tools/perf/util/metricgroup.c
Source file repositories/reference/linux-study-clean/tools/perf/util/metricgroup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/metricgroup.c- Extension
.c- Size
- 48294 bytes
- Lines
- 1743
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
metricgroup.hdebug.hevlist.hevsel.hstrbuf.hpmu.hpmus.hprint-events.hsmt.htool_pmu.hexpr.hrblist.hstring.herrno.hstrlist.hassert.hlinux/ctype.hlinux/list_sort.hlinux/string.hlinux/zalloc.hperf/cpumap.hsubcmd/parse-options.hapi/fs/fs.hutil.hasm/bug.hcgroup.hutil/hashmap.h
Detected Declarations
struct metricstruct metricgroup_iter_datastruct visited_metricstruct metricgroup_add_iter_datastruct to_resolvestruct metricgroup__add_metric_datastruct metricgroup__has_metric_datafunction Copyrightfunction metric_event_cmpfunction metric_event_deletefunction list_for_each_entry_safefunction metricgroup__rblist_initfunction metricgroup__rblist_exitfunction metric__watchdog_constraint_hintfunction metric__group_eventsfunction metric__freefunction contains_metric_idfunction setup_metric_eventsfunction evlist__for_each_entry_continuefunction match_metric_or_groupsfunction match_pm_metric_or_groupsfunction metricgroup__sys_event_iterfunction metricgroup__for_each_metricfunction encode_metric_idfunction decode_metric_idfunction decode_all_metric_idsfunction evlist__for_each_entryfunction metricgroup__build_event_stringfunction hashmap__for_each_entryfunction tool_pmu__for_each_eventfunction arch_get_runtimeparamfunction metricgroup__find_metric_callbackfunction resolve_metricfunction __add_metricfunction add_metricfunction metric_list_cmpfunction default_metricgroup_cmpfunction metricgroup__add_metric_callbackfunction metricgroup__add_metricfunction metricgroup__add_metric_listfunction metricgroup__free_metricsfunction list_for_each_entry_safefunction find_tool_eventsfunction list_for_each_entryfunction tool_pmu__for_each_eventfunction build_combined_expr_ctxfunction list_for_each_entryfunction parse_ids
Annotated Snippet
struct metric {
struct list_head nd;
/**
* The expression parse context importantly holding the IDs contained
* within the expression.
*/
struct expr_parse_ctx *pctx;
const char *pmu;
/** The name of the metric such as "IPC". */
const char *metric_name;
/** Modifier on the metric such as "u" or NULL for none. */
const char *modifier;
/** The expression to parse, for example, "instructions/cycles". */
const char *metric_expr;
/** Optional threshold expression where zero value is green, otherwise red. */
const char *metric_threshold;
/**
* The "ScaleUnit" that scales and adds a unit to the metric during
* output.
*/
const char *metric_unit;
/**
* Optional name of the metric group reported
* if the Default metric group is being processed.
*/
const char *default_metricgroup_name;
/** Optional null terminated array of referenced metrics. */
struct metric_ref *metric_refs;
/**
* Should events of the metric be grouped?
*/
bool group_events;
/** Show events even if in the Default metric group. */
bool default_show_events;
/**
* Parsed events for the metric. Optional as events may be taken from a
* different metric whose group contains all the IDs necessary for this
* one.
*/
struct evlist *evlist;
};
static void metric__watchdog_constraint_hint(const char *name, bool foot)
{
static bool violate_nmi_constraint;
if (!foot) {
pr_warning("Not grouping metric %s's events.\n", name);
violate_nmi_constraint = true;
return;
}
if (!violate_nmi_constraint)
return;
pr_warning("Try disabling the NMI watchdog to comply NO_NMI_WATCHDOG metric constraint:\n"
" echo 0 > /proc/sys/kernel/nmi_watchdog\n"
" perf stat ...\n"
" echo 1 > /proc/sys/kernel/nmi_watchdog\n");
}
static bool metric__group_events(const struct pmu_metric *pm, bool metric_no_threshold)
{
switch (pm->event_grouping) {
case MetricNoGroupEvents:
return false;
case MetricNoGroupEventsNmi:
if (!sysctl__nmi_watchdog_enabled())
return true;
metric__watchdog_constraint_hint(pm->metric_name, /*foot=*/false);
return false;
case MetricNoGroupEventsSmt:
return !smt_on();
case MetricNoGroupEventsThresholdAndNmi:
if (metric_no_threshold)
return true;
if (!sysctl__nmi_watchdog_enabled())
return true;
metric__watchdog_constraint_hint(pm->metric_name, /*foot=*/false);
return false;
case MetricGroupEvents:
default:
return true;
}
}
static void metric__free(struct metric *m)
{
if (!m)
return;
Annotation
- Immediate include surface: `metricgroup.h`, `debug.h`, `evlist.h`, `evsel.h`, `strbuf.h`, `pmu.h`, `pmus.h`, `print-events.h`.
- Detected declarations: `struct metric`, `struct metricgroup_iter_data`, `struct visited_metric`, `struct metricgroup_add_iter_data`, `struct to_resolve`, `struct metricgroup__add_metric_data`, `struct metricgroup__has_metric_data`, `function Copyright`, `function metric_event_cmp`, `function metric_event_delete`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.