[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / utils / parallel / gr2jv.bash
1 #!/usr/local/bin/bash
2 ##############################################################################
3 # Time-stamp: <Wed Jul 24 1996 20:38:02 Stardate: [-31]7859.09 hwloidl>
4 #
5 # Usage: gr3jv [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 gr3qp and then into a PostScript file using qp3ap.
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="$f".qp
72 ppfile="$f".pp
73 jvfile="$f".jv
74
75 if [ -z "$apfile" ]
76   then apfile="$f"-ap.ps
77 fi
78
79 if [ $verb -eq 1 ]
80   then echo "Input file: $grfile"
81        echo "Quasi-parallel file: $qpfile"
82        echo "PostScript file: $apfile"
83        echo "Options forwarded to qp3ap: $opts"
84        if [ "$mono" = "-m" ]
85          then echo "Producing monochrome PS file"
86          else echo "Producing color PS file"
87        fi
88        if [ "$debug" = "-D" ]
89          then echo "Debugging is turned ON"
90          else echo "Debugging is turned OFF"
91        fi
92 fi
93
94
95 #  unset noclobber
96
97 if [ ! -f "$grfile" ] 
98  then
99   echo "$grfile does not exist"
100   exit 1
101  else
102   # rm -f "$qpfile" "$apfile"
103   prog=`head -1 "$grfile" | sed -e 's/Granularity Simulation for //'`
104   echo "$prog" >| "$jvfile"
105   if [ $verb -eq 1 ]
106     then echo "Executed program: $prog"
107   fi
108   date >> "$jvfile"
109   #date="`date`"                     # This is the date of running the script
110   date="`tail +2 $grfile | head -1 | sed -e 's/Start-Time: //'`"
111   cat "$grfile" | gr2java >> "$jvfile"
112   # Sorting is part of gr2qp now.
113   #  | ghc-fool-sort | sort -n +0 -1 | ghc-unfool-sort >> "$qpfile"
114   # max=`tail -2 "$qpfile" | awk '!/^Number of threads:/ { print $1; }'`
115   xmax=`tail -1 "$jvfile" | awk '{ print $2; }'`
116   ymax=`tail -1 "$jvfile" | awk '{ print $8; }'`
117   if [ $verb -eq 1 ]
118     then echo "Total runtime: $xmax"
119          echo "Total number of tasks: $ymax"
120   fi
121   # Old: qp2ap.pl $mono  $max "$prog" "$date" < "$qpfile" > "$apfile"
122 fi
123