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