| OLD | NEW |
| 1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
| 2 # | 2 # |
| 3 # Read a memtrace logfile from stdin and group memory allocations by logical | 3 # Read a memtrace logfile from stdin and group memory allocations by logical |
| 4 # code component. The code component is guessed from the callstack, and | 4 # code component. The code component is guessed from the callstack, and |
| 5 # is something like {v8, sqlite, disk cache, skia, etc..} | 5 # is something like {v8, sqlite, disk cache, skia, etc..} |
| 6 # | 6 # |
| 7 # Usage: | 7 # Usage: |
| 8 # | 8 # |
| 9 # summary.pl | 9 # summary.pl |
| 10 # | 10 # |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 chomp($cont); | 26 chomp($cont); |
| 27 last if $cont =~ m/=====/; | 27 last if $cont =~ m/=====/; |
| 28 $loc .= "\n" . $cont; | 28 $loc .= "\n" . $cont; |
| 29 } | 29 } |
| 30 my $location_blame = ""; | 30 my $location_blame = ""; |
| 31 | 31 |
| 32 # print "Found: $bytes, $loc\n"; | 32 # print "Found: $bytes, $loc\n"; |
| 33 | 33 |
| 34 if ($loc =~ m/v8::internal::Snapshot::Deserialize/) { | 34 if ($loc =~ m/v8::internal::Snapshot::Deserialize/) { |
| 35 $location_blame = "v8 Snapshot Deserialize"; | 35 $location_blame = "v8 Snapshot Deserialize"; |
| 36 } elsif ($loc =~ m/RenderStyle::create/) { |
| 37 $location_blame = "RenderStyle::create"; |
| 36 } elsif ($loc =~ m/v8::internal::OldSpace::SlowAllocateRaw/) { | 38 } elsif ($loc =~ m/v8::internal::OldSpace::SlowAllocateRaw/) { |
| 37 $location_blame = "v8 OldSpace"; | 39 $location_blame = "v8 OldSpace"; |
| 38 } elsif ($loc =~ m/v8/) { | |
| 39 $location_blame = "v8"; | |
| 40 } elsif ($loc =~ m/sqlite/) { | 40 } elsif ($loc =~ m/sqlite/) { |
| 41 $location_blame = "sqlite"; | 41 $location_blame = "sqlite"; |
| 42 } elsif ($loc =~ m/ TransportDIB::Map/) { | 42 } elsif ($loc =~ m/ TransportDIB::Map/) { |
| 43 $location_blame = "Shared Memory Backing Store"; | 43 $location_blame = "Shared Memory Backing Store"; |
| 44 } elsif ($loc =~ m/imagedecoder/) { | 44 } elsif ($loc =~ m/imagedecoder/) { |
| 45 $location_blame = "img decoder"; | 45 $location_blame = "img decoder"; |
| 46 } elsif ($loc =~ m/SkBitmap/) { | 46 } elsif ($loc =~ m/SkBitmap/) { |
| 47 $location_blame = "skia"; | 47 $location_blame = "skia"; |
| 48 } elsif ($loc =~ m/disk_cache/) { | 48 } elsif ($loc =~ m/disk_cache/) { |
| 49 $location_blame = "disk cache"; | 49 $location_blame = "disk cache"; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } elsif ($loc =~ m/NewDOMUI/) { | 108 } elsif ($loc =~ m/NewDOMUI/) { |
| 109 $location_blame = "NewDOMUI"; | 109 $location_blame = "NewDOMUI"; |
| 110 } elsif ($loc =~ m/RegistryControlledDomainService/) { | 110 } elsif ($loc =~ m/RegistryControlledDomainService/) { |
| 111 $location_blame = "RegistryControlledDomainService"; | 111 $location_blame = "RegistryControlledDomainService"; |
| 112 } elsif ($loc =~ m/URLRequestChromeJob::DataAvailable/) { | 112 } elsif ($loc =~ m/URLRequestChromeJob::DataAvailable/) { |
| 113 $location_blame = "URLRequestChromeJob DataAvailable"; | 113 $location_blame = "URLRequestChromeJob DataAvailable"; |
| 114 } elsif ($loc =~ m/history_publisher/) { | 114 } elsif ($loc =~ m/history_publisher/) { |
| 115 $location_blame = "history publisher"; | 115 $location_blame = "history publisher"; |
| 116 } else { | 116 } else { |
| 117 $location_blame = "unknown"; | 117 $location_blame = "unknown"; |
| 118 # print "$location_blame: ($bytes) $loc\n"; | |
| 119 } | 118 } |
| 120 | 119 |
| 121 # Surface large outliers in an "interesting" group. | 120 # Surface large outliers in an "interesting" group. |
| 122 # When questioned about a specific group listed above, we | 121 my $interesting_group = "unknown"; |
| 123 # can just enter its name here, and get details. | 122 my $interesting_size = 10000000; # Make this smaller as needed. |
| 124 # TODO(jar): Add this as a pair of shell arguments. | 123 # TODO(jar): Add this as a pair of shell arguments. |
| 125 if ($bytes > 10000000 && $location_blame eq "unknown") { | 124 if ($bytes > $interesting_size && $location_blame eq $interesting_group) { |
| 126 $location_blame = "\n" . $loc; | 125 # Create a special group for the exact stack that contributed so much. |
| 126 $location_blame = $loc; |
| 127 } | 127 } |
| 128 | 128 |
| 129 $total_bytes += $bytes; | 129 $total_bytes += $bytes; |
| 130 $leaks{$location_blame} += $bytes; | 130 $leaks{$location_blame} += $bytes; |
| 131 } | 131 } |
| 132 | 132 |
| 133 # now dump our hash table | 133 # now dump our hash table |
| 134 my $sum = 0; | 134 my $sum = 0; |
| 135 my @keys = sort { $leaks{$b} <=> $leaks{$a} }keys %leaks; | 135 my @keys = sort { $leaks{$b} <=> $leaks{$a} }keys %leaks; |
| 136 for ($i=0; $i<@keys; $i++) { | 136 for ($i=0; $i<@keys; $i++) { |
| 137 my $key = @keys[$i]; | 137 my $key = @keys[$i]; |
| 138 printf "%11s\t%3.2f%%\t%s\n", comma_print($leaks{$key}), (100* $leaks{$key}
/ $total_bytes), $key; | 138 printf "%11s\t(%3.2f%%)\t%s\n", comma_print($leaks{$key}), (100* $leaks{$key
} / $total_bytes), $key; |
| 139 $sum += $leaks{$key}; | 139 $sum += $leaks{$key}; |
| 140 } | 140 } |
| 141 printf("TOTAL: %s\n", comma_print($sum)); | 141 printf("TOTAL: %s\n", comma_print($sum)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 # Insert commas into an integer after each three digits for printing. | 144 # Insert commas into an integer after each three digits for printing. |
| 145 sub comma_print { | 145 sub comma_print { |
| 146 my $num = "$_[0]"; | 146 my $num = "$_[0]"; |
| 147 $num =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g; | 147 $num =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g; |
| 148 return $num; | 148 return $num; |
| 149 } | 149 } |
| 150 | 150 |
| 151 # ----- Main ------------------------------------------------ | 151 # ----- Main ------------------------------------------------ |
| 152 | 152 |
| 153 process_stdin(); | 153 process_stdin(); |
| OLD | NEW |