[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / utils / parallel / gr2ps.bash
1 #!/usr/local/bin/bash
2 ##############################################################################
3 #
4 # Usage: gr2ps [options] <gr-file>
5 #
6 # Transform the log file of a GrAnSim run (a .gr file) into a quasi-parallel
7 # profile (a .qp file) and then into a PostScript file, showing essentially
8 # the total number of running, runnable and blocked tasks.
9 #
10 # Options:
11 #  -o <file> ... write PS file to <file>
12 #  -i <int>  ... info level from 1 to 7; number of queues to display
13 #  -m        ... create mono PostScript file instead a color one.
14 #  -O        ... optimize the produced .ps w.r.t. size
15 #                NB: With this option info is lost. If there are several values
16 #                    with same x value only the first one is printed, all 
17 #                    others are dropped.
18 #  -s <str>  ... print <str> in the top right corner of the generated graph
19 #  -v        ... be talkative. 
20 #  -h        ... print help message (this header).
21 #
22 ##############################################################################
23
24 ##############################################################################
25 # Internal comments:
26 # ----------------------------------------------------------------------
27 # This version works on both Suns and Alphas -- KH
28 # Any volunteers to convert it to /bin/sh?
29 # Next time somebody calls for volunteers I'd better keep my mouth shut ... HWL
30 ##############################################################################
31
32 progname="`basename $0`"
33 args="$*"
34
35 verb=0
36 help=0
37 mono=""
38 psfile=""
39 debug=""
40 optimize=""
41 info_level=0
42 info_mask=""
43 string=""
44
45 getopts "hvmDOSs:o:i:I:" name
46 while [ "$name" != "?" ] ; do
47   case $name in
48    h) help=1;;
49    v) verb=1;;
50    m) mono="-m";;
51    D) debug="-D";;
52    O) optimize="-O";;
53    S) lines="-S";;
54    s) string=$OPTARG;;
55    i) info_level=$OPTARG;;
56    I) info_mask=$OPTARG;;
57    o) psfile=$OPTARG;;
58   esac 
59   getopts "hvmDOSs:o:i:I:" name
60 done
61
62 shift $[ $OPTIND - 1 ]
63
64 if [ -z "$1" ]
65  then echo "usage: $progname [-m] file[.gr]"
66       exit 1;
67 fi
68
69 f="`basename $1 .gr`"
70 grfile="$f".gr
71 qpfile="$f".qp
72 ppfile="$f".pp
73
74 if [ -z "$psfile" ]
75   then psfile="$f".ps
76 fi
77
78 if [ $help -eq 1 ]
79  then no_of_lines=`cat $0 | awk 'BEGIN { n = 0; } \
80                                  /^$/ { print n; \
81                                         exit; } \
82                                       { n++; }'`
83       echo "`head -$no_of_lines $0`"
84       exit 
85 fi
86
87 if [ $verb -eq 1 ]
88   then echo "Input file: $grfile"
89        echo "Quasi-parallel file: $qpfile"
90        echo "PP file: $ppfile"
91        echo "PostScript file: $psfile"
92        if [ "$mono" = "-m" ]
93          then echo "Producing monochrome PS file"
94          else echo "Producing color PS file"
95        fi
96        if [ "$optimize" = "-O" ]
97          then echo "Optimization is ON"
98          else echo "Optimization is OFF"
99        fi
100        if [ "$debug" = "-D" ]
101          then echo "Debugging is turned ON"
102          else echo "Debugging is turned OFF"
103        fi
104 fi
105
106
107 # unset noclobber
108 if [ ! -f "$grfile" ] 
109  then
110   echo "$grfile does not exist"
111   exit 1
112  else
113   rm -f "$qpfile" "$psfile"
114   prog=`head -1 "$grfile" | sed -e 's/Granularity Simulation for //'`
115   echo "$prog" >| "$qpfile"
116   if [ $verb -eq 1 ]; then echo "Executed program: $prog"; fi
117   date >> "$qpfile"
118   date="`date`"
119   cat "$grfile" | gr2qp | ghc-fool-sort | sort -n +0 -1 | ghc-unfool-sort >> "$qpfile"
120   # max=`tail -2 "$qpfile" | awk '!/^Number of threads:/ { print $1; }'`
121   max=`tail -1 "$qpfile" | awk '{ print $1; }'`
122   if [ $verb -eq 1 ]; then echo "Total runtime: $max"; fi
123   opts="";
124   if [ $info_level -gt 0 ]
125     then opts="-i $info_level";
126   fi 
127   if [ -n "$info_mask" ]
128     then opts="-I $info_mask";
129   fi 
130   tail +3 "$qpfile" | qp2ps $debug $optimize $mono $lines "-s" "$string" $opts  "$max" "$prog" "$date" >| "$psfile"
131   rm -f "$qpfile"
132 fi
133
134   
135
136