Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf annotate: Introduce annotated_source__get_line()

It's a helper function to get annotation_line at the given offset
without using the offsets array. The goal is to get rid of the
offsets array altogether. It just does the linear search but I
think it's better to save memory as it won't be called in a hot
path.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240404175716.1225482-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
6f157d9a bfd98ceb

+25 -6
+1 -1
tools/perf/ui/browsers/annotate.c
··· 186 186 * name right after the '<' token and probably treating this like a 187 187 * 'call' instruction. 188 188 */ 189 - target = notes->src->offsets[cursor->ops.target.offset]; 189 + target = annotated_source__get_line(notes->src, cursor->ops.target.offset); 190 190 if (target == NULL) { 191 191 ui_helpline__printf("WARN: jump target inconsistency, press 'o', notes->offsets[%#x] = NULL\n", 192 192 cursor->ops.target.offset);
+21 -5
tools/perf/util/annotate.c
··· 369 369 return err; 370 370 } 371 371 372 + struct annotation_line *annotated_source__get_line(struct annotated_source *src, 373 + s64 offset) 374 + { 375 + struct annotation_line *al; 376 + 377 + list_for_each_entry(al, &src->source, node) { 378 + if (al->offset == offset) 379 + return al; 380 + } 381 + return NULL; 382 + } 383 + 372 384 static unsigned annotation__count_insn(struct annotation *notes, u64 start, u64 end) 373 385 { 374 386 unsigned n_insn = 0; 375 387 u64 offset; 376 388 377 389 for (offset = start; offset <= end; offset++) { 378 - if (notes->src->offsets[offset]) 390 + if (annotated_source__get_line(notes->src, offset)) 379 391 n_insn++; 380 392 } 381 393 return n_insn; ··· 417 405 return; 418 406 419 407 for (offset = start; offset <= end; offset++) { 420 - struct annotation_line *al = notes->src->offsets[offset]; 408 + struct annotation_line *al; 421 409 410 + al = annotated_source__get_line(notes->src, offset); 422 411 if (al && al->cycles && al->cycles->ipc == 0.0) { 423 412 al->cycles->ipc = ipc; 424 413 cover_insn++; ··· 456 443 if (ch && ch->cycles) { 457 444 struct annotation_line *al; 458 445 459 - al = notes->src->offsets[offset]; 446 + al = annotated_source__get_line(notes->src, offset); 460 447 if (al && al->cycles == NULL) { 461 448 al->cycles = zalloc(sizeof(*al->cycles)); 462 449 if (al->cycles == NULL) { ··· 479 466 struct cyc_hist *ch = &notes->branch->cycles_hist[offset]; 480 467 481 468 if (ch && ch->cycles) { 482 - struct annotation_line *al = notes->src->offsets[offset]; 469 + struct annotation_line *al; 470 + 471 + al = annotated_source__get_line(notes->src, offset); 483 472 if (al) 484 473 zfree(&al->cycles); 485 474 } ··· 1341 1326 return; 1342 1327 1343 1328 for (offset = 0; offset < size; ++offset) { 1344 - struct annotation_line *al = notes->src->offsets[offset]; 1329 + struct annotation_line *al; 1345 1330 struct disasm_line *dl; 1346 1331 1332 + al = annotated_source__get_line(notes->src, offset); 1347 1333 dl = disasm_line(al); 1348 1334 1349 1335 if (!disasm_line__is_valid_local_jump(dl, sym))
+3
tools/perf/util/annotate.h
··· 270 270 u16 max_line_len; 271 271 }; 272 272 273 + struct annotation_line *annotated_source__get_line(struct annotated_source *src, 274 + s64 offset); 275 + 273 276 /** 274 277 * struct annotated_branch - basic block and IPC information for a symbol. 275 278 *