tools/perf/util/annotate.c

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

File Facts

System
Linux kernel
Corpus path
tools/perf/util/annotate.c
Extension
.c
Size
79904 bytes
Lines
3206
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 type_hash_entry {
	struct annotated_data_type *type;
	int offset;
};

static int disasm_line__snprint_type_info(struct disasm_line *dl,
					  char *buf, int len,
					  struct annotation_print_data *apd)
{
	struct annotated_data_type *data_type = NULL;
	struct type_hash_entry *entry = NULL;
	char member[256];
	int offset = 0;
	int printed;

	scnprintf(buf, len, " ");

	if (!annotate_opts.code_with_type || apd->dbg == NULL)
		return 1;

	if (apd->type_hash) {
		hashmap__find(apd->type_hash, dl->al.offset, &entry);
		if (entry != NULL) {
			data_type = entry->type;
			offset = entry->offset;
		}
	}

	if (data_type == NULL)
		data_type = __hist_entry__get_data_type(apd->he, apd->arch, apd->dbg, dl, &offset);

	if (apd->type_hash && entry == NULL) {
		entry = malloc(sizeof(*entry));
		if (entry != NULL) {
			entry->type = data_type;
			entry->offset = offset;
			hashmap__add(apd->type_hash, dl->al.offset, entry);
		}
	}

	if (!needs_type_info(data_type))
		return 1;

	printed = scnprintf(buf, len, "\t\t# data-type: %s", data_type->self.type_name);

	if (data_type != &stackop_type && data_type != &canary_type && len > printed)
		printed += scnprintf(buf + printed, len - printed, " +%#x", offset);

	if (annotated_data_type__get_member_name(data_type, member, sizeof(member), offset) &&
	    len > printed) {
		printed += scnprintf(buf + printed, len - printed, " (%s)", member);
	}
	return printed;
}

void annotation_line__write(struct annotation_line *al, struct annotation *notes,
			    const struct annotation_write_ops *wops,
			    struct annotation_print_data *apd)
{
	bool current_entry = wops->current_entry;
	bool change_color = wops->change_color;
	double percent_max = annotation_line__max_percent(al, annotate_opts.percent_type);
	int width = wops->width;
	int pcnt_width = annotation__pcnt_width(notes);
	int cycles_width = annotation__cycles_width(notes);
	bool show_title = false;
	char bf[256];
	int printed;
	void *obj = wops->obj;
	int  (*obj__set_color)(void *obj, int color) = wops->set_color;
	void (*obj__set_percent_color)(void *obj, double percent, bool current) = wops->set_percent_color;
	int  (*obj__set_jumps_percent_color)(void *obj, int nr, bool current) = wops->set_jumps_percent_color;
	void (*obj__printf)(void *obj, const char *fmt, ...) = wops->printf;
	void (*obj__write_graph)(void *obj, int graph) = wops->write_graph;

	if (wops->first_line && (al->offset == -1 || percent_max == 0.0)) {
		if (notes->branch && al->cycles) {
			if (al->cycles->ipc == 0.0 && al->cycles->avg == 0)
				show_title = true;
		} else
			show_title = true;
	}

	if (al->offset != -1 && percent_max != 0.0) {
		int i;

		for (i = 0; i < al->data_nr; i++) {
			double percent;

			percent = annotation_data__percent(&al->data[i],

Annotation

Implementation Notes