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.

Dependency Surface

Detected Declarations

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

Implementation Notes