[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / utils / parallel / gr2ap.bash
1 #!/usr/local/bin/bash
2 ##############################################################################
3 # Time-stamp: <Wed Jul 24 1996 20:53:36 Stardate: [-31]7859.14 hwloidl>
4 #
5 # Usage: gr2ap [options] <gr-file>
6 #
7 # Create a per-thread activity graph from a GrAnSim (or GUM) profile.
8 # Transform the log file of a GrAnSim run (a .gr file) into a quasi-parallel
9 # profile (a .qp file) using gr2qp and then into a PostScript file using qp2ap.
10 # The generated PostScript file shows one horizontal line for each task. The 
11 # thickness of the line indicates the state of the thread:
12 #  thick ... active,  medium ... suspended,  thin ... fetching remote data
13 #
14 # Options:
15 #  -o <file> ... write .ps file to <file>
16 #  -m        ... create mono PostScript file instead a color one.
17 #  -O        ... optimise i.e. try to minimise the size of the .ps file.
18 #  -v        ... be talkative. 
19 #  -h        ... print help message (this header).
20 #
21 ##############################################################################
22
23 progname="`basename $0`"
24 args="$*"
25
26 verb=0
27 help=0
28 mono=""
29 apfile=""
30 optimise=""
31 scale=""
32 width=""
33
34 getopts "hvmo:s:w:OD" name
35 while [ "$name" != "?" ] ; do
36   case $name in
37    h) help=1;;
38    v) verb=1;;
39    m) mono="-m";;
40    o) apfile="$OPTARG";;
41    s) scale="-s $OPTARG";;
42    w) width="-w $OPTARG";;
43    O) optimise="-O";;
44    D) debug="-D";;
45   esac 
46   getopts "hvmo:s:w:OD" name
47 done
48
49 opts="$mono $optimise $scale $width"
50
51 shift $[ $OPTIND - 1 ]
52
53 if [ $help -eq 1 ]
54  then no_of_lines=`cat $0 | awk 'BEGIN { n = 0; } \
55                                  /^$/ { print n; \
56                                         exit; } \
57                                       { n++; }'`
58       echo "`head -$no_of_lines $0`"
59       exit 
60 fi
61
62
63 if [ -z "$1" ]
64  then echo "Usage: $progname [options] file[.gr]"
65       echo "Use -h option for details"
66       exit 1;
67 fi
68
69 f="`basename $1 .gr`"
70 grfile="$f".gr
71 qpfile="${TMPDIR:-.}/$f".qp
72 ppfile="${TMPDIR:-.}/$f".pp
73
74 if [ -z "$apfile" ]
75   then apfile="$f"_ap.ps
76 fi
77
78 if [ $verb -eq 1 ]
79   then echo "Input file: $grfile"
80        echo "Quasi-parallel file: $qpfile"
81        echo "PostScript file: $apfile"
82        echo "Options forwarded to qp2ap: $opts"
83        if [ "$mono" = "-m" ]
84          then echo "Producing monochrome PS file"
85          else echo "Producing color PS file"
86        fi
87        if [ "$debug" = "-D" ]
88          then echo "Debugging is turned ON"
89          else echo "Debugging is turned OFF"
90        fi
91 fi
92
93
94 #  unset noclobber
95
96 if [ ! -f "$grfile" ] 
97  then
98   echo "$grfile does not exist"
99   exit 1
100  else
101   # rm -f "$qpfile" "$apfile"
102   prog=`head -1 "$grfile" | sed -e 's/Granularity Simulation for //'`
103   echo "$prog" >| "$qpfile"
104   if [ $verb -eq 1 ]
105     then echo "Executed program: $prog"
106   fi
107   date >> "$qpfile"
108   #date="`date`"                     # This is the date of running the script
109   date="`tail +2 $grfile | head -1 | sed -e 's/Start time: //'`"
110   cat "$grfile" | gr2qp >> "$qpfile"
111   # Sorting is part of gr2qp now.
112   #  | ghc-fool-sort | sort -n +0 -1 | ghc-unfool-sort >> "$qpfile"
113   # max=`tail -2 "$qpfile" | awk '!/^Number of threads:/ { print $1; }'`
114   xmax=`tail -1 "$qpfile" | awk '{ print $2; }'`
115   ymax=`tail -1 "$qpfile" | awk '{ print $8; }'`
116   if [ $verb -eq 1 ]
117     then echo "Total runtime: $xmax"
118          echo "Total number of tasks: $ymax"
119   fi
120   tail +3 "$qpfile" | qp2ap $opts "$xmax" "$ymax" "$prog" "$date" >| "$apfile" 
121   rm -f "$qpfile"
122   # Old: qp2ap.pl $mono  $max "$prog" "$date" < "$qpfile" > "$apfile"
123 fi
124