From: Nicholas Nethercote Date: Wed, 3 Oct 2018 00:00:10 +0000 (+1000) Subject: Improve callgrind_annotate output. X-Git-Tag: VALGRIND_3_15_0~173 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=331949c1c5cf78909a50c6b3559f36d9dcdeea79;p=thirdparty%2Fvalgrind.git Improve callgrind_annotate output. This commit makes two changes: - it adds commas to call counts (e.g. `65658x` becomes `65,658x`); - it sorts callers/callees in the tree by the --sort order. An example, old output: ``` 72,142,945 < /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:_dl_lookup_symbol_x (65658x) 68,977,760 * /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:do_lookup_x 340 > /build/glibc-OTsEL5/glibc-2.27/malloc/malloc.c:free (3x) 4,564 > /build/glibc-OTsEL5/glibc-2.27/nptl/pthread_mutex_unlock.c:pthread_mutex_unlock (163x) 1,282,381 > /build/glibc-OTsEL5/glibc-2.27/string/../sysdeps/x86_64/strcmp.S:strcmp (12893x) 13,310 > /build/glibc-OTsEL5/glibc-2.27/malloc/malloc.c:calloc (4x) 223 > /build/glibc-OTsEL5/glibc-2.27/elf/dl-misc.c:_dl_higher_prime_number (3x) 1,741,689 > /build/glibc-OTsEL5/glibc-2.27/elf/dl-misc.c:_dl_name_match_p (16842x) 5,705 > /build/glibc-OTsEL5/glibc-2.27/nptl/../nptl/pthread_mutex_lock.c:pthread_mutex_lock (163x) 51,454 < /build/glibc-OTsEL5/glibc-2.27/elf/../elf/dl-runtime.c:_dl_fixup (33x) 2,456 < /build/glibc-OTsEL5/glibc-2.27/elf/dl-sym.c:_dl_sym (2x) 100,313,502 < /build/glibc-OTsEL5/glibc-2.27/elf/../sysdeps/x86_64/dl-machine.h:_dl_relocate_object (39094x) 28,224,467 * /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:_dl_lookup_symbol_x 72,142,945 > /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:do_lookup_x (65658x) [...] 567 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass()); 18 => /home/njn/moz/rust0/src/llvm/include/llvm/IR/LegacyPassManagers.h:non-virtual thunk to llvm::FPPassManager::getAsPass() (9x) 1,971 => /home/njn/moz/rust0/src/llvm/lib/IR/LegacyPassManager.cpp:llvm::PMTopLevelManager::setLastUser(llvm::ArrayRef, llvm::Pass*)'2 (63x) 108 => ???:non-virtual thunk to (anonymous namespace)::MPPassManager::getAsPass() (54x) ``` New output: ``` 72,142,945 < /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:_dl_lookup_symbol_x (65,658x) 68,977,760 * /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:do_lookup_x 1,741,689 > /build/glibc-OTsEL5/glibc-2.27/elf/dl-misc.c:_dl_name_match_p (16,842x) 1,282,381 > /build/glibc-OTsEL5/glibc-2.27/string/../sysdeps/x86_64/strcmp.S:strcmp (12,893x) 13,310 > /build/glibc-OTsEL5/glibc-2.27/malloc/malloc.c:calloc (4x) 5,705 > /build/glibc-OTsEL5/glibc-2.27/nptl/../nptl/pthread_mutex_lock.c:pthread_mutex_lock (163x) 4,564 > /build/glibc-OTsEL5/glibc-2.27/nptl/pthread_mutex_unlock.c:pthread_mutex_unlock (163x) 340 > /build/glibc-OTsEL5/glibc-2.27/malloc/malloc.c:free (3x) 223 > /build/glibc-OTsEL5/glibc-2.27/elf/dl-misc.c:_dl_higher_prime_number (3x) 100,313,502 < /build/glibc-OTsEL5/glibc-2.27/elf/../sysdeps/x86_64/dl-machine.h:_dl_relocate_object (39,094x) 51,454 < /build/glibc-OTsEL5/glibc-2.27/elf/../elf/dl-runtime.c:_dl_fixup (33x) 2,456 < /build/glibc-OTsEL5/glibc-2.27/elf/dl-sym.c:_dl_sym (2x) 28,224,467 * /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:_dl_lookup_symbol_x 72,142,945 > /build/glibc-OTsEL5/glibc-2.27/elf/dl-lookup.c:do_lookup_x (65,658x) [...] 567 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass()); 1,971 => /home/njn/moz/rust0/src/llvm/lib/IR/LegacyPassManager.cpp:llvm::PMTopLevelManager::setLastUser(llvm::ArrayRef, llvm::Pass*)'2 (63x) 108 => ???:non-virtual thunk to (anonymous namespace)::MPPassManager::getAsPass() (54x) 18 => /home/njn/moz/rust0/src/llvm/include/llvm/IR/LegacyPassManagers.h:non-virtual thunk to llvm::FPPassManager::getAsPass() (9x) ``` --- diff --git a/callgrind/callgrind_annotate.in b/callgrind/callgrind_annotate.in index 4f28129c07..34bdb0f5d1 100644 --- a/callgrind/callgrind_annotate.in +++ b/callgrind/callgrind_annotate.in @@ -912,11 +912,15 @@ sub print_summary_and_fn_totals () # Print function callers my $tmp1 = $calling_funcs->{$fn_name}; if (defined $tmp1) { - foreach my $calling (keys %$tmp1) { + # Sort calling functions into order dictated by --sort option. + my @callings = sort { + mycmp($call_CCs{$a,$fn_name}, $call_CCs{$b,$fn_name}) + } keys %$tmp1; + foreach my $calling (@callings) { if (defined $call_counter{$calling,$fn_name}) { print_CC($call_CCs{$calling,$fn_name}, $fn_CC_col_widths); print" < $calling ("; - print $call_counter{$calling,$fn_name} . "x)"; + print commify($call_counter{$calling,$fn_name}) . "x)"; if (defined $obj_name{$calling}) { print " [$obj_name{$calling}]"; } @@ -941,11 +945,15 @@ sub print_summary_and_fn_totals () # Print called functions my $tmp2 = $called_funcs->{$fn_name}; if (defined $tmp2) { - foreach my $called (keys %$tmp2) { + # Sort called functions into order dictated by --sort option. + my @calleds = sort { + mycmp($call_CCs{$fn_name,$a}, $call_CCs{$fn_name,$b}) + } keys %$tmp2; + foreach my $called (@calleds) { if (defined $call_counter{$fn_name,$called}) { print_CC($call_CCs{$fn_name,$called}, $fn_CC_col_widths); print" > $called ("; - print $call_counter{$fn_name,$called} . "x)"; + print commify($call_counter{$fn_name,$called}) . "x)"; if (defined $obj_name{$called}) { print " [$obj_name{$called}]"; } @@ -1163,11 +1171,15 @@ sub annotate_ann_files($) my $tmp = $called_from_line->{$src_file,$.}; my $func = $func_of_line{$src_file,$.}; if (defined $tmp) { - foreach my $called (keys %$tmp) { + # Sort called functions into order dictated by --sort option. + my @calleds = sort { + mycmp($call_CCs{$func,$a}, $call_CCs{$func,$b}) + } keys %$tmp; + foreach my $called (@calleds) { if (defined $call_CCs{$func,$called,$.}) { print_CC($call_CCs{$func,$called,$.}, $CC_col_widths); print " => $called ("; - print $call_counter{$func,$called,$.} . "x)\n"; + print commify($call_counter{$func,$called,$.}) . "x)\n"; } } }