[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / utils / parallel / grs2gr.pl
1 #
2 # Convert several .gr files (from the same GUM run) into a single
3 # .gr file with all times adjusted relative to the earliest start
4 # time.
5 #
6
7 $count = 0;
8
9 foreach $i (@ARGV) {
10     open(GR, $i) || die "Can't read $i\n";
11     $cmd = <GR>;
12     $start = <GR>;
13     ($pe, $timestamp) = ($start =~ /PE\s+(\d+) \[(\d+)\]/);
14     die "PE $pe too high\n" if $pe > $#ARGV;
15     $proc[$count++] = $pe;
16     $prog[$pe] = $cmd;
17     $time[$pe] = $timestamp;
18     close(GR) || die "Can't close $i\n";
19 }
20
21 $basetime = 0;
22
23 for($i = 0; $i < $count; $i++) {
24     $pe = $proc[$i];
25     die "PE $pe missing?\n" if !defined($time[$pe]);
26     die "Mismatched .gr files\n" if $pe > 0 && $prog[$pe] ne $prog[$pe - 1];
27     $basetime = $time[$pe] if $basetime == 0 || $basetime > $time[$pe];
28 }
29
30 print $cmd;
31
32 for($i = 0; $i < $count; $i++) {
33     $pe = $proc[$i];
34     $delta = $time[$pe] - $basetime;
35     open(GR, $ARGV[$i]) || die "Can't read $ARGV[i]\n";
36     $cmd = <GR>;
37     $start = <GR>;
38     while(<GR>) {
39         /PE\s+(\d+) \[(\d+)\]/;
40         printf "PE %2u [%lu]%s", $1, $2 + $delta, $';
41     }
42     close(GR) || die "Can't close $ARGV[$i]\n";
43 }