tools/perf/tests/symbols.c

Source file repositories/reference/linux-study-clean/tools/perf/tests/symbols.c

File Facts

System
Linux kernel
Corpus path
tools/perf/tests/symbols.c
Extension
.c
Size
4826 bytes
Lines
227
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 test_info {
	struct perf_env host_env;
	struct machine *machine;
	struct thread *thread;
};

static int init_test_info(struct test_info *ti)
{
	perf_env__init(&ti->host_env);
	ti->machine = machine__new_host(&ti->host_env);
	if (!ti->machine) {
		pr_debug("machine__new_host() failed!\n");
		perf_env__exit(&ti->host_env);
		return TEST_FAIL;
	}

	/* Create a dummy thread */
	ti->thread = machine__findnew_thread(ti->machine, 100, 100);
	if (!ti->thread) {
		pr_debug("machine__findnew_thread() failed!\n");
		perf_env__exit(&ti->host_env);
		return TEST_FAIL;
	}

	return TEST_OK;
}

static void exit_test_info(struct test_info *ti)
{
	thread__put(ti->thread);
	machine__delete(ti->machine);
	perf_env__exit(&ti->host_env);
}

struct dso_map {
	struct dso *dso;
	struct map *map;
};

static int find_map_cb(struct map *map, void *d)
{
	struct dso_map *data = d;

	if (map__dso(map) != data->dso)
		return 0;
	data->map = map;
	return 1;
}

static struct map *find_module_map(struct machine *machine, struct dso *dso)
{
	struct dso_map data = { .dso = dso };

	machine__for_each_kernel_map(machine, find_map_cb, &data);

	return data.map;
}

static void get_test_dso_filename(char *filename, size_t max_sz)
{
	if (dso_to_test)
		strlcpy(filename, dso_to_test, max_sz);
	else
		perf_exe(filename, max_sz);
}

static int create_map(struct test_info *ti, char *filename, struct map **map_p)
{
	struct dso *dso = machine__findnew_dso(ti->machine, filename);

	/*
	 * If 'filename' matches a current kernel module, must use a kernel
	 * map. Find the one that already exists.
	 */
	if (dso && dso__kernel(dso) != DSO_SPACE__USER) {
		*map_p = find_module_map(ti->machine, dso);
		dso__put(dso);
		if (!*map_p) {
			pr_debug("Failed to find map for current kernel module %s",
				 filename);
			return TEST_FAIL;
		}
		map__get(*map_p);
		return TEST_OK;
	}

	dso__put(dso);

	/* Create a dummy map at 0x100000 */
	*map_p = map__new(ti->machine, 0x100000, 0xffffffff, 0, &dso_id_empty,

Annotation

Implementation Notes