Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: tools/memory_watcher/scripts/memprof.pl

Issue 348034: Tweak perl scripts in memwatcher tool area.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/memory_watcher/scripts/memtrace.pl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 2
3 # 3 #
4 # Given a memwatcher logfile, group memory allocations by callstack. 4 # Given a memwatcher logfile, group memory allocations by callstack.
5 # 5 #
6 # Usage: 6 # Usage:
7 # 7 #
8 # memprof.pl <logfile> 8 # memprof.pl <logfile>
9 # 9 #
10 # logfile -- The memwatcher.logXXXX file to summarize. 10 # logfile -- The memwatcher.logXXXX file to summarize.
11 # 11 #
12 # 12 #
13 # 13 #
14 # Sample output: 14 # Sample output:
15 # 15 #
16 # 54061617 100.00% AllocationStack::AllocationStack 16 # 54,061,617 100.00% AllocationStack::AllocationStack
17 # 41975368 77.64% malloc 17 # 41,975,368 77.64% malloc
18 # 11886592 21.99% VirtualAlloc 18 # 11,886,592 21.99% VirtualAlloc
19 # 7168000 13.26% v8::internal::OS::Allocate 19 # 7,168,000 13.26% v8::internal::OS::Allocate
20 # 7168000 13.26% v8::internal::MemoryAllocator::AllocateRawMemory 20 # 7,168,000 13.26% v8::internal::MemoryAllocator::AllocateRawMemory
21 # 5976184 11.05% WebCore::V8Bridge::evaluate 21 # 5,976,184 11.05% WebCore::V8Bridge::evaluate
22 # 5767168 10.67% v8::internal::MemoryAllocator::AllocatePages 22 # 5,767,168 10.67% v8::internal::MemoryAllocator::AllocatePages
23 # 5451776 10.08% WebCore::V8Proxy::initContextIfNeeded 23 # 5,451,776 10.08% WebCore::V8Proxy::initContextIfNeeded
24 # .... 24 # ....
25 # 25 #
26 # 26 #
27 # 27 #
28 # ******** 28 # ********
29 # Note: The output is not currently sorted. To make it more legible, 29 # Note: The output is currently sorted by decreasing size.
30 # you will want to sort numerically by the first field:
31 # $ ./memprof.pl memwatcher.log3620.txt | sort -n -r
32 # ******** 30 # ********
33 # 31 #
34 32
35 sub process_raw($$) { 33 sub process_raw($$) {
36 my $file = shift; 34 my $file = shift;
37 my $filter = shift; 35 my $filter = shift;
38 36
39 my %leaks = (); 37 my %leaks = ();
40 my %stackframes = (); 38 my %stackframes = ();
41 39
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 $leaks{$pig} += $bytes; 81 $leaks{$pig} += $bytes;
84 } 82 }
85 83
86 $stackframes{$pig}++; 84 $stackframes{$pig}++;
87 $blamed++; 85 $blamed++;
88 } 86 }
89 } 87 }
90 88
91 # now dump our hash table 89 # now dump our hash table
92 my $sum = 0; 90 my $sum = 0;
93 my @keys = keys(%leaks); 91 my @keys = sort { $leaks{$b} <=> $leaks{$a} }keys %leaks;
94 for ($i=0; $i<@keys; $i++) { 92 for ($i=0; $i<@keys; $i++) {
95 my $key = @keys[$i]; 93 my $key = @keys[$i];
96 printf "%8d\t%3.2f%%\t%s\n", $leaks{$key}, (100* $leaks{$key} / $total_bytes ), $key; 94 printf "%11s\t%3.2f%%\t%s\n", comma_print($leaks{$key}), (100* $leaks{$key} / $total_bytes), $key;
97 $sum += $leaks{$key}; 95 $sum += $leaks{$key};
98 } 96 }
99 print("TOTAL: $sum\n"); 97 printf("TOTAL: %s\n", comma_print($sum));
100 } 98 }
101 99
100 # Insert commas into an integer after each three digits for printing.
101 sub comma_print {
102 my $num = "$_[0]";
103 $num =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g;
104 return $num;
105 }
102 106
103 # ----- Main ------------------------------------------------ 107 # ----- Main ------------------------------------------------
104 108
105 # Get the command line argument 109 # Get the command line argument
106 my $filename = shift; 110 my $filename = shift;
107 my $filter = shift; 111 my $filter = shift;
108 112
109 # Process the file. 113 # Process the file.
110 process_raw($filename, $filter); 114 process_raw($filename, $filter);
OLDNEW
« no previous file with comments | « no previous file | tools/memory_watcher/scripts/memtrace.pl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698