Skip to content

Commit b0fb1a9

Browse files
committed
Merge: perf annotate: Add annotation_options.disassembler_used
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6748 # Merge Request Required Information JIRA: https://issues.redhat.com/browse/RHEL-83785 ## Summary of Changes Signed-off-by: Jakub Brnak <jbrnak@redhat.com> Approved-by: Michael Petlan <mpetlan@redhat.com> Approved-by: ashelat <ashelat@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 67c53c4 + db351f3 commit b0fb1a9

File tree

4 files changed

+242
-93
lines changed

4 files changed

+242
-93
lines changed

tools/perf/Documentation/perf-config.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ annotate.*::
247247
These are in control of addresses, jump function, source code
248248
in lines of assembly code from a specific program.
249249

250+
annotate.disassemblers::
251+
Choose the disassembler to use: "objdump", "llvm", "capstone",
252+
if not specified it will first try, if available, the "llvm" one,
253+
then, if it fails, "capstone", and finally the original "objdump"
254+
based one.
255+
256+
Choosing a different one is useful when handling some feature that
257+
is known to be best support at some point by one of the options,
258+
to compare the output when in doubt about some bug, etc.
259+
260+
This can be a list, in order of preference, the first one that works
261+
finishes the process.
262+
250263
annotate.addr2line::
251264
addr2line binary to use for file names and line numbers.
252265

tools/perf/util/annotate.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,57 @@ int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel,
21022102
return 0;
21032103
}
21042104

2105+
const char * const perf_disassembler__strs[] = {
2106+
[PERF_DISASM_UNKNOWN] = "unknown",
2107+
[PERF_DISASM_LLVM] = "llvm",
2108+
[PERF_DISASM_CAPSTONE] = "capstone",
2109+
[PERF_DISASM_OBJDUMP] = "objdump",
2110+
};
2111+
2112+
2113+
static void annotation_options__add_disassembler(struct annotation_options *options,
2114+
enum perf_disassembler dis)
2115+
{
2116+
for (u8 i = 0; i < ARRAY_SIZE(options->disassemblers); i++) {
2117+
if (options->disassemblers[i] == dis) {
2118+
/* Disassembler is already present then don't add again. */
2119+
return;
2120+
}
2121+
if (options->disassemblers[i] == PERF_DISASM_UNKNOWN) {
2122+
/* Found a free slot. */
2123+
options->disassemblers[i] = dis;
2124+
return;
2125+
}
2126+
}
2127+
pr_err("Failed to add disassembler %d\n", dis);
2128+
}
2129+
2130+
static int annotation_options__add_disassemblers_str(struct annotation_options *options,
2131+
const char *str)
2132+
{
2133+
while (str && *str != '\0') {
2134+
const char *comma = strchr(str, ',');
2135+
int len = comma ? comma - str : (int)strlen(str);
2136+
bool match = false;
2137+
2138+
for (u8 i = 0; i < ARRAY_SIZE(perf_disassembler__strs); i++) {
2139+
const char *dis_str = perf_disassembler__strs[i];
2140+
2141+
if (len == (int)strlen(dis_str) && !strncmp(str, dis_str, len)) {
2142+
annotation_options__add_disassembler(options, i);
2143+
match = true;
2144+
break;
2145+
}
2146+
}
2147+
if (!match) {
2148+
pr_err("Invalid disassembler '%.*s'\n", len, str);
2149+
return -1;
2150+
}
2151+
str = comma ? comma + 1 : NULL;
2152+
}
2153+
return 0;
2154+
}
2155+
21052156
static int annotation__config(const char *var, const char *value, void *data)
21062157
{
21072158
struct annotation_options *opt = data;
@@ -2116,6 +2167,11 @@ static int annotation__config(const char *var, const char *value, void *data)
21162167
opt->offset_level = ANNOTATION__MAX_OFFSET_LEVEL;
21172168
else if (opt->offset_level < ANNOTATION__MIN_OFFSET_LEVEL)
21182169
opt->offset_level = ANNOTATION__MIN_OFFSET_LEVEL;
2170+
} else if (!strcmp(var, "annotate.disassemblers")) {
2171+
int err = annotation_options__add_disassemblers_str(opt, value);
2172+
2173+
if (err)
2174+
return err;
21192175
} else if (!strcmp(var, "annotate.hide_src_code")) {
21202176
opt->hide_src_code = perf_config_bool("hide_src_code", value);
21212177
} else if (!strcmp(var, "annotate.jump_arrows")) {
@@ -2181,9 +2237,25 @@ void annotation_options__exit(void)
21812237
zfree(&annotate_opts.objdump_path);
21822238
}
21832239

2240+
static void annotation_options__default_init_disassemblers(struct annotation_options *options)
2241+
{
2242+
if (options->disassemblers[0] != PERF_DISASM_UNKNOWN) {
2243+
/* Already initialized. */
2244+
return;
2245+
}
2246+
#ifdef HAVE_LIBLLVM_SUPPORT
2247+
annotation_options__add_disassembler(options, PERF_DISASM_LLVM);
2248+
#endif
2249+
#ifdef HAVE_LIBCAPSTONE_SUPPORT
2250+
annotation_options__add_disassembler(options, PERF_DISASM_CAPSTONE);
2251+
#endif
2252+
annotation_options__add_disassembler(options, PERF_DISASM_OBJDUMP);
2253+
}
2254+
21842255
void annotation_config__init(void)
21852256
{
21862257
perf_config(annotation__config, &annotate_opts);
2258+
annotation_options__default_init_disassemblers(&annotate_opts);
21872259
}
21882260

21892261
static unsigned int parse_percent_type(char *str1, char *str2)

tools/perf/util/annotate.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ struct annotated_data_type;
3434
#define ANNOTATION__BR_CNTR_WIDTH 30
3535
#define ANNOTATION_DUMMY_LEN 256
3636

37+
enum perf_disassembler {
38+
PERF_DISASM_UNKNOWN = 0,
39+
PERF_DISASM_LLVM,
40+
PERF_DISASM_CAPSTONE,
41+
PERF_DISASM_OBJDUMP,
42+
};
43+
#define MAX_DISASSEMBLERS (PERF_DISASM_OBJDUMP + 1)
44+
3745
struct annotation_options {
3846
bool hide_src_code,
3947
use_offset,
@@ -49,6 +57,8 @@ struct annotation_options {
4957
annotate_src,
5058
full_addr;
5159
u8 offset_level;
60+
u8 disassemblers[MAX_DISASSEMBLERS];
61+
u8 disassembler_used;
5262
int min_pcnt;
5363
int max_lines;
5464
int context;
@@ -128,6 +138,8 @@ struct disasm_line {
128138
struct annotation_line al;
129139
};
130140

141+
extern const char * const perf_disassembler__strs[];
142+
131143
void annotation_line__add(struct annotation_line *al, struct list_head *head);
132144

133145
static inline double annotation_data__percent(struct annotation_data *data,

0 commit comments

Comments
 (0)