2 ##############################################################################
3 # Time-stamp: <Wed Jul 24 1996 22:05:31 Stardate: [-31]7859.39 hwloidl>
5 # Usage: qp2ap [options] <max-x> <max-y> <prg> <date>
7 # Filter that transforms a quasi-parallel profile (a .qp file) at stdin to
8 # a PostScript file at stdout, showing an activity profile with one horizontal
9 # line for each task (thickness of the line shows if it's active or suspended).
12 # -o <file> ... write .ps file to <file>
13 # -m ... create mono PostScript file instead a color one.
14 # -O ... optimise i.e. try to minimise the size of the .ps file.
15 # -s <n> ... scaling factor of y axis (default: 1)
16 # -w <n> ... width of lines denoting running threads (default: 2)
17 # -v ... be talkative.
18 # -h ... print help message (this header).
20 ##############################################################################
25 &Getopts('hvms:w:OlD');
30 do print_verbose_message();
33 # ---------------------------------------------------------------------------
35 # ---------------------------------------------------------------------------
38 $gtid = 1; # number of process so far = $gtid-1
44 $labelx = $scalex - 45;
45 $markx = $scalex - 30;
53 if ( ($ymax - $ymin)/$pmax < 3 ) {
54 print STDERR "Warning: Too many tasks! Distance will be smaller than 3 pixels.\n";
58 $width = 2/3 * ($ymax - $ymin)/$pmax;
64 # ---------------------------------------------------------------------------
66 # ---------------------------------------------------------------------------
69 next if /^[^0-9]/; # ignore lines not beginning with a digit (esp. last)
71 ($time, $event, $tid, $addr, $tid2, $addr2) = split;
73 if ( $event eq "*G") {
74 $TID{$addr} = $gtid++;
75 $START{$addr} = $time;
78 elsif ($event eq "*A") {
79 $TID{$addr} = $gtid++;
80 $SUSPEND{$addr} = $time;
83 elsif ($event eq "G*" || $event eq "GR" ) {
84 do psout($START{$addr},$time,$TID{$addr},"runlineto");
85 # $STOP{$addr} = $time;
88 elsif ($event eq "GA" || $event eq "GC" || $event eq "GY") {
89 do psout($START{$addr},$time,$TID{$addr},"runlineto");
90 $SUSPEND{$addr} = $time;
93 elsif ($event eq "RA") {
94 $SUSPEND{$addr} = $time;
97 elsif ($event eq "YR") {
98 do psout($SUSPEND{$addr},$time,$TID{$addr},"fetchlineto");
101 elsif ($event eq "CA" || $event eq "YA" ) {
102 do psout($SUSPEND{$addr},$time,$TID{$addr},"fetchlineto");
103 $SUSPEND{$addr} = $time;
106 elsif ($event eq "AC" || $event eq "AY" ) {
107 do psout($SUSPEND{$addr},$time,$TID{$addr},"suspendlineto");
108 $SUSPEND{$addr} = $time;
111 elsif ($event eq "RG") {
112 $START{$addr} = $time;
115 elsif ($event eq "AG") {
116 do psout($SUSPEND{$addr},$time,$TID{$addr},"suspendlineto");
117 $START{$addr} = $time;
120 elsif ($event eq "CG" || $event eq "YG" ) {
121 do psout($SUSPEND{$addr},$time,$TID{$addr},"fetchlineto");
122 $START{$addr} = $time;
123 } elsif ( $event eq "B*" || $event eq "*B" || $event eq "BB" ) {
124 print STDERR "Ignoring spark event $event at $time\n" if $opt_v;
126 print STDERR "Unexpected event $event at $time\n";
129 print("%% $time: $event $addr $TID{$addr}\n\n") if $opt_D;
132 # ---------------------------------------------------------------------------
135 print("HE14 setfont\n");
137 print("50 550 asciilogo\n");
139 print("50 550 logo\n"); #
145 if ( $gtid-1 != $pmax ) {
147 die "Error: Calculated max no. of tasks ($gtid-1) does not agree with stated max. no. of tasks ($pmax)\n";
149 print STDERR "Warning: Calculated total no. of tasks ($gtid-1) does not agree with stated total no. of tasks ($pmax)\n" if $opt_v;
150 $y_scaling = $pmax/($gtid-1);
157 # ---------------------------------------------------------------------------
160 local($x1, $x2, $y, $cmd) = @_;
161 print("% ($x1,$y) -- ($x2,$y) $cmd\n") if $opt_D;
162 $x1 = int(($x1/$tmax) * ($xmax-$xmin) + $xmin);
163 $x2 = int(($x2/$tmax) * ($xmax-$xmin) + $xmin);
164 $y = int(($y/$pmax) * ($ymax-$ymin) + $ymin);
171 print("$x1 $y moveto\n");
172 print("$x2 $y $cmd\n");
175 print "$x1 $x2 $y " .
176 ( $cmd eq "runlineto" ? "G RL\n" :
177 $cmd eq "suspendlineto" ? "R SL\n" :
178 $cmd eq "fetchlineto" ? "B FL\n" :
179 "\n% ERROR: Unknown command $cmd\n");
182 print "$x2 $y $x1 $y " .
183 ( $cmd eq "runlineto" ? "green run\n" :
184 $cmd eq "suspendlineto" ? "red suspend\n" :
185 $cmd eq "fetchlineto" ? "blue fetch\n" :
186 "\n% ERROR: Unknown command $cmd\n");
190 # -----------------------------------------------------------------------------
195 chop($date = `date`);
199 # -----------------------------------------------------------------------------
204 $now = do get_date();
206 print("%!PS-Adobe-2.0\n");
207 print("%%BoundingBox: 0 0 560 800\n");
208 print("%%Title: Per-thread Activity Profile\n");
209 print("%%Creator: qp2ap\n");
210 print("%%StartTime: $date\n");
211 print("%%CreationDate: $now\n");
212 print("%%Copyright: 1995, 1996 by Hans-Wolfgang Loidl, University of Glasgow\n");
213 print("%%EndComments\n");
215 print "% " . "-" x 77 . "\n";
216 print "% Tunable Parameters:\n";
217 print "% The width of a line representing a task\n";
218 print "/width $width def\n";
219 print "% Scaling factor for the y-axis (usful to enlarge)\n";
220 print "/y-scale $y_scale def\n";
221 print "% " . "-" x 77 . "\n";
223 print "/total-len $tmax def\n";
224 print "/show-len $xmax def\n";
225 print "/x-offset $xmin def\n";
226 print "/y-offset $ymin def\n";
227 print "% normalize is the PS version of the formula: \n" .
228 "% int(($x1/$tmax) * ($xmax-$xmin) + $xmin) \n" .
230 print "/normalize { total-len div show-len x-offset sub mul x-offset add floor } def\n";
231 print "/x-normalize { exch show-len mul total-len div exch } def\n";
232 print "/y-normalize { y-offset sub y-scale mul y-offset add } def\n";
233 print "/str-len 12 def\n";
234 print "/prt-n { cvi str-len string cvs \n" .
235 " dup stringwidth pop \n" .
236 " currentpoint pop 780 gt { 10 sub } { 2 div } ifelse \n" .
237 " neg 0 rmoveto \n" .
239 " % print top-of-stack integer centered at the current point\n";
240 # print "/prt-n { cvi str-len string cvs \n" .
241 # " dup stringwidth pop 2 div neg 0 rmoveto \n" .
243 # " % print top-of-stack integer centered at the current point\n";
246 print ("/runlineto {1.5 setlinewidth lineto} def\n");
247 print ("/suspendlineto {0.5 setlinewidth lineto} def\n");
248 print ("/fetchlineto {0.2 setlinewidth lineto} def\n");
252 print "/R { 0 } def\n";
253 print "/G { 0.5 } def\n";
254 print "/B { 0.2 } def\n";
256 print "/red { 0 } def\n";
257 print "/green { 0.5 } def\n";
258 print "/blue { 0.2 } def\n";
260 print "/set-bg { setgray } def\n";
263 print "/R { 0.8 0 0 } def\n";
264 print "/G { 0 0.9 0.1 } def\n";
265 print "/B { 0 0.1 0.9 } def\n";
266 print "/set-bg { setrgbcolor } def\n";
268 print "/red { 0.8 0 0 } def\n";
269 print "/green { 0 0.9 0.1 } def\n";
270 print "/blue { 0 0.1 0.9 } def\n";
271 print "/set-bg { setrgbcolor } def\n";
276 print "% RL: runlineto; draws a horizontal line in given color\n";
277 print "% Operands: x-from x-to y color\n";
278 print "/RL { set-bg % set color \n" .
279 " newpath y-normalize % mangle y val\n" .
280 " 2 index 1 index moveto width setlinewidth \n" .
281 " lineto pop stroke} def\n";
282 print "% SL: suspendlineto; draws a horizontal line in given color (thinner)\n";
283 print "% Operands: x-from x-to y color\n";
284 print "/SL { set-bg % set color \n" .
285 " newpath y-normalize % mangle y val\n" .
286 " 2 index 1 index moveto width 2 div setlinewidth \n" .
287 " lineto pop stroke} def\n";
288 print "% FL: fetchlineto; draws a horizontal line in given color (thinner)\n";
289 print "% Operands: x-from x-to y color\n";
290 print "/FL { set-bg % set color \n" .
291 " newpath y-normalize % mangle y val\n" .
292 " 2 index 1 index moveto width " .
293 ( $opt_m ? " 4 " : " 2 ") .
294 " div setlinewidth \n" .
295 " lineto pop stroke} def\n";
297 print "/run { set-bg newpath 50 sub y-scale mul 50 add moveto width " .
298 "setlinewidth 50 sub y-scale mul 50 add lineto stroke} def\n";
299 print "/suspend { set-bg newpath 50 sub y-scale mul 50 add moveto width " .
300 "2 div setlinewidth 50 sub y-scale mul 50 add lineto stroke} def\n";
301 print "/fetch { set-bg newpath 50 sub y-scale mul 50 add moveto width " .
302 ( $opt_m ? " 4 " : " 2 ") .
303 "div setlinewidth 50 sub y-scale mul 50 add lineto stroke} def\n";
304 #print ("/run { newpath moveto 1.5 setlinewidth lineto stroke} def\n");
305 #print ("/suspend { newpath moveto 0.5 setlinewidth lineto stroke} def\n");
309 print "/printText { 0 0 moveto (GrAnSim) show } def\n";
310 print "/asciilogo { 5 sub moveto HB16 setfont (GrAnSim) show } def\n";
312 print "/logo { asciilogo } def\n";
314 print "/logo { gsave \n" .
317 " { dup 1 exch sub 0 exch setrgbcolor printText 1 -.5 translate } for \n" .
318 " 1 0 0 setrgbcolor printText\n" .
321 print "% For debugging PS uncomment this line and add the file behandler.ps\n";
322 print "% $brkpage begin printonly endprint \n";
324 print("/HE10 /Helvetica findfont 10 scalefont def\n");
325 print("/HE12 /Helvetica findfont 12 scalefont def\n");
326 print("/HE14 /Helvetica findfont 14 scalefont def\n");
327 print("/HB16 /Helvetica-Bold findfont 16 scalefont def\n");
328 print "% " . "-" x 77 . "\n";
331 print("-90 rotate\n");
332 print("-785 30 translate\n");
333 print("0 8.000000 moveto\n");
334 print("0 525.000000 760.000000 525.000000 8.000000 arcto\n");
335 print("4 {pop} repeat\n");
336 print("760.000000 525.000000 760.000000 0 8.000000 arcto\n");
337 print("4 {pop} repeat\n");
338 print("760.000000 0 0 0 8.000000 arcto\n");
339 print("4 {pop} repeat\n");
340 print("0 0 0 525.000000 8.000000 arcto\n");
341 print("4 {pop} repeat\n");
342 print("0.500000 setlinewidth\n");
345 print("4.000000 505.000000 moveto\n");
346 print("4.000000 521.000000 752.000000 521.000000 4.000000 arcto\n");
347 print("4 {pop} repeat\n");
348 print("752.000000 521.000000 752.000000 501.000000 4.000000 arcto\n");
349 print("4 {pop} repeat\n");
350 print("752.000000 501.000000 4.000000 501.000000 4.000000 arcto\n");
351 print("4 {pop} repeat\n");
352 print("4.000000 501.000000 4.000000 521.000000 4.000000 arcto\n");
353 print("4 {pop} repeat\n");
354 print("0.500000 setlinewidth\n");
357 print("HE14 setfont\n");
358 print("100 505 moveto\n");
359 print("($pname ) show\n");
361 print("($date) dup stringwidth pop 750 exch sub 505.000000 moveto show\n");
363 # print "/total-len $tmax def\n";
364 print("-40 -40 translate\n");
366 print "% " . "-" x 77 . "\n";
367 print "% Print x-axis:\n";
368 print "/y-val $ymin def % { y-offset 40 sub 2 div y-offset add } def\n";
369 print "0.5 setlinewidth\n";
370 print "x-offset y-val moveto total-len normalize x-offset sub 0 rlineto stroke\n";
371 print "0 total-len 10 div total-len\n" .
372 " { dup normalize dup y-val moveto 0 -2 rlineto stroke % tic\n" .
373 " y-val 10 sub moveto HE10 setfont round prt-n % print label \n" .
375 print "1 setlinewidth\n";
376 print "% " . "-" x 77 . "\n";
380 # -----------------------------------------------------------------------------
384 local ($y, $smax,$majormax, $majorint);
388 print "% " . ("-" x 75) . "\n";
390 print "% " . ("-" x 75) . "\n";
395 print "0 0 0 setrgbcolor\n";
399 print("HE12 setfont\n");
401 print("dup stringwidth pop\n");
404 print("$labelx exch\n");
405 print("translate\n");
406 print("90 rotate\n");
407 print("0 0 moveto\n");
413 if ($pmax < $majorticks) {
417 print "0.5 setlinewidth\n";
419 print("HE12 setfont\n$scalex $ymin moveto\n$scalex $ymax lineto\n");
420 print("% Total number of tasks: $pmax\n");
421 print("% Number of ticks: $majorticks\n");
423 $y = $ymax; # (($pmax - $ymin)/$majorticks) * ($majorticks-$i) + $ymin;
424 print("$scalex $y moveto\n$major $y lineto\n");
425 print("$markx $y moveto\n($pmax) show\n");
427 $majormax = int($pmax/$majorticks)*$majorticks;
428 $smax = $majormax*(($ymax-$ymin)/$pmax)+$ymin;
429 $majorint = $majormax/$majorticks;
431 for($i=0; $i <= $majorticks; ++$i) {
432 $y = (($smax - $ymin)/$majorticks) * ($majorticks-$i) + $ymin;
433 $majorval = int($majorint * ($majormax/$majorint-$i));
434 print("$scalex $y moveto\n$major $y lineto\n");
435 print("$markx $y moveto\n($majorval) show\n");
438 # print("$xmin $ymax moveto\n10 0 rlineto\n10 0 rmoveto\n($pmax) show\n");
440 print "1 setlinewidth\n";
441 print "% " . ("-" x 75) . "\n";
444 # ---------------------------------------------------------------------------
446 sub print_verbose_message {
448 print "Prg Name: $pname Date: $date\n";
449 print "Input: stdin Output: stdout\n";
452 # ----------------------------------------------------------------------------
454 sub process_options {
457 open(ME,$0) || die "Can't open myself ($0): $!\n";
475 print "Usage: $0 [options] <max x value> <max y value> <prg name> <date> \n";
476 print "Use -h option to get details\n";
482 # GUM uses the absolute path (with '=' instead of '/') of the executed file
483 # (for PVM reasons); if you want to have the full path in the generated
484 # graph, too, eliminate the substitution below
485 ($pname = $ARGV[2]) =~ s/.*=//;
495 # -----------------------------------------------------------------------------