Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/scripts/hsconvert-data.pl
612 views
1
#!/usr/bin/perl
2
3
# program to migrate power and temperature trace data for a
4
# floorplan converted by hsconvert-flp.pl
5
6
# use warnings;
7
8
sub usage {
9
print("usage: hsconvert-data.pl -o <original flp> -c <converted flp> -p <power file> (or)\n");
10
print(" hsconvert-data.pl -o <original flp> -c <converted flp> -t <temp file>\n");
11
print("migrates power/temperature trace data for a floorplan converted by hsconvert-flp.pl\n");
12
print("prints output to stdout\n");
13
print("-o <original flp> -- floorplan file used as input to hsconvert-flp.pl (eg: ev6.flp.orig)\n");
14
print("-c <converted flp> -- floorplan file containing the output of hsconvert-flp.pl (eg: ev6.flp)\n");
15
print("-p <power file> -- input power trace file corresponding to <original flp> (eg: gcc.ptrace.orig)\n");
16
print("-t <temp file> -- input temperature trace file corresponding to <original flp>\n");
17
exit(1);
18
}
19
20
sub readnames {
21
my $file = shift;
22
my @strs;
23
my @names;
24
my $tail = 0;
25
26
open(FILE, "<$file") || die("error: file $file could not be opened for reading\n");
27
while (<FILE>) {
28
# skip comments and empty lines
29
next if (/^\s*#|^\s*$/);
30
chomp;
31
@strs = split(/\s+/);
32
die ("error: wrong floorplan input format\n") if (@strs != 3 && @strs != 5);
33
# skip connectivity information
34
next if (@strs == 3);
35
$names[$tail++] = $strs[0];
36
}
37
close(FILE);
38
return @names;
39
}
40
41
# the no. of sub-blocks into which each block (that has been chopped) has been chopped
42
sub getchopcount {
43
my $ofile = shift;
44
my $cfile = shift;
45
# original names
46
my @onames = readnames($ofile);
47
# converted names
48
my @cnames = readnames($cfile);
49
my %chopcount;
50
my $i;
51
my $j;
52
53
for($i=0; $i < @onames; $i++) {
54
for($j=0; $j < @cnames; $j++) {
55
if($cnames[$j] =~ /^$onames[$i]_\d+$/) {
56
if ($chopcount{$onames[$i]}) {
57
$chopcount{$onames[$i]} += 1;
58
} else {
59
$chopcount{$onames[$i]} = 1;
60
}
61
}
62
}
63
}
64
65
return %chopcount;
66
}
67
68
# main computation
69
usage() if (@ARGV != 6 || $ARGV[0] ne "-o" || ! -f $ARGV[1] ||
70
$ARGV[2] ne "-c" || ! -f $ARGV[3] ||
71
$ARGV[4] ne "-p" && $ARGV[4] ne "-t" || ! -f $ARGV[5]);
72
73
%chopcount = getchopcount($ARGV[1], $ARGV[3]);
74
75
open (FILE, "<$ARGV[5]") || die("error: file $ARGV[5] could not be opened for reading\n");
76
77
# find the first non-empty line
78
while (<FILE>) {
79
if (!/^\s*$/) {
80
last;
81
}
82
}
83
chomp;
84
@names = split(/\s+/);
85
die("error: empty trace file\n") if (!@names);
86
87
# the first line
88
for($i = 0; $i < @names-1; $i++) {
89
if ($count = $chopcount{$names[$i]}) {
90
for($j = 0; $j < $count; $j++) {
91
print $names[$i]."_".$j."\t";
92
}
93
} else {
94
print $names[$i]."\t";
95
}
96
}
97
if ($count = $chopcount{$names[$i]}) {
98
for($j = 0; $j < $count-1; $j++) {
99
print $names[$i]."_".$j."\t";
100
}
101
print $names[$i]."_".$j."\n";
102
} else {
103
print $names[$i]."\n";
104
}
105
106
# remaining lines
107
while(<FILE>) {
108
# skip comments and empty lines
109
next if (/^\s*#|^\s*$/);
110
chomp;
111
@vals = split(/\s+/);
112
113
for($i = 0; $i < @vals-1; $i++) {
114
if ($count = $chopcount{$names[$i]}) {
115
# power values - divide proportionately
116
if ($ARGV[4] eq "-p") {
117
$vals[$i] /= $count;
118
}
119
for($j = 0; $j < $count; $j++) {
120
print $vals[$i]."\t";
121
}
122
} else {
123
print $vals[$i]."\t";
124
}
125
}
126
if ($count = $chopcount{$names[$i]}) {
127
if ($ARGV[4] eq "-p") {
128
$vals[$i] /= $count;
129
}
130
for($j = 0; $j < $count-1; $j++) {
131
print $vals[$i]."\t";
132
}
133
print $vals[$i]."\n";
134
} else {
135
print $vals[$i]."\n";
136
}
137
}
138
close(FILE);
139
140
141