add Outputable instance for OccIfaceEq
[ghc-hetmet.git] / utils / stat2resid / stat2resid.prl
1 #
2 # (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 #
4 # Perl script expect bindings for the following variables to be prepended
5 #
6 #   DEFAULT_TMPDIR libdir
7 #
8 # without them, not much success :-(
9 #
10
11 $debug = 0; # first line of script, builds confidence :-)
12 $outsuffix = ".resid.ps";       # change as appropriate
13
14 if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
15     $tmpfile = $ENV{'TMPDIR'} . "/$$.resid.data";
16 } else {
17     $tmpfile ="${DEFAULT_TMPDIR}/$$.resid.data";
18     $ENV{'TMPDIR'} = ${DEFAULT_TMPDIR}; # set the env var as well
19 }
20
21 @INC = ( ${libdir} );
22
23 require('parse-gcstats.prl')   || die "Can't load parse-gcstats.prl!\n";
24 require('process-gcstats.prl') || die "Can't load process-gcstats.prl!\n";
25
26 if ($#ARGV < 0) {
27     $infile = "-";
28     $outfile = "";                              # gnuplot: set output
29 } elsif ($#ARGV == 0) {
30     $infile = $ARGV[0];
31     if ($infile =~ /^(.*)\.stat$/) {
32         $base = $1;
33     } else {
34         $base = $infile;
35         $infile  = "$base.stat";
36     };
37     $outfile = "\"$base$outsuffix\"";           # gnuplot: set output "outfile"
38 } elsif ($#ARGV == 1) {
39     $infile = $ARGV[0];
40     $outfile = "\"$ARGV[1]\"";
41 } else {
42     die "Usage: command [infile[.stat] [outfile]]";
43 };   
44
45 %gcstats = &parse_stats($infile);
46
47 &print_stats(">&STDERR", %gcstats) if $debug;
48
49 if ($gcstats{"collector"} eq "APPEL") {
50     die "APPEL stats: no residency plot possible\n";
51 }
52
53 #
54 # stats are now loaded into %gcstats -- write out info
55 #
56
57 open(DATAFILE, ">$tmpfile") || die "Cant open >$tmpfile \n";
58 $i = -1;
59 $user = 0;
60 printf DATAFILE "%4.2f %d\n", $user, 0;
61 while (++$i < $gcstats{"gc_no"}) {
62    $user += $gcstats{"mut_user_$i"};
63    printf DATAFILE "%4.2f %d\n", $user, $gcstats{"live_$i"}; 
64 }; 
65 printf DATAFILE "%4.2f %d\n", $gcstats{"mut_user_total"}, 0;
66 close(DATAFILE);
67
68 open(PLOTFILE, "|gnuplot") || die "Cant pipe into |gnuplot \n";
69 print PLOTFILE "set data style linespoints\n";
70 print PLOTFILE "set function style lines\n";
71 print PLOTFILE "set nokey\n";
72 print PLOTFILE "set xlabel \"Mutator Time (secs)\"\n";
73 print PLOTFILE "set ylabel \"Heap Residency (bytes)\" 0,-1\n";
74 print PLOTFILE "set term post eps \"Times-Roman\" 20\n";
75 printf PLOTFILE "set title \"%s %s  (%s)\"\n", $gcstats{"command"}, $gcstats{"args"}, $infile;
76 print PLOTFILE "set output $outfile\n" ;
77 print PLOTFILE "plot \"$tmpfile\"\n";
78 close(PLOTFILE);
79
80 unlink($tmpfile);
81 exit 0;