Make TcGenDeriv warning-free
[ghc-hetmet.git] / utils / parallel / gr2gran.bash
1 #!/usr/local/bin/bash
2 ##############################################################################
3 # Last modified: Time-stamp: <95/08/01 02:21:56 hwloidl>
4 #
5 # Usage: gr2gran [options] <sim-file>
6 #
7 # Create granularity graphs for the GrAnSim profile <sim-file>. This creates
8 # a bucket statistics and a cumulative runtimes graph.
9 # This script is derived from the much more complex gran-extr script, which
10 # also produces such graphs and much more information, too.
11 #
12 # Options:
13 #  -t <file>   ... use <file> as template file (<,> global <.> local template)
14 #  -p <file>   ... use <file> as gnuplot .gp file (default: gran.gp)
15 #  -x <x-size> ... of gnuplot graph
16 #  -y <y-size> ... of gnuplot graph
17 #  -n <n>      ... use <n> as number of PEs in title 
18 #  -o <file>   ... keep the intermediate <file> (sorted list of all runtimes)
19 #  -h          ... help; print this text.
20 #  -v          ... verbose mode.
21 #
22 ##############################################################################
23
24 progname="`basename $0`"
25 args="$*"
26
27 help=0
28 verb=0
29 template=""
30 plotfile=""
31 x=""
32 y=""
33 n=""
34 rtsfile=""
35 keep_rts=0
36
37 getopts "hvt:p:x:y:n:o:" name
38 while [ "$name" != "?" ] ; do
39   case $name in
40    h) help=1;;
41    v) verb=1;;
42    t) template="-t $OPTARG";;
43    p) plotfile="-p $OPTARG";;
44    x) x="-x $OPTARG";;
45    y) y="-y $OPTARG";;
46    n) n="-n $OPTARG";;
47    o) rtsfile="$OPTARG";;
48   esac 
49   getopts "hvt:p:x:y:n:o:" name
50 done
51
52 shift $[ $OPTIND - 1 ]
53
54 if [ $help -eq 1 ]
55  then no_of_lines=`cat $0 | awk 'BEGIN { n = 0; } \
56                                  /^$/ { print n; \
57                                         exit; } \
58                                       { n++; }'`
59       echo "`head -$no_of_lines $0`"
60       exit 
61 fi
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 if [ -z "$rtsfile" ]
72   then rtsfile="${f}.rts"
73        rtsopt="-o $rtsfile"
74   else rtsopt="-o $rtsfile"
75        keep_rts=1
76 fi
77
78 opts_RTS="$rtsopt "
79 opts_ps="$template $plotfile $x $y $n "
80
81 if [ $verb -eq 1 ]
82   then echo "Input file: $grfile"
83        if [ ${keep_rts} -eq 1 ]
84          then echo "Intermediate file: $rtsfile  (kept after termination)"
85          else echo "Intermediate file: $rtsfile  (discarded at end)"
86        fi
87        verb_opt="-v "
88        opts_RTS="${opts_RTS} $verb_opt "
89        opts_ps="${opts_ps} $verb_opt "
90        echo "Options for gr2RTS: ${opts_RTS}"
91        echo "Options for RTS2gran: ${opts_ps}"
92 fi
93
94
95 # unset noclobber
96 if [ ! -f "$grfile" ] 
97  then
98   echo "$grfile does not exist"
99   exit 1
100  else
101   # rm -f "$rtsfile"
102   if [ $verb -eq 1 ] 
103     then echo "gr2RTS ..."
104   fi
105   gr2RTS ${opts_RTS} $grfile
106   if [ $verb -eq 1 ] 
107     then echo "RTS2gran ..."
108   fi
109   RTS2gran ${opts_ps} $rtsfile
110   if [ ${keep_rts} -ne 1 ] 
111     then rm -f $rtsfile
112   fi
113 fi