1 # -----------------------------------------------------------------------------
2 # $Id: ghcprof.prl,v 1.5 2005/04/22 08:41:00 simonmar Exp $
4 # (c) The GHC Team 2000
6 # needs: FPTOOLS_TOP_ABS, INSTALLING, DEFAULT_TMPDIR, TARGETPLATFORM, libexecdir
9 if ($ENV{'UDG_HOME'}) {
10 $udrawgraphhome = $ENV{'UDG_HOME'};
11 $udrawgraph = $udrawgraphhome . "/bin/uDrawGraph";
13 print STDERR "ghcprof: UDG_HOME environment variable not set\n";
17 $machname = ${TARGETPLATFORM};
23 $icondir = ( $INSTALLING ? "$libexecdir/icons"
24 : "$FPTOOLS_TOP_ABS/ghc/utils/prof/icons" );
26 $xmlparser = ( $INSTALLING ? "$libexecdir/xmlparser"
27 : "$FPTOOLS_TOP_ABS/ghc/utils/prof/xmlparser/xmlparser" );
29 $cgprof_dir = ( $INSTALLING ? "$libexecdir"
30 : "$FPTOOLS_TOP_ABS/ghc/utils/prof/cgprof" );
32 # where to make tmp file names?
33 if ( $ENV{'TMPDIR'} ) {
34 $Tmp_prefix = $ENV{'TMPDIR'} . "/ghcprof";
36 $Tmp_prefix ="${DEFAULT_TMPDIR}/ghcprof";
37 $ENV{'TMPDIR'} = "${DEFAULT_TMPDIR}"; # set the env var as well
40 # Create a new temporary filename.
43 while (-e ($tempfile = "$Tmp_prefix" . "$i")) {
47 # Create a second temporary filename.
50 while (-e ($tempfile2 = "$Tmp_prefix" . "$i" . ".sh")) {
54 # Delete temp. file if script is halted.
55 sub quit_upon_signal {
56 if ($tempfile ne "" && -e $tempfile) {
57 print STDERR "Deleting $tempfile .. \n" if $Verbose;
60 if ($tempfile2 ne "" && -e $tempfile2) {
61 print STDERR "Deleting $tempfile2 .. \n" if $Verbose;
66 $SIG{'INT'} = 'quit_upon_signal';
67 $SIG{'QUIT'} = 'quit_upon_signal';
72 print STDERR "$Pgm: $msg\n";
77 select(STDERR); $| = 1; select(STDOUT); # no STDERR buffering, please.
78 ($Pgm = $0) =~ s|.*/||;
79 $Version = "v2.1 10-3-2000";
80 $bug_reports_to = 'stephen.jarvis@dcs.warwick.ac.uk';
82 $ShortUsage = "\n$Pgm usage: for basic information, try the `-help' option\n";
85 Usage: $Pgm [option...] filename.prof
92 -color Enable color (default)
106 arg: while ($_ = $ARGV[0]) {
108 #--------HELP------------------------------------------------
109 /^-help$/ && do { print STDERR $Usage; exit(0); };
111 /^-v$/ && do {$Verbose = 1; next arg;};
113 /^-hide$/ && do {$hide= &grab_next_arg("-hide");
114 if (($hide =~ /^(\d+.\d+)$/) || ($hide =~ /^(\d+)$/)) {
117 print STDERR "$Pgm: -hide requires a percentage as ",
123 /^-nologo$/ && do {$Logo =0; next arg;};
124 /^-gr(e|a)y$/ && do {$Colour=0; next arg;};
125 /^-colou?r$/ && do {$Colour=1; next arg;};
126 /^-normalise$/ && do {$DeltaNormalise = &grab_next_arg("-normalise");
127 if ($DeltaNormalise =~ /^(\d+)$/) {
128 $DeltaNormalise = int($DeltaNormalise);
130 print STDERR "$Pgm: -normalise requires an integer ",
136 /^-/ && do { print STDERR "$Pgm: unrecognised option \"",$_,"\"\n";
140 if ($InputFile eq "") {
141 $InputFile = $_; next arg;
147 if ($InputFile eq "") {
148 print STDERR "$Pgm: no input file given\n";
152 print STDERR $ShortUsage;
155 print STDERR "$Pgm: ($Version)\n" if $Verbose;
157 # -----------------------------------------------------------------------------
160 # ToDo: use the real xmlparser
161 # system("$xmlparser < $InputFile > $tempfile");
162 # if ($? != 0) { tidy_up_and_die("xmlparser failed"); }
164 # Stehpen's hacky replacement for xmlparser:
170 open(INPUT, "<$InputFile") || tidy_up_and_die("can't open `$InputFile'");
171 open(TEMPFILE, ">$tempfile") || tidy_up_and_die("can't create `$tempfile'");
174 if (/^1 (\d+) (.*)$/)
177 print TEMPFILE ">>cost_centre\n";
183 print TEMPFILE "$cc_id $name $module\n";
185 if (/^2 (\d+) (\d+) (\d+)$/)
188 print TEMPFILE ">>cost_centre_stack\n";
194 print TEMPFILE "$ccs_id $ccptr $ccsptr\n";
196 elsif (/^2 (\d+) (\d+) (\d+) (\d+)$/)
199 print TEMPFILE ">>cost_centre_stack\n";
206 print TEMPFILE "$ccs_id $type $ccptr $ccsptr\n";
208 if (/^5 (\d+) (.*)$/)
211 print TEMPFILE ">>scc_sample\n";
215 while (/^1 (\d+) (\d+) (\d+) (\d+) (.*)$/)
221 print TEMPFILE "$rg1 $rg2 $rg3 $rg4\n";
226 print TEMPFILE ">>\n";
231 &readProfileHeader();
232 open(TEMPFILE2, ">$tempfile2")
233 || tidy_up_and_die("can't create `$tempfile2'");
235 $shcmd = sprintf("%s/cgprof %s %d \"%s\" " .
236 "\"%s\" %.1f %.1f %.1f %.1f %d %d %d %d %d",
237 $cgprof_dir,$tempfile,$nprocs,$machname,$date,
238 $bsp_s,$bsp_l,$bsp_g,$hide,$Verbose,$Logo,$Colour,
239 $DeltaNormalise,$MaxNoNodes);
240 print TEMPFILE2 "#!/bin/sh\n";
241 print TEMPFILE2 "$shcmd\n";
244 chmod 0755, $tempfile2;
245 $cmd = "env UDG_ICONDIR=$icondir UDG_HOME=$udrawgraphhome " .
246 $udrawgraph . " -startappl . $tempfile2";
247 print STDERR "$Pgm: exec $cmd\n" if $Verbose;
251 sub readProfileHeader {
254 open(PROFILE,$tempfile) || tidy_up_and_die("can't open `$tempfile'");
259 if (/-prof/ && /-flibrary-level\s+(\d+)/) {
261 } elsif (/-flibrary-level\s+(\d+)/) {