-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdroid_badapt_stamp.rb
executable file
·106 lines (84 loc) · 2.21 KB
/
droid_badapt_stamp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env ruby
require 'terminal-table'
$BENCH = {
# NewPipe:"NewPipe",
# duckduckgo:"duckduckgo",
# SoundRecorder:"SoundRecorder",
MaterialLife:"MaterialLife",
}
$DIR = "badapt_run"
$RUNS = [
"run_sd_hc", #0
"run_sd_mc", #1
"run_sd_lc", #2
"run_md_hc", #3
"run_md_mc", #4
"run_md_lc", #5
"run_ld_hc", #6
"run_ld_mc", #7
"run_ld_lc", #8
]
# Input = Date(Day) Date(Time) Timestamp V1 V2 V3
# Output = Timestamp V1 V2 V3
def load_timestamp(fname)
stamps = []
File.open(fname).read().each_line do |line|
parsed = line.strip().split()
stamps << [parsed[2].to_f, parsed[3].to_f, parsed[4].to_f, parsed[5].to_f]
end
return stamps
end
def within(stamp1,stamp2,compare)
return (stamp1 <= compare && compare <= stamp2)
end
def get_energy(stamps, tmin, tmax)
i = 0
while i < stamps.length && !within(stamps[i][0],stamps[i+1][0],tmin)
i += 1
end
if i >= stamps.length then
puts "ERROR: Couldn't find timestamp"
exit
end
indexmin = i
while i < stamps.length && !within(stamps[i][0],stamps[i+1][0],tmax)
i += 1
end
if i >= stamps.length then
puts "ERROR: Couldn't find timestamp"
exit
end
indexmax = i
energy = 0.0
for j in indexmin..indexmax do
energy += stamps[j][2]
end
return energy
end
# Main
if ARGV.length < 1
puts "pi_badapt_stamp.rb [TIMESTAMP FILE]"
exit
end
timestamp_file = ARGV[0]
stamps = load_timestamp(timestamp_file)
# Build table for energy consumed for each run
$BENCH.each do |bench, path|
puts "Bench: #{bench}"
$RUNS.each do |run|
refstamps = File.open("./android_bench/#{path}/#{$DIR}/#{run}.stamp").read().scan(/ERun.*:(.*)$/)
energyfile = File.open("./android_bench/#{path}/#{$DIR}/#{run}.txt", "w")
energyfile.write("// Created from #{timestamp_file}\n")
puts "#{bench} #{run}"
for i in 0..refstamps.length-1 do
parsed = refstamps[i][0].strip().split()
#e += m[i][0].strip().split()[2].to_f
tmin = parsed[0].to_f
tmax = parsed[1].to_f
energy = get_energy(stamps, tmin, tmax)
puts "Tmin:#{tmin} Tmax:#{tmax} Diff:#{tmax-tmin} Energy:#{energy}"
energyfile.write("ERun: #{i}: 0 0 #{energy} 0\n")
end
energyfile.close
end
end