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