tools/perf/ui/browsers/annotate-data.c

Source file repositories/reference/linux-study-clean/tools/perf/ui/browsers/annotate-data.c

File Facts

System
Linux kernel
Corpus path
tools/perf/ui/browsers/annotate-data.c
Extension
.c
Size
15322 bytes
Lines
615
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 browser_entry {
	struct list_head node;
	struct annotated_member *data;
	struct type_hist_entry *hists;
	struct browser_entry *parent;
	struct list_head children;
	int indent;  /*indentation level, starts from 0 */
	int nr_entries; /* # of visible entries: self + descendents */
	bool folded;  /* only can be false when it has children */
};

struct annotated_data_browser {
	struct ui_browser b;
	struct list_head entries;
	struct browser_entry *curr;
	int nr_events;
};

static struct annotated_data_browser *get_browser(struct ui_browser *uib)
{
	return container_of(uib, struct annotated_data_browser, b);
}

static void update_hist_entry(struct type_hist_entry *dst,
			      struct type_hist_entry *src)
{
	dst->nr_samples += src->nr_samples;
	dst->period += src->period;
}

static int get_member_overhead(struct annotated_data_type *adt,
			       struct browser_entry *entry,
			       struct evsel *leader)
{
	struct annotated_member *member = entry->data;
	int i, k;

	for (i = 0; i < member->size; i++) {
		struct type_hist *h;
		struct evsel *evsel;
		int offset = member->offset + i;

		k = 0;
		for_each_group_evsel(evsel, leader) {
			if (symbol_conf.skip_empty &&
			    evsel__hists(evsel)->stats.nr_samples == 0)
				continue;

			h = adt->histograms[evsel->core.idx];
			update_hist_entry(&entry->hists[k++], &h->addr[offset]);
		}
	}
	return 0;
}

static int add_child_entries(struct annotated_data_browser *browser,
			     struct browser_entry *parent,
			     struct annotated_data_type *adt,
			     struct annotated_member *member,
			     struct evsel *evsel, int indent)
{
	struct annotated_member *pos;
	struct browser_entry *entry;
	struct list_head *parent_list;

	entry = zalloc(sizeof(*entry));
	if (entry == NULL)
		return -1;

	entry->hists = calloc(browser->nr_events, sizeof(*entry->hists));
	if (entry->hists == NULL) {
		free(entry);
		return -1;
	}

	entry->data = member;
	entry->parent = parent;
	entry->indent = indent;
	if (get_member_overhead(adt, entry, evsel) < 0) {
		free(entry);
		return -1;
	}

	INIT_LIST_HEAD(&entry->children);
	if (parent)
		parent_list = &parent->children;
	else
		parent_list = &browser->entries;

	list_add_tail(&entry->node, parent_list);

Annotation

Implementation Notes