2 ##############################################################################
4 # Usage: gr2java [options]
6 # Filter that transforms a GrAnSim profile (a .gr file) at stdin to
7 # a quasi-parallel profile (a .qp file). It is the common front-end for most
8 # visualization tools (except gr2pe). It collects running,
9 # runnable and blocked tasks in queues of different `colours', whose meaning
11 # G ... green; queue of all running tasks
12 # A ... amber; queue of all runnable tasks
13 # R ... red; queue of all blocked tasks
14 # Y ... cyan; queue of fetching tasks
15 # C ... crimson; queue of tasks that are being stolen
16 # B ... blue; queue of all sparks
19 # -i <int> ... info level from 1 to 7; number of queues to count (see qp3ps)
20 # -I <str> ... count tasks that are in one of the given queues; encoding:
21 # 'a' ... active (running)
27 # (e.g. -I "arb" counts sum of active, runnable, blocked tasks)
28 # -c ... check consistency of data (e.g. no neg. number of tasks)
29 # -v ... be talkative.
30 # -h ... print help message (this header).
32 ##############################################################################
36 &Getopts('hvDSci:I:');
41 do print_verbose_message();
44 # ---------------------------------------------------------------------------
46 # ---------------------------------------------------------------------------
60 $improved_sort_option = $opt_S ? "-S" : "";
62 open (FOOL,"| ghc-fool-sort $improved_sort_option | sort -n +0 -1 | ghc-unfool-sort") || die "FOOL";
66 if ( $in_header == 9 ) {
84 ($PE, $pe, $time, $act, $tid, $rest) = split;
85 $time =~ s/[\[\]:]//g;
86 # next if $act eq 'REPLY';
87 chop($tid) if $act eq 'END';
90 if ($act eq 'START') {
94 if ( $n > $pmax ) { $pmax = $n; }
96 } elsif ($act eq 'START(Q)') {
100 if ( $n > $pmax ) { $pmax = $n; }
102 } elsif ($act eq 'STEALING') {
104 } elsif ($act eq 'STOLEN') {
106 } elsif ($act eq 'STOLEN(Q)') {
108 } elsif ($act eq 'FETCH') {
110 } elsif ($act eq 'REPLY') {
112 } elsif ($act eq 'BLOCK') {
114 } elsif ($act eq 'RESUME') {
117 } elsif ($act eq 'RESUME(Q)') {
120 } elsif ($act eq 'END') {
123 if ( $opt_c && $n < 0 ) {
124 print STDERR "Error at time $time: neg. number of tasks: $n\n";
126 } elsif ($act eq 'SCHEDULE') {
128 } elsif ($act eq 'DESCHEDULE') {
130 # The following are only needed for spark profiling
131 } elsif (($act eq 'SPARK') || ($act eq 'SPARKAT')) {
134 } elsif ($act eq 'USED') {
137 } elsif ($act eq 'PRUNED') {
140 } elsif ($act eq 'EXPORTED') {
143 } elsif ($act eq 'ACQUIRED') {
147 print STDERR "Error at time $time: unknown event $act\n";
152 print STDERRR "Error at time $time: process $tid has no from queue\n";
155 print FOOL $time, " ", $pe, " ",
160 # Compare with main loop in qp3ps
162 } elsif ($from eq 'G') {
164 } elsif ($from eq 'A') {
166 } elsif ($from eq 'R') {
168 } elsif ($from eq 'B') {
170 } elsif ($from eq 'C') {
172 } elsif ($from eq 'Y') {
175 print STDERR "Illegal from char: $from at $time\n";
179 } elsif ($to eq 'G') {
181 } elsif ($to eq 'A') {
183 } elsif ($to eq 'R') {
185 } elsif ($to eq 'B') {
187 } elsif ($to eq 'C') {
189 } elsif ($to eq 'Y') {
192 print STDERR "Illegal to char: $to at $time\n";
198 if ( $curr > $max ) {
203 print STDERR "%% $time: (act,runnable,blocked,fetch,mig,sp) = " .
204 "($active, $runnable, $blocked, $fetching, $migrating, $sparks)".
208 #print STDERR "Sparks @ $time: $sparks \tCurr: $curr \tMax: $max \n" if $opt_D;
210 if ( $time > $tmax ) {
213 delete $queue{$tid} if $to eq '*';
217 print "Time: ", $tmax, " Max_selected_tasks: ", $max,
218 " Max_running_tasks: ", $pmax, " Total_tasks: ", $ptotal, "\n";
224 # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
225 # Copied from qp3ps and slightly modified (we don't keep a list for each queue
226 # but just compute the max value we get out of all calls to count during the
227 # execution of the script).
228 # -----------------------------------------------------------------------------
230 # -----------------------------------------------------------------------------
235 return index($show,$queue)+1;
238 # -----------------------------------------------------------------------------
243 $res = (($queue_on_a) ? $active : 0) +
244 (($queue_on_r) ? $runnable : 0) +
245 (($queue_on_b) ? $blocked : 0) +
246 (($queue_on_f) ? $fetching : 0) +
247 (($queue_on_m) ? $migrating : 0) +
248 (($queue_on_s) ? $sparks : 0);
253 # -----------------------------------------------------------------------------
255 # -----------------------------------------------------------------------------
259 $active,$runnable,$blocked,$fetching,$sparks,$migrating) = @_;
261 $G[$samples] = queue_on_a ? $active : 0;
262 $A[$samples] = queue_on_r ? $runnable : 0;
263 $R[$samples] = queue_on_b ? $blocked : 0;
264 $Y[$samples] = queue_on_f ? $fetching : 0;
265 $B[$samples] = queue_on_s ? $sparks : 0;
266 $C[$samples] = queue_on_m ? $migrating : 0;
269 # -----------------------------------------------------------------------------
271 sub process_options {
273 open(ME,$0) || die "Can't open myself ($0): $!\n";
287 $show = "a" if info_level == 1;
288 $show = "ar" if info_level == 2;
289 $show = "arb" if info_level == 3;
290 $show = "arfb" if info_level == 4;
291 $show = "armfb" if info_level == 5;
292 $show = "armfbs" if info_level == 6;
303 $queue_on_a = &queue_on("a");
304 $queue_on_r = &queue_on("r");
305 $queue_on_b = &queue_on("b");
306 $queue_on_f = &queue_on("f");
307 $queue_on_s = &queue_on("s");
308 $queue_on_m = &queue_on("m");
311 sub print_verbose_message {
313 print STDERR "Info-str: $show\n";
314 print STDERR "The following queues are turned on: " .
315 ( $queue_on_a ? "active, " : "") .
316 ( $queue_on_r ? "runnable, " : "") .
317 ( $queue_on_b ? "blocked, " : "") .
318 ( $queue_on_f ? "fetching, " : "") .
319 ( $queue_on_m ? "migrating, " : "") .
320 ( $queue_on_s ? "sparks" : "") .