From e8c627f7e832fc3495a64d1a229187e3e1cf5474 Mon Sep 17 00:00:00 2001 From: "cltbld%netscape.com" Date: Thu, 5 Dec 2002 00:09:16 +0000 Subject: [PATCH] Display codesize in MB/KB. Sigfig change to allow 3, 4, etc. sig figs. git-svn-id: svn://10.0.0.236/trunk@134819 18797224-902f-48f8-a5cc-f745e15eee43 --- .../tools/tinderbox/build-seamonkey-util.pl | 80 ++++++++++++------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/mozilla/tools/tinderbox/build-seamonkey-util.pl b/mozilla/tools/tinderbox/build-seamonkey-util.pl index 1bb4f940971..2e5aae370db 100644 --- a/mozilla/tools/tinderbox/build-seamonkey-util.pl +++ b/mozilla/tools/tinderbox/build-seamonkey-util.pl @@ -22,7 +22,7 @@ use File::Path; # for rmtree(); use Config; # for $Config{sig_name} and $Config{sig_num} use File::Find (); -$::UtilsVersion = '$Revision: 1.190 $ '; +$::UtilsVersion = '$Revision: 1.191 $ '; package TinderUtils; @@ -1614,9 +1614,10 @@ sub run_all_tests { my $z_data = extract_token_from_file("$build_dir/$test_log", "__codesize", ":"); chomp($z_data); my $time = POSIX::strftime "%Y:%m:%d:%H:%M:%S", localtime; + my $z_data_string = PrintSize($z_data,4); print_log "TinderboxPrint:" . "Z:$z_data" . "\n"; + ::hostname() . "&autoscale=1&units=bytes&days=7&avg=1&showpoint=$time,$z_data\">Z:$z_data_string" . "B\n"; if($Settings::TestsPhoneHome) { send_results_to_server($z_data, "--", "codesize", ::hostname()); @@ -2123,10 +2124,10 @@ sub BloatTest { if($Settings::TestsPhoneHome) { # Generate and print tbox output strings for leak, bloat. - my $leaks_string = "\n\nTinderboxPrint:" . $label_prefix . "Lk:" . PrintSize($leaks) . "B\n\n"; + my $leaks_string = "\n\nTinderboxPrint:" . $label_prefix . "Lk:" . PrintSize($leaks,3) . "B\n\n"; print_log $leaks_string; - my $bloat_string = "\n\nTinderboxPrint:" . $label_prefix . "Bl:" . PrintSize($bloat) . "B\n\n"; + my $bloat_string = "\n\nTinderboxPrint:" . $label_prefix . "Bl:" . PrintSize($bloat,3) . "B\n\n"; print_log $bloat_string; # Report numbers to server. @@ -2134,8 +2135,8 @@ sub BloatTest { send_results_to_server($bloat, "--", $bloat_testname, ::hostname() ); } else { - print_log "TinderboxPrint:" . $label_prefix . "Lk:" . PrintSize($leaks) . "B\n\n"; - print_log "TinderboxPrint:" . $label_prefix . "Bl:" . PrintSize($bloat) . "B\n\n"; + print_log "TinderboxPrint:" . $label_prefix . "Lk:" . PrintSize($leaks,3) . "B\n\n"; + print_log "TinderboxPrint:" . $label_prefix . "Bl:" . PrintSize($bloat,3) . "B\n\n"; } return 'success'; @@ -2191,34 +2192,51 @@ sub PercentChange($$) { } # Print a value of bytes out in a reasonable -# KB, MB, or GB form. -sub PrintSize($) { +# KB, MB, or GB form. Sig figs should probably +# be 3, 4, or 5 for most purposes here. This used +# to default to 3 sig figs, but I wanted 4 so I +# generalized here. -mcafee +# +# Usage: PrintSize(valueAsInteger, numSigFigs) +# +sub PrintSize($$) { # print a number with 3 significant figures - sub PrintNum($) { - my ($num) = @_; + sub PrintNum($$) { + my ($num, $sigs) = @_; my $rv; - if ($num < 1) { - $rv = sprintf "%.3f", ($num); - } elsif ($num < 10) { - $rv = sprintf "%.2f", ($num); - } elsif ($num < 100) { - $rv = sprintf "%.1f", ($num); + + # Figure out how many decimal places to show. + # Only doing a few cases here, for normal range + # of test numbers. + if ($num < 10**($sigs-5)) { + $rv = sprintf "%.5f", ($num); + } elsif ($num < 10**($sigs-4)) { + $rv = sprintf "%.4f", ($num); + } elsif ($num < 10**($sigs-3)) { + $rv = sprintf "%.3f", ($num); + } elsif ($num < 10**($sigs-2)) { + $rv = sprintf "%.2f", ($num); + } elsif ($num < 10**($sigs-1)) { + $rv = sprintf "%.1f", ($num); } else { - $rv = sprintf "%d", ($num); + $rv = sprintf "%d", ($num); } + } - my ($size) = @_; + my ($size, $sigfigs) = @_; + + # 1K = 1024, previously this was approximated as 1000. my $rv; - if ($size > 1000000000) { - $rv = PrintNum($size / 1000000000.0) . "G"; - } elsif ($size > 1000000) { - $rv = PrintNum($size / 1000000.0) . "M"; - } elsif ($size > 1000) { - $rv = PrintNum($size / 1000.0) . "K"; + if ($size > 1073741824) { # 1024^3 + $rv = PrintNum($size / 1073741824.0, $sigfigs) . "G"; + } elsif ($size > 1048576) { # 1024^2 + $rv = PrintNum($size / 1048576.0, $sigfigs) . "M"; + } elsif ($size > 1024) { + $rv = PrintNum($size / 1024.0, $sigfigs) . "K"; } else { - $rv = PrintNum($size); + $rv = PrintNum($size, $sigfigs); } } @@ -2293,15 +2311,15 @@ sub BloatTest2 { if($Settings::TestsPhoneHome) { my $leaks_testname = "trace_malloc_leaks"; - my $leaks_string = "\n\nTinderboxPrint:Lk:" . PrintSize($newstats->{'leaks'}) . "B\n\n"; + my $leaks_string = "\n\nTinderboxPrint:Lk:" . PrintSize($newstats->{'leaks'},3) . "B\n\n"; print_log $leaks_string; my $maxheap_testname = "trace_malloc_maxheap"; - my $maxheap_string = "\n\nTinderboxPrint:MH:" . PrintSize($newstats->{'mhs'}) . "B\n\n"; + my $maxheap_string = "\n\nTinderboxPrint:MH:" . PrintSize($newstats->{'mhs'},3) . "B\n\n"; print_log $maxheap_string; my $allocs_testname = "trace_malloc_allocs"; - my $allocs_string = "\n\nTinderboxPrint:A:" . PrintSize($newstats->{'allocs'}) . "\n\n"; + my $allocs_string = "\n\nTinderboxPrint:A:" . PrintSize($newstats->{'allocs'},3) . "\n\n"; print_log $allocs_string; # Send results to server. @@ -2311,9 +2329,9 @@ sub BloatTest2 { } else { print_log "TinderboxPrint:"; - print_log "Lk:" . PrintSize($newstats->{'leaks'}) . "B,"; - print_log "MH:" . PrintSize($newstats->{'mhs'}) . "B,"; - print_log "A:" . PrintSize($newstats->{'allocs'}) . "\n"; + print_log "Lk:" . PrintSize($newstats->{'leaks'},3) . "B,"; + print_log "MH:" . PrintSize($newstats->{'mhs'},3) . "B,"; + print_log "A:" . PrintSize($newstats->{'allocs'},3) . "\n"; } if (-e $old_sdleak_log && -e $sdleak_log) {