# This script processes the output of ajax_java_call_flow.d and # prints a list of all Java and JavaScript methods / functions # (mixed) and their exclusive and inclusive time. # The list is printed in a descended order of exclusive time ($in) = @ARGV; open (IN, $in) || die "Cannot open $in"; while () { $is_entry = /^\s*->/; $is_return = /^\s*<-/; next unless ($is_entry || $is_return); ($timestamp) = /(\d+)\)\s*$/; if ($is_entry) { ($fname) = /^\s*->\s+(\S+)/; &process_entry($fname, $timestamp); } else { ($fname) = /^\s*<-\s+(\S+)/; &process_return($fname, $timestamp); } } printf("%-60s %-10s %-10s\n", "Method/Function", "Exc. time", "Inc. time"); foreach $f (sort by_value keys(%fexclusive)) { # printf("%-60s %-015d %-015d\n", ${f}, $fexclusive{$f}, $finclusive{$f}); printf("%-60s %-10u %-10u\n", ${f}, $fexclusive{$f}, $finclusive{$f}); } sub by_value { $fexclusive{$b} <=> $fexclusive{$a}; } sub process_entry { my ($fname, $timestamp) = @_; $t_finclusive{$fname} -= $timestamp; $t_fexclusive{$fname} -= $timestamp; $stackTop = &popCallStack; if ($stackTop) { $t_fexclusive{$stackTop} += $timestamp; &pushCallStack($stackTop); } &pushCallStack($fname); } sub process_return { my ($fname, $timestamp) = @_; $t_finclusive{$fname} += $timestamp; $t_fexclusive{$fname} += $timestamp; &popCallStack; $stackTop = &popCallStack; if ($stackTop) { $t_fexclusive{$stackTop} -= $timestamp; &pushCallStack($stackTop); } &commitFTime($fname); } sub commitFTime { my ($fname) = @_; $finclusive{$fname} += $t_finclusive{$fname}; $t_finclusive{$fname} = 0; $fexclusive{$fname} += $t_fexclusive{$fname}; $t_fexclusive{$fname} = 0; } sub pushCallStack { my ($fname) = @_; push @callStack, $fname; } sub popCallStack { pop @callStack; }