Chromium Code Reviews

Unified Diff: tools/memory_watcher/scripts/memtrace.pl

Issue 348034: Tweak perl scripts in memwatcher tool area.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « tools/memory_watcher/scripts/memprof.pl ('k') | tools/memory_watcher/scripts/summary.pl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/memory_watcher/scripts/memtrace.pl
===================================================================
--- tools/memory_watcher/scripts/memtrace.pl (revision 30172)
+++ tools/memory_watcher/scripts/memtrace.pl (working copy)
@@ -15,21 +15,16 @@
#
# Sample output:
#
-# 41975368 77.64% f:\sp\vctools\crt_bld\self_x86\crt\src\malloc.c (163): malloc
-# 2097152 3.88% c:\src\chrome1\src\webkit\pending\frameloader.cpp (3300): WebCore::FrameLoader::committedLoad
-# 1572864 2.91% c:\src\chrome1\src\webkit\port\bridge\v8bridge.cpp (214): WebCore::V8Bridge::evaluate
-# 1572864 2.91% c:\src\chrome1\src\webkit\glue\webframeloaderclient_impl.cc (1071): WebFrameLoaderClient::committedLoad
-# 1572864 2.91% c:\src\chrome1\src\v8\src\ast.h (1181): v8::internal::Visitor::Visit
+# 41,975,368 77.64% f:\sp\vctools\crt_bld\self_x86\crt\src\malloc.c (163): malloc
+# 2,097,152 3.88% c:\src\chrome1\src\webkit\pending\frameloader.cpp (3300): WebCore::FrameLoader::committedLoad
+# 1,572,864 2.91% c:\src\chrome1\src\webkit\port\bridge\v8bridge.cpp (214): WebCore::V8Bridge::evaluate
+# 1,572,864 2.91% c:\src\chrome1\src\webkit\glue\webframeloaderclient_impl.cc (1071): WebFrameLoaderClient::committedLoad
+# 1,572,864 2.91% c:\src\chrome1\src\v8\src\ast.h (1181): v8::internal::Visitor::Visit
#
#
#
-# ********
-# Note: The output is not currently sorted. To make it more legible,
-# you will want to sort numerically by the first field:
-# $ ./memtrace.pl memwatcher.log3620.txt | sort -n -r
-# ********
-#
+
sub process_raw($) {
my $file = shift;
@@ -81,7 +76,7 @@
elsif ($line =~ m/Untracking untracked/) {
next;
}
- elsif ($line =~ m/[ ]*(c:\\trunk\\[a-zA-Z_\\0-9\.]*) /) {
+ elsif ($line =~ m/[ ]*([a-z]:\\[a-z]*\\[a-zA-Z_\\0-9\.]*) /) {
my $filename = $1;
if ($filename =~ m/memory_watcher/) {
next;
@@ -123,15 +118,22 @@
# now dump our hash table
my $sum = 0;
- my @keys = keys(%leaks);
+ my @keys = sort { $leaks{$b} <=> $leaks{$a} }keys %leaks;
for ($i=0; $i<@keys; $i++) {
my $key = @keys[$i];
- printf "%8d\t%3.2f%%\t%s\n", $leaks{$key}, (100* $leaks{$key} / $total_bytes), $key;
+ if (0 == $total_bytes) { $total_bytes = 1; }
+ printf "%11s\t%3.2f%%\t%s\n", comma_print($leaks{$key}), (100* $leaks{$key} / $total_bytes), $key;
$sum += $leaks{$key};
}
- print("TOTAL: $sum\n");
+ printf("TOTAL: %s\n", comma_print($sum));
}
+# Insert commas into an integer after each three digits for printing.
+sub comma_print {
+ my $num = "$_[0]";
+ $num =~ s/(\d{1,3}?)(?=(\d{3})+$)/$1,/g;
+ return $num;
+}
# ----- Main ------------------------------------------------
« no previous file with comments | « tools/memory_watcher/scripts/memprof.pl ('k') | tools/memory_watcher/scripts/summary.pl » ('j') | no next file with comments »

Powered by Google App Engine