[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / utils / parallel / gr2ps.bash
1 #!/usr/local/bin/bash
2 ##############################################################################
3 # Time-stamp: <Wed Jul 24 1996 22:11:13 Stardate: [-31]7859.41 hwloidl>
4 #
5 # Usage: gr2ps [options] <gr-file>
6 #
7 # Create an overall 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 qp2ps.
10 # The generated PostScript file shows essentially the number of running, 
11 # runnable and blocked tasks during the execution of the program.
12 #
13 # Options:
14 #  -o <file> ... write .ps file to <file>
15 #  -I <str>  ... queues to be displayed (in the given order) with the encoding
16 #                 'a' ... active (running)
17 #                 'r' ... runnable
18 #                 'b' ... blocked
19 #                 'f' ... fetching
20 #                 'm' ... migrating
21 #                 's' ... sparks
22 #                (e.g. -I "arb" shows active, runnable, blocked tasks)
23 #  -i <int>  ... info level from 1 to 7; number of queues to display
24 #  -m        ... create mono PostScript file instead a color one.
25 #  -O        ... optimise the produced .ps w.r.t. size
26 #                NB: With this option info is lost. If there are several values
27 #                    with same x value only the first one is printed, all 
28 #                    others are dropped.
29 #  -s <str>  ... print <str> in the top right corner of the generated graph
30 #  -S        ... improved version of sorting events
31 #  -l <int>  ... length of slice in the .ps file; (default: 100)
32 #                small value => less memory consumption of .ps file & script
33 #  -d        ... Print date instead of average parallelism
34 #  -v        ... be talkative. 
35 #  -h        ... print help message (this header).
36 #
37 ##############################################################################
38
39 progname="`basename $0`"
40 args="$*"
41
42 verb=0
43 help=0
44 mono=""
45 psfile=""
46 debug=""
47 optimise=""
48 info_level=""
49 info_mask=""
50 string=""
51 length=""
52 force_date=""
53 hack=""
54
55 getopts "hvmDCOHSdl:s:o:i:I:" name
56 while [ "$name" != "?" ] ; do
57   case $name in
58    h) help=1;;
59    v) verb=1;;
60    m) mono="-m";;
61    D) debug="-D";;
62    C) check="-C";;
63    O) optimise="-O";;
64    d) force_date="-d";;
65    H) hack="-H";;
66    S) improved_sort="-S";;
67    s) string="-s $OPTARG";;
68    l) length="-l $OPTARG";;
69    i) info_level="-i $OPTARG";;
70    I) info_mask="-I $OPTARG";;
71    o) psfile=$OPTARG;;
72   esac 
73   getopts "hvmDCOHSdl:s:o:i:I:" name
74 done
75
76 opts_qp="$debug $info_level $info_mask $improved_sort "
77 opts_ps="$debug $check $optimise $mono $string $length $info_level $info_mask $force_date $hack "
78
79 shift $[ $OPTIND - 1 ]
80
81 if [ $help -eq 1 ]
82  then no_of_lines=`cat $0 | awk 'BEGIN { n = 0; } \
83                                  /^$/ { print n; \
84                                         exit; } \
85                                       { n++; }'`
86       echo "`head -$no_of_lines $0`"
87       exit 
88 fi
89
90 if [ -z "$1" ]
91  then echo "Usage: $progname [options] file[.gr]"
92       echo "Use -h option for details"
93       exit 1;
94 fi
95
96 f="`basename $1 .gr`"
97 grfile="$f".gr
98 qpfile="${TMPDIR:-.}/$f".qp
99 ppfile="${TMPDIR:-.}/$f".pp
100
101 if [ -z "$psfile" ]
102   then psfile="$f".ps
103 fi
104
105 if [ $verb -eq 1 ]
106   then echo "Input file: $grfile"
107        echo "Quasi-parallel file: $qpfile"
108        echo "PP file: $ppfile"
109        echo "PostScript file: $psfile"
110        if [ -n "$mono" ]
111          then echo "Producing monochrome PS file"
112          else echo "Producing color PS file"
113        fi
114        if [ -n "$optimise" ]
115          then echo "Optimisation is ON"
116          else echo "Optimisation is OFF"
117        fi
118        if [ -n "$debug" ]
119          then echo "Debugging is turned ON"
120          else echo "Debugging is turned OFF"
121        fi
122        if [ -n "$improved_sort" ]
123          then echo "Improved sort is turned ON"
124          else echo "Improved sort is turned OFF"
125        fi
126        verb_opt="-v "
127        opts_qp="${opts_qp} $verb_opt "
128        opts_ps="${opts_ps} $verb_opt "
129        echo "Options for gr2qp: ${opts_qp}"
130        echo "Options for qp2ps: ${opts_ps}"
131 fi
132
133
134 # unset noclobber
135 if [ ! -f "$grfile" ] 
136  then
137   echo "$grfile does not exist"
138   exit 1
139  else
140   rm -f "$qpfile" "$psfile"
141   prog=`head -1 "$grfile" | sed -e 's/Granularity Simulation for //'`
142   echo "$prog" >| "$qpfile"
143   if [ $verb -eq 1 ] 
144     then echo "Executed program: $prog" 
145   fi
146   date >> "$qpfile"
147   #date="`date`"                     # This is the date of running the script
148   date="`tail +2 $grfile | head -1 | sed -e 's/Start time: //'`"
149   cat "$grfile" | gr2qp ${opts_qp} >> "$qpfile"
150   # Sorting is part of gr2qp now.
151   #  | ghc-fool-sort | sort -n +0 -1 | ghc-unfool-sort >> "$qpfile"
152   # max=`tail -2 "$qpfile" | awk '!/^Number of threads:/ { print $1; }'`
153   xmax=`tail -1 "$qpfile" | awk '{ print $2; }'`
154   ymax=`tail -1 "$qpfile" | awk '{ print $4; }'`
155   if [ $verb -eq 1 ] 
156     then echo "Total runtime: $xmax"
157          echo "Maximal number of tasks: $ymax"
158   fi
159   tail +3 "$qpfile" | qp2ps ${opts_ps} "$xmax" "$ymax" "$prog" "$date" >| "$psfile"
160   rm -f "$qpfile"
161   if [ $verb -eq 1 ] 
162     then echo "Scaling (maybe): ps-scale-y $psfile " 
163   fi
164   ps-scale-y "$psfile"
165 fi
166
167   
168
169