tools/perf/builtin-list.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-list.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-list.c- Extension
.c- Size
- 21013 bytes
- Lines
- 774
- 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
builtin.hutil/print-events.hutil/pmus.hutil/pmu.hutil/debug.hutil/metricgroup.hutil/pfm.hutil/string2.hutil/strlist.hutil/strbuf.hutil/tool_pmu.hsubcmd/pager.hsubcmd/parse-options.hlinux/zalloc.hctype.hstdarg.hstdio.h
Detected Declarations
struct print_statestruct json_print_statefunction default_print_startfunction default_print_endfunction wordwrapfunction default_print_eventfunction default_print_metricfunction strcmpfunction json_print_startfunction json_print_endfunction fix_escape_fprintffunction json_print_eventfunction json_print_metricfunction json_skip_duplicate_pmusfunction default_skip_duplicate_pmusfunction cmd_listfunction strcmpfunction strcmpfunction strcmpfunction strcmp
Annotated Snippet
struct print_state {
/** @fp: File to write output to. */
FILE *fp;
/**
* @pmu_glob: Optionally restrict PMU and metric matching to PMU or
* debugfs subsystem name.
*/
char *pmu_glob;
/** @event_glob: Optional pattern matching glob. */
char *event_glob;
/** @name_only: Print event or metric names only. */
bool name_only;
/** @desc: Print the event or metric description. */
bool desc;
/** @long_desc: Print longer event or metric description. */
bool long_desc;
/** @deprecated: Print deprecated events or metrics. */
bool deprecated;
/**
* @detailed: Print extra information on the perf event such as names
* and expressions used internally by events.
*/
bool detailed;
/** @metrics: Controls printing of metric and metric groups. */
bool metrics;
/** @metricgroups: Controls printing of metric and metric groups. */
bool metricgroups;
/** @exclude_abi: Exclude PMUs with types less than PERF_TYPE_MAX except PERF_TYPE_RAW. */
bool exclude_abi;
/** @last_topic: The last printed event topic. */
char *last_topic;
/** @last_metricgroups: The last printed metric group. */
char *last_metricgroups;
/** @visited_metrics: Metrics that are printed to avoid duplicates. */
struct strlist *visited_metrics;
};
static void default_print_start(void *ps)
{
struct print_state *print_state = ps;
if (!print_state->name_only && pager_in_use()) {
fprintf(print_state->fp,
"\nList of pre-defined events (to be used in -e or -M):\n\n");
}
}
static void default_print_end(void *print_state __maybe_unused) {}
static const char *skip_spaces_or_commas(const char *str)
{
while (isspace(*str) || *str == ',')
++str;
return str;
}
static void wordwrap(FILE *fp, const char *s, int start, int max, int corr)
{
int column = start;
int n;
bool saw_newline = false;
bool comma = false;
while (*s) {
int wlen = strcspn(s, " ,\t\n");
const char *sep = comma ? "," : " ";
if ((column + wlen >= max && column > start) || saw_newline) {
fprintf(fp, comma ? ",\n%*s" : "\n%*s", start, "");
column = start + corr;
}
if (column <= start)
sep = "";
n = fprintf(fp, "%s%.*s", sep, wlen, s);
if (n <= 0)
break;
saw_newline = s[wlen] == '\n';
s += wlen;
comma = s[0] == ',';
column += n;
s = skip_spaces_or_commas(s);
}
}
static void default_print_event(void *ps, const char *topic,
const char *pmu_name, u32 pmu_type,
const char *event_name, const char *event_alias,
const char *scale_unit __maybe_unused,
bool deprecated, const char *event_type_desc,
const char *desc, const char *long_desc,
Annotation
- Immediate include surface: `builtin.h`, `util/print-events.h`, `util/pmus.h`, `util/pmu.h`, `util/debug.h`, `util/metricgroup.h`, `util/pfm.h`, `util/string2.h`.
- Detected declarations: `struct print_state`, `struct json_print_state`, `function default_print_start`, `function default_print_end`, `function wordwrap`, `function default_print_event`, `function default_print_metric`, `function strcmp`, `function json_print_start`, `function json_print_end`.
- 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.