[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / utils / parallel / gr2RTS.pl
1 #!/usr/local/bin/perl
2 #                                           (C) Hans Wolfgang Loidl, July 1995
3 ##############################################################################
4 # Time-stamp: <Thu Oct 26 1995 18:40:10 Stardate: [-31]6498.68 hwloidl>
5 #
6 # Usage: gr2RTS [options] <sim-file>
7 #
8 # Options:
9 #  -o <file> ... write output to <file>
10 #  -h        ... help; print this text.
11 #  -v        ... verbose mode.
12 #
13 ##############################################################################
14
15 # ----------------------------------------------------------------------------
16 # Command line processing and initialization
17 # ----------------------------------------------------------------------------
18
19 require "getopts.pl";
20
21 &Getopts('hvo:');  
22
23 do process_options();
24
25 if ( $opt_v ) {
26     do print_verbose_message ();
27 }
28
29 # ----------------------------------------------------------------------------
30 # The real thing
31 # ----------------------------------------------------------------------------
32
33 open(INPUT,"<$input") || die "Couldn't open input file $input";
34 open(OUTPUT,"| sort -n > $output") || die "Couldn't open output file $output";
35
36 #do skip_header();
37
38 $tot_total_rt = 0;
39 $tot_rt = 0;
40
41 $line_no = 0;
42 while (<INPUT>) {
43     next                     if /^--/;     # Comment lines start with --
44     next                     if /^\s*$/;   # Skip empty lines
45     $line_no++;
46     @fields = split(/[:,]/,$_);
47     $has_end = 0;
48
49     foreach $elem (@fields) {
50       foo : {
51         $pe = $1, $end = $2 , last foo   if $elem =~ /^\s*PE\s+(\d+)\s+\[(\d+)\].*$/;
52         $tn = $1, $has_end = 1  , last foo   if $elem =~ /^\s*END\s+(\w+).*$/;
53         # $tn = $1      , last foo   if $elem =~ /^\s*TN\s+(\w+).*$/;
54         $sn = $1        , last foo   if $elem =~ /^\s*SN\s+(\d+).*$/;
55         $start = $1     , last foo   if $elem =~ /^\s*ST\s+(\d+).*$/;
56         $is_global = $1 , last foo   if $elem =~ /^\s*EXP\s+(T|F).*$/;
57         $bbs = $1       , last foo   if $elem =~ /^\s*BB\s+(\d+).*$/;
58         $ha = $1        , last foo   if $elem =~ /^\s*HA\s+(\d+).*$/;
59         $rt = $1        , last foo   if $elem =~ /^\s*RT\s+(\d+).*$/;
60         $bt = $1, $bc = $2 , last foo if $elem =~ /^\s*BT\s+(\d+)\s+\((\d+)\).*$/;
61         $ft = $1, $fc = $2 , last foo if $elem =~ /^\s*FT\s+(\d+)\s+\((\d+)\).*$/;
62         $lsp = $1        , last foo   if $elem =~ /^\s*LS\s+(\d+).*$/;
63         $gsp = $1        , last foo   if $elem =~ /^\s*GS\s+(\d+).*$/;
64         $my = $1        , last foo   if $elem =~ /^\s*MY\s+(T|F).*$/;
65       }
66     }
67
68     next unless $has_end == 1;
69
70     $total_rt = $end - $start;
71     $tot_total_rt += $total_rt;
72     $tot_rt += $rt;
73
74     print OUTPUT "$rt\n";
75     $sum_rt += $rt;
76     $max_rt = $rt  if $rt > $max_rt;
77 }
78
79 close INPUT;
80 close OUTPUT;
81
82 # Hack to  fake a filter
83 if ( $output eq $filter_output ) {
84     system "cat $output";
85     system "rm $output";
86 }
87
88 exit 0;
89
90 # ---------------------------------------------------------------------------
91
92 sub process_options {
93     if ( $opt_h ) {                      
94         open(ME,$0) || die "Can't open myself ($0)";
95         $n = 0;
96         while (<ME>) {
97             last if $_ =~ /^$/;
98             print $_;
99             $n++;
100         }
101         close(ME);
102         
103         # system "cat $0 | awk 'BEGIN { n = 0; } \
104         #                             /^$/ { print n; \
105         #                                    exit; } \
106         #                                  { n++; }'"
107         exit ;
108     }
109
110     $input = $#ARGV == -1 ? "-" : $ARGV[0] ;
111     
112     if ( $#ARGV != 0 ) {
113         #print "Usage: gran-extr [options] <sim-file>\n";
114         #print "Use -h option to get details\n";
115         #exit 1;
116         
117     }
118
119     $filter_output = $ENV{'TMPDIR'} . "./,gr2RTS-out";
120     if ( $opt_o ) {
121         $output = $opt_o;
122     } else {
123         if ( $input eq "-" ) {
124             $output = $filter_output;
125         } else {
126             $output = $input; # "RTS";
127             $output =~ s/\.gr$/.rts/g;
128         }                       # 
129     }
130 }
131
132 # ----------------------------------------------------------------------------
133
134 sub print_verbose_message {
135     print "Input file: $input\t Output file: $output\n";
136 }
137
138 # ----------------------------------------------------------------------------