tools/perf/util/probe-event.c

Source file repositories/reference/linux-study-clean/tools/perf/util/probe-event.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/probe-event.c
Extension
.c
Size
90926 bytes
Lines
3845
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

struct kernel_get_module_map_cb_args {
	const char *module;
	struct map *result;
};

static int kernel_get_module_map_cb(struct map *map, void *data)
{
	struct kernel_get_module_map_cb_args *args = data;
	struct dso *dso = map__dso(map);
	const char *short_name = dso__short_name(dso);
	u16 short_name_len =  dso__short_name_len(dso);

	if (strncmp(short_name + 1, args->module, short_name_len - 2) == 0 &&
	    args->module[short_name_len - 2] == '\0') {
		args->result = map__get(map);
		return 1;
	}
	return 0;
}

static struct map *kernel_get_module_map(const char *module)
{
	struct kernel_get_module_map_cb_args args = {
		.module = module,
		.result = NULL,
	};

	/* A file path -- this is an offline module */
	if (module && strchr(module, '/'))
		return dso__new_map(module);

	if (!module) {
		struct map *map = machine__kernel_map(host_machine);

		return map__get(map);
	}

	maps__for_each_map(machine__kernel_maps(host_machine), kernel_get_module_map_cb, &args);

	return args.result;
}

struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user)
{
	/* Init maps of given executable or kernel */
	if (user) {
		struct map *map;
		struct dso *dso;

		map = dso__new_map(target);
		dso = map ? map__dso(map) : NULL;
		if (dso) {
			mutex_lock(dso__lock(dso));
			dso__set_nsinfo(dso, nsinfo__get(nsi));
			mutex_unlock(dso__lock(dso));
		}
		return map;
	} else {
		return kernel_get_module_map(target);
	}
}

static int convert_exec_to_group(const char *exec, char **result)
{
	char *ptr1, *ptr2, *exec_copy;
	char buf[64];
	int ret;

	exec_copy = strdup(exec);
	if (!exec_copy)
		return -ENOMEM;

	ptr1 = (char *)perf_basename(exec_copy);
	if (!ptr1) {
		ret = -EINVAL;
		goto out;
	}

	for (ptr2 = ptr1; *ptr2 != '\0'; ptr2++) {
		if (!isalnum(*ptr2) && *ptr2 != '_') {
			*ptr2 = '\0';
			break;
		}
	}

	ret = e_snprintf(buf, sizeof(buf), "%s_%s", PERFPROBE_GROUP, ptr1);
	if (ret < 0)
		goto out;

	*result = strdup(buf);

Annotation

Implementation Notes