tools/perf/util/dsos.c

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

File Facts

System
Linux kernel
Corpus path
tools/perf/util/dsos.c
Extension
.c
Size
11347 bytes
Lines
496
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 dsos__read_build_ids_cb_args {
	bool with_hits;
	bool have_build_id;
};

static int dsos__read_build_ids_cb(struct dso *dso, void *data)
{
	struct dsos__read_build_ids_cb_args *args = data;
	struct nscookie nsc;
	struct build_id bid = { .size = 0, };

	if (args->with_hits && !dso__hit(dso) && !dso__is_vdso(dso))
		return 0;
	if (dso__has_build_id(dso)) {
		args->have_build_id = true;
		return 0;
	}
	nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
	if (filename__read_build_id(dso__long_name(dso), &bid) > 0) {
		dso__set_build_id(dso, &bid);
		args->have_build_id = true;
	} else if (errno == ENOENT && dso__nsinfo(dso)) {
		char *new_name = dso__filename_with_chroot(dso, dso__long_name(dso));

		if (new_name && filename__read_build_id(new_name, &bid) > 0) {
			dso__set_build_id(dso, &bid);
			args->have_build_id = true;
		}
		free(new_name);
	}
	nsinfo__mountns_exit(&nsc);
	return 0;
}

bool dsos__read_build_ids(struct dsos *dsos, bool with_hits)
{
	struct dsos__read_build_ids_cb_args args = {
		.with_hits = with_hits,
		.have_build_id = false,
	};

	dsos__for_each_dso(dsos, dsos__read_build_ids_cb, &args);
	return args.have_build_id;
}

static int __dso__cmp_long_name(const char *long_name, const struct dso_id *id,
				const struct dso *b)
{
	int rc = strcmp(long_name, dso__long_name(b));
	return rc ?: dso_id__cmp(id, dso__id_const(b));
}

static int __dso__cmp_short_name(const char *short_name, const struct dso_id *id,
				 const struct dso *b)
{
	int rc = strcmp(short_name, dso__short_name(b));
	return rc ?: dso_id__cmp(id, dso__id_const(b));
}

static int dsos__cmp_long_name_id_short_name(const void *va, const void *vb)
{
	const struct dso *a = *((const struct dso **)va);
	const struct dso *b = *((const struct dso **)vb);
	int rc = strcmp(dso__long_name(a), dso__long_name(b));

	if (!rc) {
		rc = dso_id__cmp(dso__id_const(a), dso__id_const(b));
		if (!rc)
			rc = strcmp(dso__short_name(a), dso__short_name(b));
	}
	return rc;
}

struct dsos__key {
	const char *long_name;
	const struct dso_id *id;
};

static int dsos__cmp_key_long_name_id(const void *vkey, const void *vdso)
{
	const struct dsos__key *key = vkey;
	const struct dso *dso = *((const struct dso **)vdso);

	return __dso__cmp_long_name(key->long_name, key->id, dso);
}

/*
 * Find a matching entry and/or link current entry to RB tree.
 * Either one of the dso or name parameter must be non-NULL or the
 * function will not work.

Annotation

Implementation Notes