Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * builtin-buildid-list.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Builtin buildid-list command: list buildids in perf.data, in the running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * kernel and in ELF files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2009, Red Hat Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "builtin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "perf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "util/build-id.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "util/debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "util/dso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <subcmd/pager.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <subcmd/parse-options.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "util/session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "util/symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "util/data.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int sysfs__fprintf_build_id(FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	char sbuild_id[SBUILD_ID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	ret = sysfs__sprintf_build_id("/", sbuild_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (ret != sizeof(sbuild_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		return ret < 0 ? ret : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	return fprintf(fp, "%s\n", sbuild_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int filename__fprintf_build_id(const char *name, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	char sbuild_id[SBUILD_ID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	ret = filename__sprintf_build_id(name, sbuild_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (ret != sizeof(sbuild_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return ret < 0 ? ret : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	return fprintf(fp, "%s\n", sbuild_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static bool dso__skip_buildid(struct dso *dso, int with_hits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return with_hits && !dso->hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static int perf_session__list_build_ids(bool force, bool with_hits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct perf_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct perf_data data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		.path  = input_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		.mode  = PERF_DATA_MODE_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		.force = force,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	symbol__elf_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 * See if this is an ELF file first:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (filename__fprintf_build_id(input_name, stdout) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (IS_ERR(session))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return PTR_ERR(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 * We take all buildids when the file contains AUX area tracing data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	 * because we do not decode the trace because it would take too long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (!perf_data__is_pipe(&data) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	    perf_header__has_feat(&session->header, HEADER_AUXTRACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		with_hits = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * in pipe-mode, the only way to get the buildids is to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * the record stream. Buildids are stored as RECORD_HEADER_BUILD_ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (with_hits || perf_data__is_pipe(&data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		perf_session__process_events(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	perf_session__fprintf_dsos_buildid(session, stdout, dso__skip_buildid, with_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	perf_session__delete(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) int cmd_buildid_list(int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	bool show_kernel = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	bool with_hits = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	bool force = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	const struct option options[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	OPT_STRING('i', "input", &input_name, "file", "input file name"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	OPT_END()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	const char * const buildid_list_usage[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		"perf buildid-list [<options>]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	argc = parse_options(argc, argv, options, buildid_list_usage, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	setup_pager();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (show_kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return !(sysfs__fprintf_build_id(stdout) > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return perf_session__list_build_ids(force, with_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }