[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / utils / stat2resid / process-gcstats.prl
1 #!/local/sun4/bin/perl
2 #
3 # Subroutines which derive information from
4 #   ghc garbage collection stats -- %gcstat
5 #
6
7 sub max_residency {
8     local(%gcstats) = @_;
9     local($i, $max) = (-1, 0);
10
11     if ($gcstats{"collector"} eq "APPEL") {
12         die "APPEL stats: average residency not possible\n" ;
13     }
14
15     while(++$i < $gcstats{"gc_no"}) {
16         $max = $gcstats{"live_$i"} > $max ?
17                    $gcstats{"live_$i"} : $max;
18     }
19     $max;
20 }
21
22 sub avg_residency {
23     local(%gcstats) = @_;
24     local($i, $j, $total);
25
26     if ($gcstats{"collector"} eq "APPEL") {
27         die "APPEL stats: average residency not possible\n" ;
28     }
29
30     if ($gcstats{"gc_no"} == 0) { return(0); };
31
32     $i = 0; $j = 0;
33     $total = $gcstats{"live_$i"} * $gcstats{"mut_user_$i"} / 2;
34
35     while(++$i < $gcstats{"gc_no"}) {
36         $total += ($gcstats{"live_$i"} + $gcstats{"live_$j"})
37                  * $gcstats{"mut_user_$i"} / 2;
38         $j = $i;
39     };
40
41     $total += $gcstats{"live_$j"} * $gcstats{"mut_user_$i"} / 2;
42
43     int($total / $gcstats{"mut_user_total"});
44 }
45
46 1;