1 %************************************************************************
3 \section[Driver-stats]{Collecting garbage collection statistics for a ghc run}
5 %************************************************************************
9 &process_ghc_timings();
11 sub process_ghc_timings {
12 local($SysSpecificTiming) = 'ghc';
14 open(STATS, $StatsFile) || die "Failed when opening $StatsFile\n";
16 local($tot_live) = 0; # for calculating residency stuff
17 local($tot_samples) = 0;
20 if (! /Gen:\s+0/ && ! /Minor/ && /^\s*\d+\s+\d+\s+(\d+)\s+\d+\.\d+/ ) {
21 $max_live = $1 if $max_live < $1;
25 $BytesAlloc = $1 if /^\s*([0-9,]+) bytes allocated in the heap/;
27 if ( /^\s*([0-9,]+) bytes maximum residency .* (\d+) sample/ ) {
28 $MaxResidency = $1; $ResidencySamples = $2;
31 $GCs = $1 if /^\s*([0-9,]+) (collections? in generation 0|garbage collections? performed)/;
33 if ( /^\s+([0-9]+)\s+Mb total memory/ ) {
37 # The presence of -? in the following pattern is only there to
38 # accommodate 0.29 && <= 2.05 RTS'
39 if ( /^\s*INIT\s+time\s*(\d+\.\d\d)s\s*\(\s*-?(\d+\.\d\d)s elapsed\)/ ) {
40 $InitTime = $1; $InitElapsed = $2;
41 } elsif ( /^\s*MUT\s+time\s*(\d+\.\d\d)s\s*\(\s*(\d+\.\d\d)s elapsed\)/ ) {
42 $MutTime = $1; $MutElapsed = $2;
43 } elsif ( /^\s*GC\s+time\s*(\d+\.\d\d)s\s*\(\s*(\d+\.\d\d)s elapsed\)/ ) {
44 $GcTime = $1; $GcElapsed = $2;
47 close(STATS) || die "Failed when closing $StatsFile\n";
48 if ( $tot_samples > 0 ) {
49 $ResidencySamples = $tot_samples;
50 $MaxResidency = $max_live;
51 $AvgResidency = int ($tot_live / $tot_samples) ;
54 # warn about what we didn't find
55 print STDERR "Warning: BytesAlloc not found in stats file\n" unless defined($BytesAlloc);
56 print STDERR "Warning: GCs not found in stats file\n" unless defined($GCs);
57 print STDERR "Warning: InitTime not found in stats file\n" unless defined($InitTime);
58 print STDERR "Warning: InitElapsed not found in stats file\n" unless defined($InitElapsed);
59 print STDERR "Warning: MutTime not found in stats file\n" unless defined($MutTime);
60 print STDERR "Warning: MutElapsed not found in stats file\n" unless defined($MutElapsed);
61 print STDERR "Warning: GcTime inot found in stats file\n" unless defined($GcTime);
62 print STDERR "Warning: GcElapsed not found in stats file\n" unless defined($GcElapsed);
64 # things we didn't necessarily expect to find
65 $MaxResidency = 0 unless defined($MaxResidency);
66 $AvgResidency = 0 unless defined($AvgResidency);
67 $ResidencySamples = 0 unless defined($ResidencySamples);
70 $BytesAlloc =~ s/,//g;
71 $MaxResidency =~ s/,//g;
74 $InitElapsed =~ s/,//g;
76 $MutElapsed =~ s/,//g;
80 # print out what we found
81 print STDERR "<<$SysSpecificTiming: ",
82 "$BytesAlloc bytes, $GCs GCs, $AvgResidency/$MaxResidency avg/max bytes residency ($ResidencySamples samples), ${TotMem}M in use, $InitTime INIT ($InitElapsed elapsed), $MutTime MUT ($MutElapsed elapsed), $GcTime GC ($GcElapsed elapsed)",
83 " :$SysSpecificTiming>>\n";