tools/perf/tests/hists_link.c

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

File Facts

System
Linux kernel
Corpus path
tools/perf/tests/hists_link.c
Extension
.c
Size
9199 bytes
Lines
364
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 sample {
	u32 pid;
	u64 ip;
	struct thread *thread;
	struct map *map;
	struct symbol *sym;
};

/* For the numbers, see hists_common.c */
static struct sample fake_common_samples[] = {
	/* perf [kernel] schedule() */
	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },
	/* perf [perf]   main() */
	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, },
	/* perf [perf]   cmd_record() */
	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, },
	/* bash [bash]   xmalloc() */
	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, },
	/* bash [libc]   malloc() */
	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, },
};

static struct sample fake_samples[][5] = {
	{
		/* perf [perf]   run_command() */
		{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_RUN_COMMAND, },
		/* perf [libc]   malloc() */
		{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },
		/* perf [kernel] page_fault() */
		{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
		/* perf [kernel] sys_perf_event_open() */
		{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN, },
		/* bash [libc]   free() */
		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_FREE, },
	},
	{
		/* perf [libc]   free() */
		{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_LIBC_FREE, },
		/* bash [libc]   malloc() */
		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, }, /* will be merged */
		/* bash [bash]   xfee() */
		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XFREE, },
		/* bash [libc]   realloc() */
		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_REALLOC, },
		/* bash [kernel] page_fault() */
		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
	},
};

static int add_hist_entries(struct evlist *evlist, struct machine *machine)
{
	struct evsel *evsel;
	struct addr_location al;
	struct hist_entry *he;
	struct perf_sample sample = { .period = 1, .weight = 1, };
	size_t i = 0, k;

	addr_location__init(&al);
	/*
	 * each evsel will have 10 samples - 5 common and 5 distinct.
	 * However the second evsel also has a collapsed entry for
	 * "bash [libc] malloc" so total 9 entries will be in the tree.
	 */
	evlist__for_each_entry(evlist, evsel) {
		struct hists *hists = evsel__hists(evsel);

		for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) {
			sample.cpumode = PERF_RECORD_MISC_USER;
			sample.pid = fake_common_samples[k].pid;
			sample.tid = fake_common_samples[k].pid;
			sample.ip = fake_common_samples[k].ip;

			if (machine__resolve(machine, &al, &sample) < 0)
				goto out;

			he = hists__add_entry(hists, &al, NULL,
					      NULL, NULL, NULL, &sample, true);
			if (he == NULL) {
				goto out;
			}

			thread__put(fake_common_samples[k].thread);
			fake_common_samples[k].thread = thread__get(al.thread);
			map__put(fake_common_samples[k].map);
			fake_common_samples[k].map = map__get(al.map);
			fake_common_samples[k].sym = al.sym;
		}

		for (k = 0; k < ARRAY_SIZE(fake_samples[i]); k++) {
			sample.pid = fake_samples[i][k].pid;

Annotation

Implementation Notes