PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/ghc-7.0.4/utils/parallel/qp2ap.pl

http://picorec.googlecode.com/
Perl | 495 lines | 372 code | 76 blank | 47 comment | 49 complexity | f13a57bfc61281bd17acc413c7d1593c MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause
  1. #! /usr/local/bin/perl
  2. ##############################################################################
  3. # Time-stamp: <Wed Jul 24 1996 22:05:31 Stardate: [-31]7859.39 hwloidl>
  4. #
  5. # Usage: qp2ap [options] <max-x> <max-y> <prg> <date>
  6. #
  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).
  10. #
  11. # Options:
  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).
  19. #
  20. ##############################################################################
  21. require "getopts.pl";
  22. &Getopts('hvms:w:OlD');
  23. do process_options();
  24. if ( $opt_v ) {
  25. do print_verbose_message();
  26. }
  27. # ---------------------------------------------------------------------------
  28. # Init
  29. # ---------------------------------------------------------------------------
  30. $y_scaling = 0;
  31. $gtid = 1; # number of process so far = $gtid-1
  32. $xmin = 100;
  33. $xmax = 790;
  34. $scalex = $xmin;
  35. $labelx = $scalex - 45;
  36. $markx = $scalex - 30;
  37. $major = $scalex - 5;
  38. $majorticks = 10;
  39. # $pmax = 40;
  40. $ymin = 50;
  41. $ymax = 500;
  42. if ( ($ymax - $ymin)/$pmax < 3 ) {
  43. print STDERR "Warning: Too many tasks! Distance will be smaller than 3 pixels.\n";
  44. }
  45. if ( !$width ) {
  46. $width = 2/3 * ($ymax - $ymin)/$pmax;
  47. }
  48. do write_prolog();
  49. do print_y_axis();
  50. # ---------------------------------------------------------------------------
  51. # Main Part
  52. # ---------------------------------------------------------------------------
  53. while(<STDIN>) {
  54. next if /^[^0-9]/; # ignore lines not beginning with a digit (esp. last)
  55. chop;
  56. ($time, $event, $tid, $addr, $tid2, $addr2) = split;
  57. if ( $event eq "*G") {
  58. $TID{$addr} = $gtid++;
  59. $START{$addr} = $time;
  60. }
  61. elsif ($event eq "*A") {
  62. $TID{$addr} = $gtid++;
  63. $SUSPEND{$addr} = $time;
  64. }
  65. elsif ($event eq "G*" || $event eq "GR" ) {
  66. do psout($START{$addr},$time,$TID{$addr},"runlineto");
  67. # $STOP{$addr} = $time;
  68. }
  69. elsif ($event eq "GA" || $event eq "GC" || $event eq "GY") {
  70. do psout($START{$addr},$time,$TID{$addr},"runlineto");
  71. $SUSPEND{$addr} = $time;
  72. }
  73. elsif ($event eq "RA") {
  74. $SUSPEND{$addr} = $time;
  75. }
  76. elsif ($event eq "YR") {
  77. do psout($SUSPEND{$addr},$time,$TID{$addr},"fetchlineto");
  78. }
  79. elsif ($event eq "CA" || $event eq "YA" ) {
  80. do psout($SUSPEND{$addr},$time,$TID{$addr},"fetchlineto");
  81. $SUSPEND{$addr} = $time;
  82. }
  83. elsif ($event eq "AC" || $event eq "AY" ) {
  84. do psout($SUSPEND{$addr},$time,$TID{$addr},"suspendlineto");
  85. $SUSPEND{$addr} = $time;
  86. }
  87. elsif ($event eq "RG") {
  88. $START{$addr} = $time;
  89. }
  90. elsif ($event eq "AG") {
  91. do psout($SUSPEND{$addr},$time,$TID{$addr},"suspendlineto");
  92. $START{$addr} = $time;
  93. }
  94. elsif ($event eq "CG" || $event eq "YG" ) {
  95. do psout($SUSPEND{$addr},$time,$TID{$addr},"fetchlineto");
  96. $START{$addr} = $time;
  97. } elsif ( $event eq "B*" || $event eq "*B" || $event eq "BB" ) {
  98. print STDERR "Ignoring spark event $event at $time\n" if $opt_v;
  99. } else {
  100. print STDERR "Unexpected event $event at $time\n";
  101. }
  102. print("%% $time: $event $addr $TID{$addr}\n\n") if $opt_D;
  103. }
  104. # ---------------------------------------------------------------------------
  105. # Logo
  106. print("HE14 setfont\n");
  107. if ( $opt_m ) {
  108. print("50 550 asciilogo\n");
  109. } else {
  110. print("50 550 logo\n"); #
  111. }
  112. # Epilogue
  113. print("showpage\n");
  114. if ( $gtid-1 != $pmax ) {
  115. if ( $pedantic ) {
  116. die "Error: Calculated max no. of tasks ($gtid-1) does not agree with stated max. no. of tasks ($pmax)\n";
  117. } else {
  118. print STDERR "Warning: Calculated total no. of tasks ($gtid-1) does not agree with stated total no. of tasks ($pmax)\n" if $opt_v;
  119. $y_scaling = $pmax/($gtid-1);
  120. }
  121. }
  122. exit 0;
  123. # ---------------------------------------------------------------------------
  124. sub psout {
  125. local($x1, $x2, $y, $cmd) = @_;
  126. print("% ($x1,$y) -- ($x2,$y) $cmd\n") if $opt_D;
  127. $x1 = int(($x1/$tmax) * ($xmax-$xmin) + $xmin);
  128. $x2 = int(($x2/$tmax) * ($xmax-$xmin) + $xmin);
  129. $y = int(($y/$pmax) * ($ymax-$ymin) + $ymin);
  130. if ( $x1 == $x2 ) {
  131. $x2 = $x1 + 1;
  132. }
  133. if ( $opt_l ) {
  134. print("newpath\n");
  135. print("$x1 $y moveto\n");
  136. print("$x2 $y $cmd\n");
  137. print("stroke\n");
  138. } elsif ( $opt_O ) {
  139. print "$x1 $x2 $y " .
  140. ( $cmd eq "runlineto" ? "G RL\n" :
  141. $cmd eq "suspendlineto" ? "R SL\n" :
  142. $cmd eq "fetchlineto" ? "B FL\n" :
  143. "\n% ERROR: Unknown command $cmd\n");
  144. } else {
  145. print "$x2 $y $x1 $y " .
  146. ( $cmd eq "runlineto" ? "green run\n" :
  147. $cmd eq "suspendlineto" ? "red suspend\n" :
  148. $cmd eq "fetchlineto" ? "blue fetch\n" :
  149. "\n% ERROR: Unknown command $cmd\n");
  150. }
  151. }
  152. # -----------------------------------------------------------------------------
  153. sub get_date {
  154. local ($date);
  155. chop($date = `date`);
  156. return ($date);
  157. }
  158. # -----------------------------------------------------------------------------
  159. sub write_prolog {
  160. local ($now);
  161. $now = do get_date();
  162. print("%!PS-Adobe-2.0\n");
  163. print("%%BoundingBox: 0 0 560 800\n");
  164. print("%%Title: Per-thread Activity Profile\n");
  165. print("%%Creator: qp2ap\n");
  166. print("%%StartTime: $date\n");
  167. print("%%CreationDate: $now\n");
  168. print("%%Copyright: 1995, 1996 by Hans-Wolfgang Loidl, University of Glasgow\n");
  169. print("%%EndComments\n");
  170. print "% " . "-" x 77 . "\n";
  171. print "% Tunable Parameters:\n";
  172. print "% The width of a line representing a task\n";
  173. print "/width $width def\n";
  174. print "% Scaling factor for the y-axis (usful to enlarge)\n";
  175. print "/y-scale $y_scale def\n";
  176. print "% " . "-" x 77 . "\n";
  177. print "/total-len $tmax def\n";
  178. print "/show-len $xmax def\n";
  179. print "/x-offset $xmin def\n";
  180. print "/y-offset $ymin def\n";
  181. print "% normalize is the PS version of the formula: \n" .
  182. "% int(($x1/$tmax) * ($xmax-$xmin) + $xmin) \n" .
  183. "% in psout.\n";
  184. print "/normalize { total-len div show-len x-offset sub mul x-offset add floor } def\n";
  185. print "/x-normalize { exch show-len mul total-len div exch } def\n";
  186. print "/y-normalize { y-offset sub y-scale mul y-offset add } def\n";
  187. print "/str-len 12 def\n";
  188. print "/prt-n { cvi str-len string cvs \n" .
  189. " dup stringwidth pop \n" .
  190. " currentpoint pop 780 gt { 10 sub } { 2 div } ifelse \n" .
  191. " neg 0 rmoveto \n" .
  192. " show } def \n" .
  193. " % print top-of-stack integer centered at the current point\n";
  194. # print "/prt-n { cvi str-len string cvs \n" .
  195. # " dup stringwidth pop 2 div neg 0 rmoveto \n" .
  196. # " show } def \n" .
  197. # " % print top-of-stack integer centered at the current point\n";
  198. if ( $opt_l ) {
  199. print ("/runlineto {1.5 setlinewidth lineto} def\n");
  200. print ("/suspendlineto {0.5 setlinewidth lineto} def\n");
  201. print ("/fetchlineto {0.2 setlinewidth lineto} def\n");
  202. } else {
  203. if ( $opt_m ) {
  204. if ( $opt_O ) {
  205. print "/R { 0 } def\n";
  206. print "/G { 0.5 } def\n";
  207. print "/B { 0.2 } def\n";
  208. } else {
  209. print "/red { 0 } def\n";
  210. print "/green { 0.5 } def\n";
  211. print "/blue { 0.2 } def\n";
  212. }
  213. print "/set-bg { setgray } def\n";
  214. } else {
  215. if ( $opt_O ) {
  216. print "/R { 0.8 0 0 } def\n";
  217. print "/G { 0 0.9 0.1 } def\n";
  218. print "/B { 0 0.1 0.9 } def\n";
  219. print "/set-bg { setrgbcolor } def\n";
  220. } else {
  221. print "/red { 0.8 0 0 } def\n";
  222. print "/green { 0 0.9 0.1 } def\n";
  223. print "/blue { 0 0.1 0.9 } def\n";
  224. print "/set-bg { setrgbcolor } def\n";
  225. }
  226. }
  227. if ( $opt_O ) {
  228. print "% RL: runlineto; draws a horizontal line in given color\n";
  229. print "% Operands: x-from x-to y color\n";
  230. print "/RL { set-bg % set color \n" .
  231. " newpath y-normalize % mangle y val\n" .
  232. " 2 index 1 index moveto width setlinewidth \n" .
  233. " lineto pop stroke} def\n";
  234. print "% SL: suspendlineto; draws a horizontal line in given color (thinner)\n";
  235. print "% Operands: x-from x-to y color\n";
  236. print "/SL { set-bg % set color \n" .
  237. " newpath y-normalize % mangle y val\n" .
  238. " 2 index 1 index moveto width 2 div setlinewidth \n" .
  239. " lineto pop stroke} def\n";
  240. print "% FL: fetchlineto; draws a horizontal line in given color (thinner)\n";
  241. print "% Operands: x-from x-to y color\n";
  242. print "/FL { set-bg % set color \n" .
  243. " newpath y-normalize % mangle y val\n" .
  244. " 2 index 1 index moveto width " .
  245. ( $opt_m ? " 4 " : " 2 ") .
  246. " div setlinewidth \n" .
  247. " lineto pop stroke} def\n";
  248. } else {
  249. print "/run { set-bg newpath 50 sub y-scale mul 50 add moveto width " .
  250. "setlinewidth 50 sub y-scale mul 50 add lineto stroke} def\n";
  251. print "/suspend { set-bg newpath 50 sub y-scale mul 50 add moveto width " .
  252. "2 div setlinewidth 50 sub y-scale mul 50 add lineto stroke} def\n";
  253. print "/fetch { set-bg newpath 50 sub y-scale mul 50 add moveto width " .
  254. ( $opt_m ? " 4 " : " 2 ") .
  255. "div setlinewidth 50 sub y-scale mul 50 add lineto stroke} def\n";
  256. #print ("/run { newpath moveto 1.5 setlinewidth lineto stroke} def\n");
  257. #print ("/suspend { newpath moveto 0.5 setlinewidth lineto stroke} def\n");
  258. }
  259. }
  260. print "/printText { 0 0 moveto (GrAnSim) show } def\n";
  261. print "/asciilogo { 5 sub moveto HB16 setfont (GrAnSim) show } def\n";
  262. if ( $opt_m ) {
  263. print "/logo { asciilogo } def\n";
  264. } else {
  265. print "/logo { gsave \n" .
  266. " translate \n" .
  267. " .95 -.05 0\n" .
  268. " { dup 1 exch sub 0 exch setrgbcolor printText 1 -.5 translate } for \n" .
  269. " 1 0 0 setrgbcolor printText\n" .
  270. " grestore} def\n";
  271. }
  272. print "% For debugging PS uncomment this line and add the file behandler.ps\n";
  273. print "% $brkpage begin printonly endprint \n";
  274. print("/HE10 /Helvetica findfont 10 scalefont def\n");
  275. print("/HE12 /Helvetica findfont 12 scalefont def\n");
  276. print("/HE14 /Helvetica findfont 14 scalefont def\n");
  277. print("/HB16 /Helvetica-Bold findfont 16 scalefont def\n");
  278. print "% " . "-" x 77 . "\n";
  279. print("newpath\n");
  280. print("-90 rotate\n");
  281. print("-785 30 translate\n");
  282. print("0 8.000000 moveto\n");
  283. print("0 525.000000 760.000000 525.000000 8.000000 arcto\n");
  284. print("4 {pop} repeat\n");
  285. print("760.000000 525.000000 760.000000 0 8.000000 arcto\n");
  286. print("4 {pop} repeat\n");
  287. print("760.000000 0 0 0 8.000000 arcto\n");
  288. print("4 {pop} repeat\n");
  289. print("0 0 0 525.000000 8.000000 arcto\n");
  290. print("4 {pop} repeat\n");
  291. print("0.500000 setlinewidth\n");
  292. print("stroke\n");
  293. print("newpath\n");
  294. print("4.000000 505.000000 moveto\n");
  295. print("4.000000 521.000000 752.000000 521.000000 4.000000 arcto\n");
  296. print("4 {pop} repeat\n");
  297. print("752.000000 521.000000 752.000000 501.000000 4.000000 arcto\n");
  298. print("4 {pop} repeat\n");
  299. print("752.000000 501.000000 4.000000 501.000000 4.000000 arcto\n");
  300. print("4 {pop} repeat\n");
  301. print("4.000000 501.000000 4.000000 521.000000 4.000000 arcto\n");
  302. print("4 {pop} repeat\n");
  303. print("0.500000 setlinewidth\n");
  304. print("stroke\n");
  305. print("HE14 setfont\n");
  306. print("100 505 moveto\n");
  307. print("($pname ) show\n");
  308. print("($date) dup stringwidth pop 750 exch sub 505.000000 moveto show\n");
  309. # print "/total-len $tmax def\n";
  310. print("-40 -40 translate\n");
  311. print "% " . "-" x 77 . "\n";
  312. print "% Print x-axis:\n";
  313. print "/y-val $ymin def % { y-offset 40 sub 2 div y-offset add } def\n";
  314. print "0.5 setlinewidth\n";
  315. print "x-offset y-val moveto total-len normalize x-offset sub 0 rlineto stroke\n";
  316. print "0 total-len 10 div total-len\n" .
  317. " { dup normalize dup y-val moveto 0 -2 rlineto stroke % tic\n" .
  318. " y-val 10 sub moveto HE10 setfont round prt-n % print label \n" .
  319. " } for \n";
  320. print "1 setlinewidth\n";
  321. print "% " . "-" x 77 . "\n";
  322. }
  323. # -----------------------------------------------------------------------------
  324. sub print_y_axis {
  325. local ($i);
  326. local ($y, $smax,$majormax, $majorint);
  327. # Y-axis label
  328. print "% " . ("-" x 75) . "\n";
  329. print "% Y-Axis:\n";
  330. print "% " . ("-" x 75) . "\n";
  331. if ( $opt_m ) {
  332. print "0 setgray\n";
  333. } else {
  334. print "0 0 0 setrgbcolor\n";
  335. }
  336. print("gsave\n");
  337. print("HE12 setfont\n");
  338. print("(tasks)\n");
  339. print("dup stringwidth pop\n");
  340. print("$ymax\n");
  341. print("exch sub\n");
  342. print("$labelx exch\n");
  343. print("translate\n");
  344. print("90 rotate\n");
  345. print("0 0 moveto\n");
  346. print("show\n");
  347. print("grestore\n");
  348. # Scale
  349. if ($pmax < $majorticks) {
  350. $majorticks = $pmax;
  351. }
  352. print "0.5 setlinewidth\n";
  353. print("HE12 setfont\n$scalex $ymin moveto\n$scalex $ymax lineto\n");
  354. print("% Total number of tasks: $pmax\n");
  355. print("% Number of ticks: $majorticks\n");
  356. $y = $ymax; # (($pmax - $ymin)/$majorticks) * ($majorticks-$i) + $ymin;
  357. print("$scalex $y moveto\n$major $y lineto\n");
  358. print("$markx $y moveto\n($pmax) show\n");
  359. $majormax = int($pmax/$majorticks)*$majorticks;
  360. $smax = $majormax*(($ymax-$ymin)/$pmax)+$ymin;
  361. $majorint = $majormax/$majorticks;
  362. for($i=0; $i <= $majorticks; ++$i) {
  363. $y = (($smax - $ymin)/$majorticks) * ($majorticks-$i) + $ymin;
  364. $majorval = int($majorint * ($majormax/$majorint-$i));
  365. print("$scalex $y moveto\n$major $y lineto\n");
  366. print("$markx $y moveto\n($majorval) show\n");
  367. }
  368. # print("$xmin $ymax moveto\n10 0 rlineto\n10 0 rmoveto\n($pmax) show\n");
  369. print " stroke\n";
  370. print "1 setlinewidth\n";
  371. print "% " . ("-" x 75) . "\n";
  372. }
  373. # ---------------------------------------------------------------------------
  374. sub print_verbose_message {
  375. print "Prg Name: $pname Date: $date\n";
  376. print "Input: stdin Output: stdout\n";
  377. }
  378. # ----------------------------------------------------------------------------
  379. sub process_options {
  380. if ( $opt_h ) {
  381. open(ME,$0) || die "Can't open myself ($0): $!\n";
  382. $n = 0;
  383. while (<ME>) {
  384. last if $_ =~ /^$/;
  385. print $_;
  386. $n++;
  387. }
  388. close(ME);
  389. exit ;
  390. }
  391. if ( $opt_s ) {
  392. $y_scale = $opt_s;
  393. } else {
  394. $y_scale = 1;
  395. }
  396. if ( $#ARGV != 3 ) {
  397. print "Usage: $0 [options] <max x value> <max y value> <prg name> <date> \n";
  398. print "Use -h option to get details\n";
  399. exit 1;
  400. }
  401. $tmax = $ARGV[0];
  402. $pmax = $ARGV[1];
  403. # GUM uses the absolute path (with '=' instead of '/') of the executed file
  404. # (for PVM reasons); if you want to have the full path in the generated
  405. # graph, too, eliminate the substitution below
  406. ($pname = $ARGV[2]) =~ s/.*=//;
  407. $date = $ARGV[3];
  408. if ( $opt_w ) {
  409. $width = $opt_w;
  410. } else {
  411. $width = 0;
  412. }
  413. }
  414. # -----------------------------------------------------------------------------