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

perf hist: Improve srcline_{from,to} sort key performance

Likewise, modify ->cmp() callback to compare sample address and map
address. And add ->collapse() and ->sort() to check the actual
srcfile string. Also add ->init() to make sure it has the srcfile.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20221215192817.2734573-10-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
ad9ef9eb f0cdde28

+42
+42
tools/perf/util/sort.c
··· 433 433 static int64_t 434 434 sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right) 435 435 { 436 + return left->branch_info->from.addr - right->branch_info->from.addr; 437 + } 438 + 439 + static int64_t 440 + sort__srcline_from_collapse(struct hist_entry *left, struct hist_entry *right) 441 + { 436 442 if (!left->branch_info->srcline_from) 437 443 left->branch_info->srcline_from = addr_map_symbol__srcline(&left->branch_info->from); 438 444 ··· 446 440 right->branch_info->srcline_from = addr_map_symbol__srcline(&right->branch_info->from); 447 441 448 442 return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from); 443 + } 444 + 445 + static int64_t 446 + sort__srcline_from_sort(struct hist_entry *left, struct hist_entry *right) 447 + { 448 + return sort__srcline_from_collapse(left, right); 449 + } 450 + 451 + static void sort__srcline_from_init(struct hist_entry *he) 452 + { 453 + if (!he->branch_info->srcline_from) 454 + he->branch_info->srcline_from = addr_map_symbol__srcline(&he->branch_info->from); 449 455 } 450 456 451 457 static int hist_entry__srcline_from_snprintf(struct hist_entry *he, char *bf, ··· 469 451 struct sort_entry sort_srcline_from = { 470 452 .se_header = "From Source:Line", 471 453 .se_cmp = sort__srcline_from_cmp, 454 + .se_collapse = sort__srcline_from_collapse, 455 + .se_sort = sort__srcline_from_sort, 456 + .se_init = sort__srcline_from_init, 472 457 .se_snprintf = hist_entry__srcline_from_snprintf, 473 458 .se_width_idx = HISTC_SRCLINE_FROM, 474 459 }; ··· 481 460 static int64_t 482 461 sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right) 483 462 { 463 + return left->branch_info->to.addr - right->branch_info->to.addr; 464 + } 465 + 466 + static int64_t 467 + sort__srcline_to_collapse(struct hist_entry *left, struct hist_entry *right) 468 + { 484 469 if (!left->branch_info->srcline_to) 485 470 left->branch_info->srcline_to = addr_map_symbol__srcline(&left->branch_info->to); 486 471 ··· 494 467 right->branch_info->srcline_to = addr_map_symbol__srcline(&right->branch_info->to); 495 468 496 469 return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to); 470 + } 471 + 472 + static int64_t 473 + sort__srcline_to_sort(struct hist_entry *left, struct hist_entry *right) 474 + { 475 + return sort__srcline_to_collapse(left, right); 476 + } 477 + 478 + static void sort__srcline_to_init(struct hist_entry *he) 479 + { 480 + if (!he->branch_info->srcline_to) 481 + he->branch_info->srcline_to = addr_map_symbol__srcline(&he->branch_info->to); 497 482 } 498 483 499 484 static int hist_entry__srcline_to_snprintf(struct hist_entry *he, char *bf, ··· 517 478 struct sort_entry sort_srcline_to = { 518 479 .se_header = "To Source:Line", 519 480 .se_cmp = sort__srcline_to_cmp, 481 + .se_collapse = sort__srcline_to_collapse, 482 + .se_sort = sort__srcline_to_sort, 483 + .se_init = sort__srcline_to_init, 520 484 .se_snprintf = hist_entry__srcline_to_snprintf, 521 485 .se_width_idx = HISTC_SRCLINE_TO, 522 486 };