tools/perf/builtin-script.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-script.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-script.c- Extension
.c- Size
- 127367 bytes
- Lines
- 4611
- 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/counts.hutil/debug.hutil/dso.hsubcmd/exec-cmd.hutil/header.hsubcmd/parse-options.hutil/perf_regs.hutil/session.hutil/tool.hutil/map.hutil/srcline.hutil/symbol.hutil/thread.hutil/trace-event.hutil/env.hutil/evlist.hutil/evsel.hutil/evsel_fprintf.hutil/evswitch.hutil/sort.hutil/data.hutil/auxtrace.hutil/cpumap.hutil/thread_map.hutil/stat.hutil/color.hutil/string2.hutil/thread-stack.hutil/time-utils.hutil/path.hutil/event.h
Detected Declarations
struct perf_scriptstruct evsel_scriptstruct printer_datastruct metric_ctxstruct script_find_metrics_argsstruct script_descenum perf_output_fieldfunction evsel_script__deletefunction evsel_script__fprintffunction output_typefunction evsel__output_typefunction output_set_by_userfunction evsel__do_check_stypefunction evsel__check_stypefunction evsel__check_attrfunction evsel__set_print_ip_optsfunction evlist__for_each_entryfunction perf_session__check_output_optfunction evlist__for_each_entryfunction evlist__for_each_entryfunction perf_sample__fprintf_regsfunction for_each_set_bitfunction tod_scnprintffunction perf_sample__fprintf_iregsfunction perf_sample__fprintf_uregsfunction perf_sample__fprintf_startfunction bstack_event_strfunction print_bstack_flagsfunction perf_sample__fprintf_brstackfunction perf_sample__fprintf_brstacksymfunction perf_sample__fprintf_brstackofffunction grab_bbfunction map__fprintf_srccodefunction print_srccodefunction any_dump_insnfunction add_paddingfunction ip__fprintf_jumpfunction evlist__for_each_entry_fromfunction ip__fprintf_symfunction perf_sample__fprintf_brstackinsnfunction perf_sample__fprintf_addrfunction perf_sample__fprintf_callindentfunction perf_sample__fprintf_insnfunction perf_sample__fprintf_ipcfunction perf_sample__fprintf_btsfunction perf_sample__fprintf_flagsfunction sample__fprintf_bpf_outputfunction perf_sample__fprintf_bpf_output
Annotated Snippet
script->tool.context_switch = process_switch_event;
if (scripting_ops && scripting_ops->process_auxtrace_error)
script->tool.auxtrace_error = process_auxtrace_error;
if (script->show_namespace_events)
script->tool.namespaces = process_namespaces_event;
if (script->show_cgroup_events)
script->tool.cgroup = process_cgroup_event;
if (script->show_lost_events)
script->tool.lost = process_lost_event;
if (script->show_round_events) {
script->tool.ordered_events = false;
script->tool.finished_round = process_finished_round_event;
}
if (script->show_bpf_events) {
script->tool.ksymbol = process_bpf_events;
script->tool.bpf = process_bpf_events;
script->tool.bpf_metadata = process_bpf_metadata_event;
}
if (script->show_text_poke_events) {
script->tool.ksymbol = process_bpf_events;
script->tool.text_poke = process_text_poke_events;
}
if (perf_script__setup_per_event_dump(script)) {
pr_err("Couldn't create the per event dump files\n");
return -1;
}
ret = perf_session__process_events(script->session);
if (script->per_event_dump)
perf_script__exit_per_event_dump_stats(script);
if (debug_mode)
pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
return ret;
}
static int list_available_languages_cb(struct scripting_ops *ops, const char *spec)
{
fprintf(stderr, " %-42s [%s]\n", spec, ops->name);
return 0;
}
static void list_available_languages(void)
{
fprintf(stderr, "\n");
fprintf(stderr, "Scripting language extensions (used in "
"perf script -s [spec:]script.[spec]):\n\n");
script_spec__for_each(&list_available_languages_cb);
fprintf(stderr, "\n");
}
/* Find script file relative to current directory or exec path */
static char *find_script(const char *script)
{
char path[PATH_MAX];
if (!scripting_ops) {
const char *ext = strrchr(script, '.');
if (!ext)
return NULL;
scripting_ops = script_spec__lookup(++ext);
if (!scripting_ops)
return NULL;
}
if (access(script, R_OK)) {
char *exec_path = get_argv_exec_path();
if (!exec_path)
return NULL;
snprintf(path, sizeof(path), "%s/scripts/%s/%s",
exec_path, scripting_ops->dirname, script);
free(exec_path);
script = path;
if (access(script, R_OK))
return NULL;
}
return strdup(script);
}
static int parse_scriptname(const struct option *opt __maybe_unused,
const char *str, int unset __maybe_unused)
{
char spec[PATH_MAX];
const char *script, *ext;
Annotation
- Immediate include surface: `builtin.h`, `util/counts.h`, `util/debug.h`, `util/dso.h`, `subcmd/exec-cmd.h`, `util/header.h`, `subcmd/parse-options.h`, `util/perf_regs.h`.
- Detected declarations: `struct perf_script`, `struct evsel_script`, `struct printer_data`, `struct metric_ctx`, `struct script_find_metrics_args`, `struct script_desc`, `enum perf_output_field`, `function evsel_script__delete`, `function evsel_script__fprintf`, `function output_type`.
- 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.