2
##############################################################################
3
# Time-stamp: <Mon May 20 1996 17:22:45 Stardate: [-31]7533.41 hwloidl>
5
# Usage: RTS2gran <RTS-file>
8
# -t <file> ... use <file> as template file (<,> global <.> local template)
9
# -p <file> ... use <file> as gnuplot .gp file (default: gran.gp)
10
# -x <x-size> ... of gnuplot graph
11
# -y <y-size> ... of gnuplot graph
12
# -n <n> ... use <n> as number of PEs in title
13
# -h ... help; print this text.
14
# -v ... verbose mode.
16
##############################################################################
18
# ----------------------------------------------------------------------------
19
# Command line processing and initialization
20
# ----------------------------------------------------------------------------
22
$gran_dir = $ENV{'GRANDIR'};
23
if ( $gran_dir eq "" ) {
24
print STDERR "RTS2gran: Warning: Env variable GRANDIR is undefined\n";
27
push(@INC, $gran_dir, $gran_dir . "/bin");
28
# print STDERR "INC: " . join(':',@INC) . "\n";
31
require "template.pl"; # contains read_template for parsing template file
32
require "stats.pl"; # statistics package with corr and friends
34
&Getopts('hvt:p:x:y:n:Y:Z:');
42
do print_verbose_message ();
45
# ----------------------------------------------------------------------------
47
# ----------------------------------------------------------------------------
49
$max_y = &pre_process($input);
51
open(INPUT,"<$input") || die "Couldn't open input file $input";
52
open(OUT_CUMU,">$cumulat_rts_file_name") || die "Couldn't open output file $cumulat_rts_file_name";
53
open(OUT_CUMU0,">$cumulat0_rts_file_name") || die "Couldn't open output file $cumulat0_rts_file_name";
62
$last_y = ($logscale{"'g'"} ne "") ? 1 : 0;
67
next if /^--/; # Comment lines start with --
68
next if /^\s*$/; # Skip empty lines
73
print STDERR "Error @ line $line_no: RTS file not sorted!\n";
79
$index = do get_index_open_int($rt,@exec_times);
80
$exec_class[$index]++;
82
if ( $last_rt != $rt ) {
83
print OUT_CUMU "$rt \t" . int($last_y/$max_y) . "\n";
84
print OUT_CUMU0 "$rt \t$last_y\n";
85
print OUT_CUMU "$rt \t" . int($count/$max_y) . "\n";
86
print OUT_CUMU0 "$rt \t$count\n";
93
print OUT_CUMU "$rt \t" . int($last_y/$max_y) . "\n";
94
print OUT_CUMU0 "$rt \t$last_y\n";
95
print OUT_CUMU "$rt \t" . int($count/$max_y) . "\n";
96
print OUT_CUMU0 "$rt \t$count\n";
101
$tot_tasks = $count; # this is y-max in cumulat graph
102
$max_rt = $rt; # this is x-max in cumulat graph
104
$max_rt_class = &list_max(@exec_class);
106
do write_data($gran_file_name, $OPEN_INT, $logscale{"'g'"}, $#exec_times+1,
107
@exec_times, @exec_class);
109
# ----------------------------------------------------------------------------
110
# Run GNUPLOT over the data files and create figures
111
# ----------------------------------------------------------------------------
113
do gnu_plotify($gp_file_name);
115
# ----------------------------------------------------------------------------
117
if ( $max_y != $tot_tasks ) {
119
die "ERROR: pre-processed number of tasks ($max_y) does not match computed one ($tot_tasks)\n";
121
print STDERR "Warning: pre-processed number of tasks ($max_y) does not match computed one ($tot_tasks)\n" if $opt_v;
127
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128
# ToDo: Put these routines into an own package
129
# ----------------------------------------------------------------------------
130
# Basic Operations on the intervals
131
# ----------------------------------------------------------------------------
133
sub get_index_open_int {
134
local ($value,@list) = @_;
135
local ($index,$right);
137
# print "get_index: searching for index of" . $value;
138
# print " in " . join(':',@list);
141
$right = $list[$index];
142
while ( ($value >= $right) && ($index < $#list) ) {
144
$right = $list[$index];
147
return ( ($index == $#list) && ($value > $right) ) ? $index+1 : $index;
150
# ----------------------------------------------------------------------------
152
sub get_index_closed_int {
153
local ($value,@list) = @_;
154
local ($index,$right);
156
if ( ($value < $list[0]) || ($value > $list[$#list]) ) {
161
$left = $list[$index];
162
while ( ($left <= $value) && ($index < $#list) ) {
164
$left = $list[$index];
169
# ----------------------------------------------------------------------------
171
# ----------------------------------------------------------------------------
174
local ($file_name, $open_int, $logaxes, $n, @rest) = @_;
175
local (@times) = splice(@rest,0,$n);
176
local (@class) = @rest;
178
open(GRAN,">$file_name") || die "Couldn't open file $file_name for output";
180
if ( $open_int == $OPEN_INT ) {
183
$left = ( index($logaxes,"x") != -1 ? int($times[0]/2) : 0 ),
186
$i++, $left = $right) {
188
print GRAN int(($left+$right)/2) . " " .
189
($class[$i] eq "" ? "0" : $class[$i]) . "\n";
191
print GRAN $times[$n-1]+(($times[$n-1]-$times[$n-2])/2) . " " .
192
($class[$n] eq "" ? "0" : $class[$n]) . "\n";
196
print GRAN ( (index($logaxes,"x") != -1) && ($times[0] == 0 ? int($times[1]/2) : ($times[$1] + $times[0])/2 ) . " " . $class[0] . "\n");
197
for ($i=1; $i < $n-2; $i++) {
199
$right = $times[$i+1];
200
print(GRAN ($left+$right)/2 . " " .
201
($class[$i] eq "" ? "0" : $class[$i]) . "\n");
203
print GRAN ($times[$n-1]+$times[$n-2])/2 . " " . $class[$n-2] if $n >= 2;
209
# ----------------------------------------------------------------------------
212
local ($file_name,$n,@list) = @_;
214
open(FILE,">$file_name") || die "$file_name: $!";
215
for ($i=0; $i<=$#list; $i++) {
216
print FILE $i . " " . ( $list[$i] eq "" ? "0" : $list[$i] ) . "\n";
220
print "write_array: (" . join(", ",1 .. $#list) . ")\n for file $file_name returns: \n (0, $#list, &list_max(@list)\n";
223
return ( (0, $#list, &list_max(@list),
224
"(" . join(", ",1 .. $#list) . ")\n") );
227
# ----------------------------------------------------------------------------
230
local ($gp_file_name) = @_;
232
@open_xrange = &range($OPEN_INT,$logscale{"'g'"},@exec_times);
234
$exec_xtics = $opt_T ? &get_xtics($OPEN_INT,@exec_times) : "" ;
236
open(GP_FILE,">$gp_file_name") ||
237
die "Couldn't open gnuplot file $gp_file_name for output\n";
239
print GP_FILE "set term postscript \"Roman\" 20\n";
240
do write_gp_record(GP_FILE,
241
$gran_file_name, &dat2ps_name($gran_file_name),
242
"Granularity (pure exec. time)", "Number of threads",
244
@open_xrange,$max_rt_class,$exec_xtics);
246
do write_gp_lines_record(GP_FILE,
247
$cumulat_rts_file_name, &dat2ps_name($cumulat_rts_file_name),
248
"Cumulative pure exec. times","% of threads",
251
# $xtics_cluster_rts as last arg?
253
do write_gp_lines_record(GP_FILE,
254
$cumulat0_rts_file_name, &dat2ps_name($cumulat0_rts_file_name),
255
"Cumulative pure exec. times","Number of threads",
257
$max_rt, $tot_tasks, "");
258
# $xtics_cluster_rts as last arg?
262
print "Gnu plotting figures ...\n";
263
system "gnuplot $gp_file_name";
265
print "Extending thickness of impulses ...\n";
266
do gp_ext($gran_file_name);
269
# ----------------------------------------------------------------------------
272
local (@file_names) = @_;
274
local ($ps_file_name);
277
#$prg = system "which gp-ext-imp";
278
#print " Using script $prg for impuls extension\n";
279
$prg = $ENV{GRANDIR} ? $ENV{GRANDIR} . "/bin/gp-ext-imp"
280
: $ENV{HOME} . "/bin/gp-ext-imp" ;
282
print " (using script $prg)\n";
285
foreach $file_name (@file_names) {
286
$ps_file_name = &dat2ps_name($file_name);
287
system "$prg -w $ext_size -g $gray " .
288
$ps_file_name . " " .
289
$ps_file_name . "2" ;
290
system "mv " . $ps_file_name . "2 " . $ps_file_name;
294
# ----------------------------------------------------------------------------
296
sub write_gp_record {
297
local ($file,$in_file,$out_file,$xlabel,$ylabel,$logaxes,
298
$xstart,$xend,$ymax,$xtics) = @_;
300
if ( $xstart >= $xend ) {
301
print ("WARNING: empty xrange [$xstart:$xend] changed to [$xstart:" . $xstart+1 . "]\n") if ( $pedantic || $opt_v );
307
print "WARNING: empty yrange changed to [0:$ymax]\n" if ( $pedantic || $opt_v );
310
$str = "set size " . $xsize . "," . $ysize . "\n" .
311
"set xlabel \"" . $xlabel . "\"\n" .
312
"set ylabel \"" . $ylabel . "\"\n" .
314
: "set xrange [" . int($xstart) .":" . int($xend) . "]\n") .
316
("set yrange [" . (index($logaxes,"y") != -1 ? 1 : 0) . ":$opt_Y]\n") :
318
: "set yrange [" . (index($logaxes,"y") != -1 ? 1 : 0) .
319
":" . &list_max(2,int($ymax+$ymax/5)) . "]\n")) .
320
($xtics ne "" ? "set xtics $xtics" : "") .
323
( $nPEs!=0 ? "set title \"$nPEs PEs\"\n" : "" ) .
326
"set format xy \"%8.8g\"\n" .
327
(index($logaxes,"x") != -1 ?
329
"set nologscale x\n") .
330
(index($logaxes,"y") != -1 ?
332
"set nologscale y\n") .
333
"set output \"" . $out_file . "\"\n" .
334
"plot \"" . $in_file . "\" with impulses\n\n";
338
# ----------------------------------------------------------------------------
340
sub write_gp_lines_record {
341
local ($file,$in_file,$out_file,$xlabel,$ylabel,$logaxes,
342
$xend,$yend,$xtics) = @_;
346
$str = "set xlabel \"" . $xlabel . "\"\n" .
347
"set ylabel \"" . $ylabel . "\"\n" .
348
"set xrange [" . ( index($logaxes,"x") != -1 ? 1 : 0 ) . ":$xend]\n" .
349
"set yrange [" . ( index($logaxes,"y") != -1 ? 1 : 0 ) .
350
($yend!=100 && $opt_Z ? ":$opt_Z]\n" : ":$yend]\n") .
353
( $xtics ne "" ? "set xtics $xtics" : "" ) .
354
(index($logaxes,"x") != -1 ?
356
"set nologscale x\n") .
357
(index($logaxes,"y") != -1 ?
359
"set nologscale y\n") .
361
"set format xy \"%8.8g\"\n" .
362
"set output \"" . $out_file . "\"\n" .
363
"plot \"" . $in_file . "\" with lines\n\n";
368
# ----------------------------------------------------------------------------
370
sub write_gp_simple_record {
371
local ($file,$in_file,$out_file,$xlabel,$ylabel,$logaxes,
372
$xstart,$xend,$ymax,$xtics) = @_;
374
$str = "set size " . $xsize . "," . $ysize . "\n" .
375
"set xlabel \"" . $xlabel . "\"\n" .
376
"set ylabel \"" . $ylabel . "\"\n" .
378
: "set xrange [" . int($xstart) .":" . int($xend) . "]\n") .
380
: "set yrange [" . (index($logaxes,"y") != -1 ? 1 : 0) .
381
":" . &list_max(2,int($ymax+$ymax/5)) . "]\n") .
382
($xtics ne "" ? "set xtics $xtics" : "") .
387
"set format xy \"%8.8g\"\n" .
388
(index($logaxes,"x") != -1 ?
390
"set nologscale x\n") .
391
(index($logaxes,"y") != -1 ?
393
"set nologscale y\n") .
394
"set output \"" . $out_file . "\"\n" .
395
"plot \"" . $in_file . "\" with impulses\n\n";
399
# ----------------------------------------------------------------------------
402
local ($open_int, $logaxes, @ints) = @_;
404
local ($range, $left_margin, $right_margin);
406
$range = $ints[$#ints]-$ints[0];
407
$left_margin = 0; # $range/10;
408
$right_margin = 0; # $range/10;
411
print "\n==> Range: logaxes are $logaxes i.e. " .
412
(index($logaxes,"x") != -1 ? "matches x axis\n"
413
: "DOESN'T match x axis\n");
415
if ( index($logaxes,"x") != -1 ) {
416
if ( $open_int == $OPEN_INT ) {
417
return ( ($ints[0]/2-$left_margin,
418
$ints[$#ints]+($ints[$#ints]-$ints[$#ints-1])/2+$right_margin) );
420
return ( ( &list_max(1,$ints[0]-$left_margin),
421
$ints[$#ints]+($ints[$#ints]-$ints[$#ints-1])/2+$right_margin) );
424
if ( $open_int == $OPEN_INT ) {
425
return ( ($ints[0]/2-$left_margin,
426
$ints[$#ints]+($ints[$#ints]-$ints[$#ints-1])/2+$right_margin) );
428
return ( ($ints[0]-$left_margin,
429
$ints[$#ints]+($ints[$#ints]-$ints[$#ints-1])/2+$right_margin) );
434
# ----------------------------------------------------------------------------
436
# ----------------------------------------------------------------------------
438
sub process_options {
440
open(ME,$0) || die "Can't open myself ($0)";
449
# system "cat $0 | awk 'BEGIN { n = 0; } \
456
$input = $#ARGV == -1 ? "-" : $ARGV[0] ;
459
#print "Usage: gran-extr [options] <sim-file>\n";
460
#print "Use -h option to get details\n";
466
$gp_file_name = "gran.gp";
467
$gran_file_name = "gran.dat";
468
$cumulat_rts_file_name = "cumu-rts.dat";
469
$cumulat0_rts_file_name = "cumu-rts0.dat";
474
$gp_file_name = $opt_p;
476
$gp_file_name = "gran.gp";
480
# $gp_file_name =~ s|\.|${opt_s}.|;
481
# $gran_file_name =~ s|\.|${opt_s}.|;
482
# $cumulat_rts_file_name =~ s|\.|${opt_s}.|;
483
# $cumulat0_rts_file_name =~ s|\.|${opt_s}.|;
499
do read_template($opt_t,$input);
504
# ----------------------------------------------------------------------------
506
sub print_verbose_message {
508
print "-" x 70 . "\n";
510
print "-" x 70 . "\n";
511
print "\nFilenames: \n";
512
print " Input file: $input\n";
513
print " Gran files: $gran_file_name $gran_global_file_name $gran_local_file_name\n";
514
print " Comm files: $comm_file_name $comm_global_file_name $comm_local_file_name\n";
515
print " Sparked threads file: $spark_file_name $spark_local_file_name $spark_global_file_name\n";
516
print " Heap file: $ha_file_name\n";
517
print " GNUPLOT file name: $gp_file_name Correlation file name: $corr_file_name\n";
518
print " Cumulative RT file name: $cumulat_rts_file_name ($cumulat0_rts_file_name) \n Cumulative HA file name: $cumulat_has_file_name\n";
519
print " Cluster RT file name: $clust_rts_file_name \n Cluster HA file name: $clust_has_file_name\n";
520
print " Cumulative runtimes file name: $cumulat_rts_file_name\n";
521
print " Cumulative heap allocations file name $cumulat_has_file_name\n";
522
print " Cluster run times file name: $clust_rts_file_name\n";
523
print " Cluster heap allocations file name: $clust_has_file_name\n";
524
print " PE load file name: $pe_file_name\n";
525
print " Site size file name: $sn_file_name\n";
526
print "\nBoundaries: \n";
527
print " Gran boundaries: (" . join(',',@exec_times) . ")\n";
528
print " Comm boundaries: (" . join(',',@comm_percs) . ")\n";
529
print " Sparked threads boundaries: (" . join(',',@sparks) . ")\n";
530
print " Heap boundaries: (" . join(',',@has) .")\n";
531
print "\nOther pars: \n";
532
print " Left margin: $left_margin Right margin: $right_margin\n";
533
print " GP-extension: $ext_size GP xsize: $xsize GP ysize: $ysize\n";
534
print " Gray scale: $gray Smart x-tics is " . ($opt_T ? "ON" : "OFF") .
535
" Percentage y-axis is " . ($opt_P ? "ON" : "OFF") . "\n";
536
print " Log. scaling assoc list: ";
537
while (($key,$value) = each %logscale) {
538
print "$key: $value, ";
541
print " Active template file: $templ_file\n" if $opt_t;
542
print "-" x 70 . "\n";
545
# ----------------------------------------------------------------------------
550
open(PIPE,"wc -l $input |") || die "Couldn't open pipe";
556
die "Error in pre-processing: Last line of $file does not match RTS!\n";
564
# ----------------------------------------------------------------------------
567
# ----------------------------------------------------------------------------
569
# Old version (eventually delete it)
570
# New version is in template.pl
572
# sub read_template {
576
# print "Reading template file $templ_file_name ...\n";
579
# ($f = ($input eq "-" ? "stdin" : $input)) =~ s/.rts//;
581
# open(TEMPLATE,"cat $templ_file_name | sed -e 's/\$0/$f/' |")
582
# || die "Couldn't open file $templ_file_name";
584
# while (<TEMPLATE>) {
585
# next if /^\s*$/ || /^--/;
586
# if (/^\s*G[:,;.\s]+([^\n]+)$/) {
588
# $list_str =~ s/[\(\)\[\]]//g;
589
# @exec_times = split(/[,;. ]+/, $list_str);
590
# } elsif (/^\s*F[:,;.\s]+([^\n]+)$/) {
592
# $list_str =~ s/[\(\)\[\]]//g;
593
# @fetch_times = split(/[,;. ]+/, $list_str);
594
# } elsif (/^\s*A[:,;.\s]+([^\n]+)$/) {
596
# $list_str =~ s/[\(\)\[\]]//g;
597
# @has = split(/[,;. ]+/, $list_str);
598
# } elsif (/^\s*C[:,;.\s]+([^\n]+)$/) {
600
# $list_str =~ s/[\(\)\[\]]//g;
601
# @comm_percs = split(/[,;. ]+/, $list_str);
602
# } elsif (/^\s*S[:,;.\s]+([^\n]+)$/) {
604
# $list_str =~ s/[\(\)\[\]]//g;
605
# @sparks = split(/[,;. ]+/, $list_str);
606
# } elsif (/^\s*g[:,;.\s]+([\S]+)$/) {
607
# ($gran_file_name,$gran_global_file_name, $gran_local_file_name) =
608
# &mk_global_local_names($1);
609
# } elsif (/^\s*f[:,;.\s]+([\S]+)$/) {
610
# ($ft_file_name,$ft_global_file_name, $ft_local_file_name) =
611
# &mk_global_local_names($1);
612
# } elsif (/^\s*c[:,;.\s]+([\S]+)$/) {
613
# ($comm_file_name, $comm_global_file_name, $comm_local_file_name) =
614
# &mk_global_local_names($1);
615
# } elsif (/^\s*s[:,;.\s]+([\S]+)$/) {
616
# ($spark_file_name, $spark_global_file_name, $spark_local_file_name) =
617
# &mk_global_local_names($1);
618
# } elsif (/^\s*a[:,;.\s]+([\S]+)$/) {
619
# ($ha_file_name, $ha_global_file_name, $ha_local_file_name) =
620
# &mk_global_local_names($1);
621
# } elsif (/^\s*p[:,;.\s]+([\S]+)$/) {
622
# $gp_file_name = $1;
623
# $ps_file_name = &dat2ps_name($gp_file_name);
625
# } elsif (/^\s*Xcorr[:,;.\s]+([\S]+)$/) {
626
# $corr_file_name = $1;
627
# } elsif (/^\s*Xcumulat-rts[:,;.\s]+([\S]+)$/) {
628
# $cumulat_rts_file_name = $1;
629
# ($cumulat0_rts_file_name = $1) =~ s/\./0./;
630
# } elsif (/^\s*Xcumulat-has[:,;.\s]+([\S]+)$/) {
631
# $cumulat_has_file_name = $1;
632
# } elsif (/^\s*Xcumulat-fts[:,;.\s]+([\S]+)$/) {
633
# $cumulat_fts_file_name = $1;
634
# } elsif (/^\s*Xcumulat-cps[:,;.\s]+([\S]+)$/) {
635
# $cumulat_cps_file_name = $1;
636
# } elsif (/^\s*Xclust-rts[:,;.\s]+([\S]+)$/) {
637
# $clust_rts_file_name = $1;
638
# } elsif (/^\s*Xclust-has[:,;.\s]+([\S]+)$/) {
639
# $clust_has_file_name = $1;
640
# } elsif (/^\s*Xclust-fts[:,;.\s]+([\S]+)$/) {
641
# $clust_fts_file_name = $1;
642
# } elsif (/^\s*Xclust-cps[:,;.\s]+([\S]+)$/) {
643
# $clust_cps_file_name = $1;
644
# } elsif (/^\s*Xpe[:,;.\s]+([\S]+)$/) {
645
# $pe_file_name = $1;
646
# } elsif (/^\s*Xsn[:,;.\s]+([\S]+)$/) {
647
# $sn_file_name = $1;
649
# } elsif (/^\s*XRTS[:,;.\s]+([\S]+)$/) {
650
# $rts_file_name = $1;
651
# } elsif (/^\s*XHAS[:,;.\s]+([\S]+)$/) {
652
# $has_file_name = $1;
653
# } elsif (/^\s*XFTS[:,;.\s]+([\S]+)$/) {
654
# $fts_file_name = $1;
655
# } elsif (/^\s*XLSPS[:,;.\s]+([\S]+)$/) {
656
# $lsps_file_name = $1;
657
# } elsif (/^\s*XGSPS[:,;.\s]+([\S]+)$/) {
658
# $gsps_file_name = $1;
659
# } elsif (/^\s*XCPS[:,;.\s]+([\S]+)$/) {
660
# $cps_file_name = $1;
661
# } elsif (/^\s*XCCPS[:,;.\s]+([\S]+)$/) {
662
# $ccps_file_name = $1;
664
# } elsif (/^\s*\-[:,;.\s]+([\S]+)$/) {
666
# } elsif (/^\s*L[:,;\s]+(.*)$/) {
668
# %logscale = ('g',"xy",'a',"xy",'Cg',"xy",'Ca',"xy",'Yp',"y",'Ys',"y") , next if $str eq ".";
669
# $str =~ s/[\(\)\[\]]//g;
670
# %logscale = split(/[,;. ]+/, $str);
671
# } elsif (/^\s*i[:,;.\s]+([\S]+)$/) {
673
# } elsif (/^\s*k[:,;.\s]+([\S]+)$/) {
674
# $no_of_clusters = $1;
675
# } elsif (/^\s*e[:,;.\s]+([\S]+)$/) {
677
# } elsif (/^\s*v.*$/) {
679
# } elsif (/^\s*T.*$/) {