manafa 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/batteryStats/BatteryStatsParser.py +17 -13
- Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa/emanafa.py +223 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/perfetto/perfettoParser.py +2 -2
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/services/batteryStatsService.py +5 -3
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/services/perfettoService.py +7 -7
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa}/tests/perfetto/test_perfettoService.py +4 -4
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/utils/Utils.py +1 -1
- Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa-0.2.2-py3.8.egg-info/PKG-INFO +103 -0
- {manafa-0.2.1/manafa.egg-info → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa-0.2.2-py3.8.egg-info}/SOURCES.txt +19 -6
- {manafa-0.2.1/manafa.egg-info → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa-0.2.2-py3.8.egg-info}/top_level.txt +0 -1
- manafa-0.2.1/PKG-INFO +0 -81
- manafa-0.2.1/README.md +0 -64
- manafa-0.2.1/manafa/emanafa.py +0 -175
- manafa-0.2.1/manafa.egg-info/PKG-INFO +0 -81
- manafa-0.2.1/setup.cfg +0 -4
- manafa-0.2.1/setup.py +0 -50
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/batteryStats/BatteryStatsConstants.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/batteryStats/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/perfetto/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/powerProfile/PowerProfile.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/powerProfile/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/services/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/services/service.py +0 -0
- {manafa-0.2.1/manafa/utils → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa/tests}/__init__.py +0 -0
- {manafa-0.2.1/tests → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa/tests/batterystats}/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa}/tests/batterystats/test_batteryStatsService.py +0 -0
- {manafa-0.2.1/tests/batterystats → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa/tests/perfetto}/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/utils/Logger.py +0 -0
- {manafa-0.2.1/tests/perfetto → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa/utils}/__init__.py +0 -0
- {manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/utils/dateUtils.py +0 -0
- {manafa-0.2.1/manafa.egg-info → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa-0.2.2-py3.8.egg-info}/dependency_links.txt +0 -0
- {manafa-0.2.1/manafa.egg-info → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa-0.2.2-py3.8.egg-info}/requires.txt +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import re,json
|
|
2
2
|
#sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
|
|
3
|
+
from collections import Iterable
|
|
4
|
+
|
|
3
5
|
from manafa.powerProfile.PowerProfile import PowerProfile
|
|
4
6
|
from manafa.utils.dateUtils import convertBatStatTimeToTimeStamp,batStatResetTimeToTimeStamp
|
|
5
7
|
import copy
|
|
@@ -19,9 +21,9 @@ def areInMinCPUFreq( cpu_freq , possible_cpu_states ):
|
|
|
19
21
|
possible_freqs = possible_cpu_states["core_speeds"] if "core_speeds" in possible_cpu_states else []
|
|
20
22
|
if len(possible_freqs)>0:
|
|
21
23
|
possible_freqs = sum(possible_freqs.values(),[])
|
|
22
|
-
|
|
24
|
+
|
|
23
25
|
#tem que ser os 2 tempos absolutos
|
|
24
|
-
print(possible_freqs)
|
|
26
|
+
#print(possible_freqs)
|
|
25
27
|
return False
|
|
26
28
|
|
|
27
29
|
def safe_division(a,b):
|
|
@@ -61,14 +63,17 @@ class BatteryEvent(object):
|
|
|
61
63
|
return state in self.concurrentUpdates
|
|
62
64
|
|
|
63
65
|
def getCurrentOfBatStatEvent(self):
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
currs = {}
|
|
67
|
+
total = 0
|
|
68
|
+
for v, x in self.currents.items():
|
|
66
69
|
try:
|
|
67
70
|
z = float(x)
|
|
68
|
-
|
|
71
|
+
currs[v] = z / 1000
|
|
72
|
+
total += z
|
|
69
73
|
except ValueError:
|
|
74
|
+
currs[v]=0
|
|
70
75
|
continue
|
|
71
|
-
return total
|
|
76
|
+
return total/1000, currs
|
|
72
77
|
|
|
73
78
|
def getVoltageValue(self):
|
|
74
79
|
return float(self.updates["volt"]) / 1000 if "volt" in self.updates else 0
|
|
@@ -236,7 +241,7 @@ class BatteryStatsParser(object):
|
|
|
236
241
|
current = 0.0
|
|
237
242
|
curravg=0
|
|
238
243
|
avg_ct=0
|
|
239
|
-
# screen
|
|
244
|
+
# screen
|
|
240
245
|
if comp_name == "screen" and "screen" in bt_event.updates:
|
|
241
246
|
on_current = possible_states["on"]
|
|
242
247
|
brightness_level = bt_event.updates["brightness"] if "brightness" in bt_event.updates else 1
|
|
@@ -270,13 +275,13 @@ class BatteryStatsParser(object):
|
|
|
270
275
|
current+=audio_curr
|
|
271
276
|
|
|
272
277
|
# audio
|
|
273
|
-
elif
|
|
278
|
+
elif comp_name == "video" and "video" in bt_event.updates:
|
|
274
279
|
video_curr = possible_states
|
|
275
|
-
current+=video_curr
|
|
280
|
+
current += video_curr
|
|
276
281
|
# video
|
|
277
|
-
elif
|
|
282
|
+
elif comp_name == "audio" and "audio" in bt_event.updates:
|
|
278
283
|
audio_curr = possible_states
|
|
279
|
-
current+=audio_curr
|
|
284
|
+
current += audio_curr
|
|
280
285
|
|
|
281
286
|
# wifi
|
|
282
287
|
elif comp_name == "wifi" and "wifi_running" in bt_event.updates:
|
|
@@ -296,7 +301,6 @@ class BatteryStatsParser(object):
|
|
|
296
301
|
curravg+=possible_states["controller"]["rx"]
|
|
297
302
|
avg_ct+=1
|
|
298
303
|
current += safe_division(curravg, avg_ct)
|
|
299
|
-
|
|
300
304
|
elif "wifi_radio" in bt_event.updates:
|
|
301
305
|
current+= possible_states["active"] if "active" in possible_states else 0
|
|
302
306
|
if "controller" in possible_states:
|
|
@@ -368,7 +372,7 @@ class BatteryStatsParser(object):
|
|
|
368
372
|
curravg+= on_vals[-1]
|
|
369
373
|
elif len(on_vals)>0:
|
|
370
374
|
curravg+= on_vals[signal_stren]
|
|
371
|
-
|
|
375
|
+
|
|
372
376
|
avg_ct+=1
|
|
373
377
|
if "rx" in possible_states["controller"]:
|
|
374
378
|
curravg+=possible_states["controller"]["rx"]
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from manafa.services.batteryStatsService import BatteryStatsService
|
|
4
|
+
from manafa.services.service import *
|
|
5
|
+
from manafa.services.perfettoService import PerfettoService
|
|
6
|
+
from manafa.perfetto.perfettoParser import PerfettoCPUfreqParser
|
|
7
|
+
from manafa.batteryStats.BatteryStatsParser import BatteryStatsParser
|
|
8
|
+
import argparse
|
|
9
|
+
from manafa.utils.Logger import log, LogSeverity
|
|
10
|
+
from manafa.utils.Utils import execute_shell_command, mega_find
|
|
11
|
+
|
|
12
|
+
DEFAULT_PROFILE="resources/profiles/power_profile.xml"
|
|
13
|
+
DEFAULT_TIMEZONE="GMT"
|
|
14
|
+
|
|
15
|
+
def getLastBootTime(bts_file=None):
|
|
16
|
+
res, out, err = execute_shell_command("adb shell cat /proc/stat | grep btime | awk '{print $2}'") #executeShCommand("adb shell cat /proc/stat | grep btime | awk '{print $2}'")
|
|
17
|
+
if res != 0 or len(out) == 0:
|
|
18
|
+
log("no device connected. Assuming Boot time of battery stats file", LogSeverity.ERROR)
|
|
19
|
+
flds = bts_file.split("-") if bts_file is not None else []
|
|
20
|
+
if len(flds)>1:
|
|
21
|
+
log("Boot time: " + flds[2], LogSeverity.WARNING )
|
|
22
|
+
return int(flds[2])
|
|
23
|
+
else:
|
|
24
|
+
log("no device connected. Assuming Boot time 0", LogSeverity.WARNING)
|
|
25
|
+
return 0
|
|
26
|
+
#raise Exception("Invalid boot time ")
|
|
27
|
+
#print("[Warning]: no device connected. Assuming Boot time %d" % boot_time)
|
|
28
|
+
return float(out.strip())
|
|
29
|
+
|
|
30
|
+
def is_float(string):
|
|
31
|
+
try:
|
|
32
|
+
float(string)
|
|
33
|
+
except ValueError:
|
|
34
|
+
return False
|
|
35
|
+
return True
|
|
36
|
+
|
|
37
|
+
class EManafa(Service):
|
|
38
|
+
"""docstring for GreenStats"""
|
|
39
|
+
def __init__(self, power_profile, timezone="EST", resources_dir="resources"):
|
|
40
|
+
Service.__init__(self)
|
|
41
|
+
self.power_profile = power_profile
|
|
42
|
+
self.boot_time = 0
|
|
43
|
+
log("Power profile file: " + power_profile , LogSeverity.INFO )
|
|
44
|
+
self.resources_dir = resources_dir
|
|
45
|
+
self.batterystats = BatteryStatsService()
|
|
46
|
+
self.perf_events = None
|
|
47
|
+
self.perfetto = PerfettoService()
|
|
48
|
+
self.timezone = timezone
|
|
49
|
+
|
|
50
|
+
def config(self, **kwargs):
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
def init(self):
|
|
54
|
+
self.boot_time = getLastBootTime()
|
|
55
|
+
self.batterystats.init(boot_time = self.boot_time)
|
|
56
|
+
self.perfetto.init(boot_time = self.boot_time)
|
|
57
|
+
|
|
58
|
+
def start(self):
|
|
59
|
+
self.batterystats.start()
|
|
60
|
+
self.perfetto.start()
|
|
61
|
+
|
|
62
|
+
def stop(self):
|
|
63
|
+
b_out = self.batterystats.stop()
|
|
64
|
+
p_out = self.perfetto.stop()
|
|
65
|
+
return b_out, p_out
|
|
66
|
+
|
|
67
|
+
def clean(self):
|
|
68
|
+
self.batterystats.clean()
|
|
69
|
+
self.perfetto.clean()
|
|
70
|
+
|
|
71
|
+
def parseResults(self, bts_file="", pf_file=""):
|
|
72
|
+
if bts_file== "" or pf_file == "":
|
|
73
|
+
log("Empty result files", LogSeverity.FATAL)
|
|
74
|
+
raise Exception()
|
|
75
|
+
self.b_time = getLastBootTime(bts_file)
|
|
76
|
+
self.bat_events = BatteryStatsParser(self.power_profile, timezone=self.timezone)
|
|
77
|
+
self.bat_events.parseFile(bts_file)
|
|
78
|
+
self.perf_events = PerfettoCPUfreqParser(self.power_profile, self.b_time, timezone=self.timezone)
|
|
79
|
+
self.perf_events.parseFile(pf_file)
|
|
80
|
+
|
|
81
|
+
# energy calc related stuff
|
|
82
|
+
def getConsumptionInBetween(self, start_time=0, end_time=9905715380):
|
|
83
|
+
total, per_component = self.calculateNonCpuEnergy(start_time, end_time)
|
|
84
|
+
total_cpu = self.calculateCPUEnergy(start_time,end_time)
|
|
85
|
+
per_component['cpu'] += total_cpu
|
|
86
|
+
return total + total_cpu, per_component
|
|
87
|
+
|
|
88
|
+
def calculateNonCpuEnergy(self, start_time, end_time):
|
|
89
|
+
c_beg_bef, c_beg_aft = getClosestPair(self.bat_events.events, start_time)
|
|
90
|
+
total = 0
|
|
91
|
+
per_component_consumption = {}
|
|
92
|
+
last_event = self.bat_events.events[c_beg_bef]
|
|
93
|
+
last_time = start_time
|
|
94
|
+
for i, x in enumerate(self.bat_events.events[c_beg_aft:]):
|
|
95
|
+
if x.time > end_time:
|
|
96
|
+
break
|
|
97
|
+
delta_time = abs(x.time - last_time)
|
|
98
|
+
tot_curr, comps_curr = last_event.getCurrentOfBatStatEvent()
|
|
99
|
+
total += tot_curr * (last_event.getVoltageValue()) * delta_time
|
|
100
|
+
for comp, comp_curr in comps_curr.items():
|
|
101
|
+
if comp not in per_component_consumption:
|
|
102
|
+
per_component_consumption[comp] = 0
|
|
103
|
+
if is_float(comp_curr):
|
|
104
|
+
per_component_consumption[comp] += (comp_curr * last_event.getVoltageValue() * delta_time)
|
|
105
|
+
last_event = x
|
|
106
|
+
last_time = x.time
|
|
107
|
+
|
|
108
|
+
delta_time = end_time - last_time
|
|
109
|
+
if delta_time < 0.0:
|
|
110
|
+
log(time.time(), "Error calculating delta (<0) ", LogSeverity.FATAL)
|
|
111
|
+
tot_curr, comps_curr = last_event.getCurrentOfBatStatEvent()
|
|
112
|
+
total += tot_curr * (last_event.getVoltageValue()) * (delta_time)
|
|
113
|
+
for comp, comp_curr in comps_curr.items():
|
|
114
|
+
if comp not in per_component_consumption:
|
|
115
|
+
per_component_consumption[comp] = 0
|
|
116
|
+
if is_float(comp_curr):
|
|
117
|
+
per_component_consumption[comp] += (comp_curr * last_event.getVoltageValue() * delta_time)
|
|
118
|
+
return total, per_component_consumption
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def calculateCPUEnergy(self,start_time,end_time):
|
|
122
|
+
c_beg_bef,c_beg_aft = getClosestPair(self.perf_events.events, start_time)
|
|
123
|
+
#c_end_bef,c_end_aft = getClosestPair(self.perf_events.events, end_time)
|
|
124
|
+
total = 0
|
|
125
|
+
last_event = self.perf_events.events[c_beg_bef]
|
|
126
|
+
last_time = start_time
|
|
127
|
+
tot_time=0
|
|
128
|
+
for i, x in enumerate(self.perf_events.events[c_beg_aft:]):
|
|
129
|
+
if x.time > end_time:
|
|
130
|
+
break
|
|
131
|
+
#print("between %f - %f" %(last_time,x.time) )
|
|
132
|
+
# get different states of cpu btween perf event interval
|
|
133
|
+
#print( x.time - last_time )
|
|
134
|
+
l = self.bat_events.getCPUSamplesInBetween(last_time,x.time)
|
|
135
|
+
# TODO : test to assert if x.time - last_time = sum( deltas_of_L )
|
|
136
|
+
for sample in l:
|
|
137
|
+
delta, state, voltage = sample[0],sample[1],sample[2]
|
|
138
|
+
cpus_current = last_event.calculateCPUsCurrent(state, self.perf_events.power_profile)
|
|
139
|
+
tot_time += delta
|
|
140
|
+
total += ( cpus_current) * delta * voltage
|
|
141
|
+
last_event = x
|
|
142
|
+
last_time = x.time
|
|
143
|
+
|
|
144
|
+
# after calcs'''
|
|
145
|
+
# TODO merge with cycle just like with non cpu
|
|
146
|
+
l = self.bat_events.getCPUSamplesInBetween(last_time, end_time)
|
|
147
|
+
for sample in l:
|
|
148
|
+
delta, state, voltage = sample[0], sample[1], sample[2]
|
|
149
|
+
cpus_current = last_event.calculateCPUsCurrent(state, self.perf_events.power_profile)
|
|
150
|
+
tot_time += delta
|
|
151
|
+
total += (cpus_current) * delta * voltage
|
|
152
|
+
# TODO just like non cpu
|
|
153
|
+
#print(tot_time)
|
|
154
|
+
return total
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def getClosestPair(events, time):
|
|
158
|
+
lasti = 0
|
|
159
|
+
for i, x in enumerate(events):
|
|
160
|
+
if x.time>time:
|
|
161
|
+
return lasti, i
|
|
162
|
+
lasti = i
|
|
163
|
+
return lasti,lasti
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def extractPowerProfile(resources_dir, filename):
|
|
167
|
+
# extracting power_profile.xml from device
|
|
168
|
+
res, suc, _ = execute_shell_command("adb pull /system/framework/framework-res.apk %s" % resources_dir)
|
|
169
|
+
if res==0:
|
|
170
|
+
cmd = """java -jar {res_dir}/apktool_2.4.0.jar d -s {res_dir}/framework-res.apk -o {res_dir}/out_jar_dir/""".format(res_dir=resources_dir)
|
|
171
|
+
res, suc, _ = execute_shell_command(cmd)
|
|
172
|
+
pp_file = resources_dir + "/out_jar_dir/res/xml/power_profile.xml"
|
|
173
|
+
if res==0:
|
|
174
|
+
# cp to profiles, remove out_jar_dir and framework-res.apk
|
|
175
|
+
res,_,_= execute_shell_command("cp {extracted_file} \"{res_dir}/profiles/{new_file}\" ; rm -rf {res_dir}/out_jar_dir {res_dir}/framework-res.apk".format(extracted_file=pp_file, new_file=filename, res_dir=resources_dir ))
|
|
176
|
+
if res ==0:
|
|
177
|
+
return filename
|
|
178
|
+
|
|
179
|
+
return DEFAULT_PROFILE
|
|
180
|
+
|
|
181
|
+
def inferPowerProfile(resources_dir):
|
|
182
|
+
res, device_model, _ = execute_shell_command("adb shell getprop ro.product.model")
|
|
183
|
+
if res == 0 and device_model != "":
|
|
184
|
+
model_profile_file = """power_profile_{device_model}.xml""".format(device_model=device_model.replace(" ", "").strip().lower())
|
|
185
|
+
matching_profiles = mega_find(resources_dir, pattern=model_profile_file, maxdepth=2)
|
|
186
|
+
if len(matching_profiles) > 0:
|
|
187
|
+
return matching_profiles[0]
|
|
188
|
+
else:
|
|
189
|
+
# if power profile not present in profiles directory, extract from device
|
|
190
|
+
power_profile = extractPowerProfile(resources_dir,model_profile_file)
|
|
191
|
+
return power_profile
|
|
192
|
+
else:
|
|
193
|
+
return DEFAULT_PROFILE
|
|
194
|
+
|
|
195
|
+
def inferTimezone():
|
|
196
|
+
res,out,err = execute_shell_command("adb shell date")
|
|
197
|
+
default_tz = DEFAULT_TIMEZONE
|
|
198
|
+
if res == 0 and len(out) > 0:
|
|
199
|
+
default_tz = out.split(" ")[-2]
|
|
200
|
+
log("Using timezone: %s" % default_tz)
|
|
201
|
+
return default_tz
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == '__main__':
|
|
205
|
+
default_resources_dir = "resources"
|
|
206
|
+
parser = argparse.ArgumentParser()
|
|
207
|
+
parser.add_argument("-p", "--profile", default=inferPowerProfile(default_resources_dir), type=str)
|
|
208
|
+
parser.add_argument("-t", "--timezone", default=inferTimezone(), type=str)
|
|
209
|
+
args = parser.parse_args()
|
|
210
|
+
g = EManafa(power_profile=args.profile, timezone=args.timezone,resources_dir=default_resources_dir)
|
|
211
|
+
g.init()
|
|
212
|
+
g.start()
|
|
213
|
+
time.sleep(7) # do work
|
|
214
|
+
bts_file, pf_file = g.stop()
|
|
215
|
+
#bts_file = "results/batterystats/bstats-1615831762.log"
|
|
216
|
+
#pf_file = "results/perfetto/trace-1615831762.systrace"
|
|
217
|
+
g.parseResults(bts_file, pf_file )
|
|
218
|
+
begin = g.bat_events.events[0].time
|
|
219
|
+
end = g.bat_events.events[-1].time
|
|
220
|
+
consumption, per_component_consumption = g.getConsumptionInBetween(begin, end)
|
|
221
|
+
print(per_component_consumption)
|
|
222
|
+
log("Energy consumed: %f Joules" % consumption, log_sev=LogSeverity.SUCCESS)
|
|
223
|
+
|
|
@@ -83,7 +83,7 @@ class PerfettoCPUfreqParser(object):
|
|
|
83
83
|
def loadPowerProfile(self, xml_profile ):
|
|
84
84
|
return PowerProfile(xml_profile)
|
|
85
85
|
|
|
86
|
-
def parseFile(self,filename):
|
|
86
|
+
def parseFile(self, filename):
|
|
87
87
|
with open(filename, 'r') as filehandle:
|
|
88
88
|
lines=filehandle.read().splitlines()
|
|
89
89
|
self.parseHistory(lines)
|
|
@@ -92,7 +92,7 @@ class PerfettoCPUfreqParser(object):
|
|
|
92
92
|
for line in lines:
|
|
93
93
|
if line.startswith("#"):
|
|
94
94
|
continue
|
|
95
|
-
z =
|
|
95
|
+
z = re.match(r"^\s*([^\s]+)\-(\d+)\s*\(\s*(\d+|\-+)\) \[(\d+)\] (\d+|\.+) ([0-9]*\.[0-9]+|[0-9]+)\: (.*)?$",line)
|
|
96
96
|
if z is not None:
|
|
97
97
|
time = float(z.groups()[5])
|
|
98
98
|
time += self.start_time
|
|
@@ -9,13 +9,15 @@ from ..utils.Utils import execute_shell_command
|
|
|
9
9
|
|
|
10
10
|
class BatteryStatsService(Service):
|
|
11
11
|
"""docstring for BatteryStatsService"""
|
|
12
|
-
def __init__(self, output_res_folder="batterystats"):
|
|
12
|
+
def __init__(self,boot_time=0, output_res_folder="batterystats"):
|
|
13
13
|
Service.__init__(self,output_res_folder)
|
|
14
|
+
self.boot_time = boot_time
|
|
14
15
|
|
|
15
16
|
def config(self,**kwargs):
|
|
16
17
|
pass
|
|
17
18
|
|
|
18
|
-
def init(self,**kwargs):
|
|
19
|
+
def init(self,boot_time=0,**kwargs):
|
|
20
|
+
self.boot_time = boot_time
|
|
19
21
|
self.clean()
|
|
20
22
|
|
|
21
23
|
def start(self):
|
|
@@ -25,7 +27,7 @@ class BatteryStatsService(Service):
|
|
|
25
27
|
|
|
26
28
|
if fil is None:
|
|
27
29
|
uid_file = execute_shell_command("date +%s")[1].strip()
|
|
28
|
-
filename = self.results_dir + "/bstats-%s.log" % uid_file
|
|
30
|
+
filename = self.results_dir + "/bstats-%s-%s.log" % (uid_file, str(self.boot_time))
|
|
29
31
|
execute_shell_command("adb shell dumpsys batterystats --history > %s" % filename)
|
|
30
32
|
#print(colored("Output file %s" % filename, "green"))
|
|
31
33
|
log("Output file %s" % filename)
|
|
@@ -10,13 +10,15 @@ from manafa.utils.Utils import execute_shell_command
|
|
|
10
10
|
|
|
11
11
|
class PerfettoService(Service):
|
|
12
12
|
"""docstring for BatteryStatsService"""
|
|
13
|
-
def __init__(self,output_res_folder="perfetto"):
|
|
13
|
+
def __init__(self,boot_time=0,output_res_folder="perfetto"):
|
|
14
14
|
Service.__init__(self,output_res_folder)
|
|
15
|
+
self.boot_time = boot_time
|
|
15
16
|
|
|
16
17
|
def config(self,**kwargs):
|
|
17
18
|
pass
|
|
18
19
|
|
|
19
|
-
def init(self,**kwargs):
|
|
20
|
+
def init(self,boot_time=0,**kwargs):
|
|
21
|
+
self.boot_time = boot_time
|
|
20
22
|
self.clean()
|
|
21
23
|
|
|
22
24
|
def start(self):
|
|
@@ -28,17 +30,15 @@ class PerfettoService(Service):
|
|
|
28
30
|
#executeShCommand("adb shell su -c \"killall perfetto\"")
|
|
29
31
|
execute_shell_command("adb shell killall perfetto")
|
|
30
32
|
time.sleep(1)
|
|
31
|
-
execute_shell_command("adb pull /data/misc/perfetto-traces/trace " + ("%strace" % self.results_dir )
|
|
33
|
+
execute_shell_command("adb pull /data/misc/perfetto-traces/trace " + ("%strace" % self.results_dir ) + "-" + file_id + "-" + str(self.boot_time))
|
|
32
34
|
return self.export()
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
def export(self):
|
|
36
37
|
last_exported = ""
|
|
37
38
|
for f in os.listdir(self.results_dir):
|
|
38
39
|
execute_shell_command("./resources/traceconv systrace %s/%s %s/%s.systrace" %(self.results_dir,f,self.results_dir,f) )
|
|
39
40
|
last_exported = "%s/%s.systrace" %(self.results_dir,f)
|
|
40
41
|
return last_exported
|
|
42
|
+
|
|
41
43
|
def clean(self):
|
|
42
44
|
execute_shell_command("find %s -type f | xargs rm " % self.results_dir)
|
|
43
|
-
|
|
44
|
-
|
|
@@ -3,13 +3,13 @@ from unittest import TestCase
|
|
|
3
3
|
|
|
4
4
|
class TestPerfettoService(TestCase):
|
|
5
5
|
def test_start(self):
|
|
6
|
-
self.
|
|
6
|
+
self.assertTrue(True)
|
|
7
7
|
|
|
8
8
|
def test_stop(self):
|
|
9
|
-
self.
|
|
9
|
+
self.assertTrue(True)
|
|
10
10
|
|
|
11
11
|
def test_export(self):
|
|
12
|
-
self.
|
|
12
|
+
self.assertTrue(True)
|
|
13
13
|
|
|
14
14
|
def test_clean(self):
|
|
15
|
-
self.
|
|
15
|
+
self.assertTrue(True)
|
{manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/utils/Utils.py
RENAMED
|
@@ -11,4 +11,4 @@ def mega_find(basedir, pattern="*", maxdepth=999, mindepth=0, type_file='n'):
|
|
|
11
11
|
basedir_len = len(basedir.split("/"))
|
|
12
12
|
res = find(basedir, pattern=pattern, only_files=type_file=='f',only_dirs=type_file=='d' )
|
|
13
13
|
# filter by depth
|
|
14
|
-
return list( filter(lambda x : len(x.split("/")) >= basedir_len + mindepth and len(x.split("/")) <= maxdepth + basedir_len , res ) )
|
|
14
|
+
return list( filter(lambda x : len(x.split("/")) >= basedir_len + mindepth and len(x.split("/")) <= maxdepth + basedir_len , res ) )
|
Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages/manafa-0.2.2-py3.8.egg-info/PKG-INFO
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: manafa
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: E-MANAFA: Energy Monitor and ANAlyzer For Android
|
|
5
|
+
Home-page: https://github.com/RRua/e-manafa
|
|
6
|
+
Author: Rui Rua
|
|
7
|
+
Author-email: rui.rrua@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/RRua/e-manafa/issues
|
|
10
|
+
Description: [](https://travis-ci.com/RRua/e-manafa)
|
|
11
|
+
[](https://www.python.org/)
|
|
12
|
+
[](https://badge.fury.io/py/manafa)
|
|
13
|
+
[](https://pypi.python.org/pypi/manafa)
|
|
14
|
+
[](https://pypi.python.org/pypi/manafa)
|
|
15
|
+
# E-MANAFA: Energy Monitor and ANAlyzer For Android
|
|
16
|
+
|
|
17
|
+
E-MANAFA is a software model-based tool for performing fine-grained estimates of energy consumption on Android devices. For this purpose, it uses values from power_profile.xml and from the BatteryStats and Perfetto services to estimate the energy consumption of each resource / component of the device.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# SETUP
|
|
21
|
+
|
|
22
|
+
In order to run this tool, the following resources are required:
|
|
23
|
+
- A rooted Android device (running Android 9 or above);
|
|
24
|
+
- A *nix-based environment (MAC OS , Linux);
|
|
25
|
+
- Python 3.6 or above;
|
|
26
|
+
- Android Sdk tools (https://developer.android.com/studio/releases/platform-tools)
|
|
27
|
+
|
|
28
|
+
# Installation
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install manafa
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## define environment variables
|
|
35
|
+
|
|
36
|
+
In order to run this tool, there are at least 2 env. variables that need to be defined in the shell startup script (e.g .bashrc or .bash_profile file)
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
export ANDROID_HOME=$HOME/<your-android-instalation-folder>/
|
|
40
|
+
export PATH=$ANDROID_HOME/platform-tools:$PATH
|
|
41
|
+
```
|
|
42
|
+
## Replicate the environment
|
|
43
|
+
|
|
44
|
+
Install virtual virtualenv enviroment (via python-pip):
|
|
45
|
+
```
|
|
46
|
+
$ python -m pip install --user virtualenv
|
|
47
|
+
```
|
|
48
|
+
## Replicate locally the dev virtualenv
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
$ virtualenv env/
|
|
52
|
+
```
|
|
53
|
+
## Activate the virtual environment
|
|
54
|
+
```
|
|
55
|
+
$ source env/bin/activate
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Extract power_profile.xml file from device (https://source.android.com/devices/tech/power/values)
|
|
59
|
+
Note: This file present in every device since Android 5 should contain values that were estimated by device manufacturers using external apparatus. However, most
|
|
60
|
+
devices don't provide a fine-grained power profile. Google provides a set of instructions in order to complete this file with more accurate values(https://source.android.com/devices/tech/power/component).
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
TODO
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
# Install required packages
|
|
67
|
+
```
|
|
68
|
+
$ pip install -r requirements.txt
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
# Examples
|
|
72
|
+
```
|
|
73
|
+
# getting the energy consumed during a profiling session (between first and last measurement)
|
|
74
|
+
g = GreenStats(power_profile=DEFAULT_PROFILE, timezone="EST")
|
|
75
|
+
g.init()
|
|
76
|
+
g.start()
|
|
77
|
+
do_some_work()
|
|
78
|
+
batstats_out_file, perfetto_out_file = g.stop()
|
|
79
|
+
g.parseResults( DEFAULT_PROFILE, batstats_out_file , perfetto_out_file )
|
|
80
|
+
begin = g.bat_events.events[0].time
|
|
81
|
+
end = g.bat_events.events[-1].time
|
|
82
|
+
consumption = g.getConsumptionInBetween(begin, end)
|
|
83
|
+
print("Energy consumed: %f Joules" % consumption)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
# Supported devices:
|
|
87
|
+
This tool can be used with any Android device able to run Perfetto, that is available since Android 9 (P). The tool so far was successfuly executed on the following devices:
|
|
88
|
+
- Pixel 3a
|
|
89
|
+
- Pixel 4a 5G
|
|
90
|
+
- Xiaomi Mi 9 Lite
|
|
91
|
+
|
|
92
|
+
# TODO
|
|
93
|
+
- calibrate the model
|
|
94
|
+
- test using flashlight
|
|
95
|
+
- Retrieve consumption per component
|
|
96
|
+
|
|
97
|
+
Platform: UNKNOWN
|
|
98
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
99
|
+
Classifier: Intended Audience :: Science/Research
|
|
100
|
+
Classifier: Operating System :: OS Independent
|
|
101
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
102
|
+
Requires-Python: >=3.8
|
|
103
|
+
Description-Content-Type: text/markdown
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
MANIFEST.in
|
|
1
2
|
README.md
|
|
2
|
-
|
|
3
|
+
notes.txt
|
|
4
|
+
requirements.txt
|
|
3
5
|
setup.py
|
|
4
6
|
manafa/__init__.py
|
|
5
7
|
manafa/emanafa.py
|
|
@@ -19,12 +21,23 @@ manafa/services/__init__.py
|
|
|
19
21
|
manafa/services/batteryStatsService.py
|
|
20
22
|
manafa/services/perfettoService.py
|
|
21
23
|
manafa/services/service.py
|
|
24
|
+
manafa/tests/__init__.py
|
|
25
|
+
manafa/tests/batterystats/__init__.py
|
|
26
|
+
manafa/tests/batterystats/test_batteryStatsService.py
|
|
27
|
+
manafa/tests/perfetto/__init__.py
|
|
28
|
+
manafa/tests/perfetto/test_perfettoService.py
|
|
22
29
|
manafa/utils/Logger.py
|
|
23
30
|
manafa/utils/Utils.py
|
|
24
31
|
manafa/utils/__init__.py
|
|
25
32
|
manafa/utils/dateUtils.py
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
resources/apktool_2.4.0.jar
|
|
34
|
+
resources/record_android_trace
|
|
35
|
+
resources/traceconv
|
|
36
|
+
resources/profiles/power_profile.xml
|
|
37
|
+
resources/profiles/power_profile_pixel3a.xml
|
|
38
|
+
resources/profiles/power_profile_pixel4a(5g).xml
|
|
39
|
+
results/batterystats/README.md
|
|
40
|
+
results/batterystats/bstats-1616406727-1614351254.0.log
|
|
41
|
+
results/perfetto/README.md
|
|
42
|
+
results/perfetto/trace-1616406727-1614351254.0
|
|
43
|
+
results/perfetto/trace-1616406727-1614351254.0.systrace
|
manafa-0.2.1/PKG-INFO
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: manafa
|
|
3
|
-
Version: 0.2.1
|
|
4
|
-
Summary: E-MANAFA: Energy Monitor and ANAlyzer For Android
|
|
5
|
-
Home-page: https://github.com/RRua/e-manafa
|
|
6
|
-
Author: Rui Rua
|
|
7
|
-
Author-email: rui.rrua@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Project-URL: Bug Tracker, https://github.com/RRua/e-manafa/issues
|
|
10
|
-
Description: # petra-like
|
|
11
|
-
|
|
12
|
-
This tool is a software model-based tool, for performing fine-grained estimates of energy consumption on Android devices. For this purpose, it uses the values contained in the power_profile.xml file for each device and the BatteryStats and Perfetto services to estimate the energy consumption of each resource / component of the device.
|
|
13
|
-
|
|
14
|
-
# SETUP
|
|
15
|
-
|
|
16
|
-
In order to run this tool, the following components are required:
|
|
17
|
-
- An Android rooted device (running Android 9 or above);
|
|
18
|
-
- A * nix-based environment;
|
|
19
|
-
- Android Sdk tools (https://developer.android.com/studio/releases/platform-tools)-
|
|
20
|
-
|
|
21
|
-
# Installation
|
|
22
|
-
|
|
23
|
-
## define environment variables
|
|
24
|
-
|
|
25
|
-
In order to run this tool, there are at least 2 env. variables that need to be defined in the shell startup script (e.g .bashrc or .bash_profile file)
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
export ANDROID_HOME=$HOME/android-sdk/
|
|
29
|
-
export PATH=$ANDROID_HOME/platform-tools:$PATH
|
|
30
|
-
```
|
|
31
|
-
## Replicate the enviroment
|
|
32
|
-
|
|
33
|
-
Install virtual virtualenv enviroment (via python-pip):
|
|
34
|
-
```
|
|
35
|
-
$ python -m pip install --user virtualenv
|
|
36
|
-
```
|
|
37
|
-
##Replicate locally the dev virtualenv
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
$ virtualenv env/
|
|
41
|
-
```
|
|
42
|
-
## Activate the virtual environment
|
|
43
|
-
```
|
|
44
|
-
$ source env/bin/activate
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Extract power_profile file from device
|
|
48
|
-
|
|
49
|
-
(In progress)
|
|
50
|
-
|
|
51
|
-
## Install required packages
|
|
52
|
-
```
|
|
53
|
-
$ pip install -r requirements.txt
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
# Example
|
|
57
|
-
```
|
|
58
|
-
# getting the energy consumed in a profiling session (between first and last measurement)
|
|
59
|
-
g = GreenStats(power_profile=DEFAULT_PROFILE, timezone="EST")
|
|
60
|
-
g.init()
|
|
61
|
-
g.start()
|
|
62
|
-
do_some_work()
|
|
63
|
-
batstats_out_file, perfetto_out_file = g.stop()
|
|
64
|
-
g.parseResults( DEFAULT_PROFILE, batstats_out_file , perfetto_out_file )
|
|
65
|
-
begin = g.bat_events.events[0].time
|
|
66
|
-
end = g.bat_events.events[-1].time
|
|
67
|
-
consumption = g.getConsumptionInBetween(begin, end)
|
|
68
|
-
print("Energy consumed: %f Joules" % consumption)
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
# TODO
|
|
72
|
-
- calibrate the model
|
|
73
|
-
- test using flashlight
|
|
74
|
-
|
|
75
|
-
Platform: UNKNOWN
|
|
76
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
77
|
-
Classifier: Intended Audience :: Science/Research
|
|
78
|
-
Classifier: Operating System :: OS Independent
|
|
79
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
80
|
-
Requires-Python: >=3.8
|
|
81
|
-
Description-Content-Type: text/markdown
|
manafa-0.2.1/README.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# petra-like
|
|
2
|
-
|
|
3
|
-
This tool is a software model-based tool, for performing fine-grained estimates of energy consumption on Android devices. For this purpose, it uses the values contained in the power_profile.xml file for each device and the BatteryStats and Perfetto services to estimate the energy consumption of each resource / component of the device.
|
|
4
|
-
|
|
5
|
-
# SETUP
|
|
6
|
-
|
|
7
|
-
In order to run this tool, the following components are required:
|
|
8
|
-
- An Android rooted device (running Android 9 or above);
|
|
9
|
-
- A * nix-based environment;
|
|
10
|
-
- Android Sdk tools (https://developer.android.com/studio/releases/platform-tools)-
|
|
11
|
-
|
|
12
|
-
# Installation
|
|
13
|
-
|
|
14
|
-
## define environment variables
|
|
15
|
-
|
|
16
|
-
In order to run this tool, there are at least 2 env. variables that need to be defined in the shell startup script (e.g .bashrc or .bash_profile file)
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
export ANDROID_HOME=$HOME/android-sdk/
|
|
20
|
-
export PATH=$ANDROID_HOME/platform-tools:$PATH
|
|
21
|
-
```
|
|
22
|
-
## Replicate the enviroment
|
|
23
|
-
|
|
24
|
-
Install virtual virtualenv enviroment (via python-pip):
|
|
25
|
-
```
|
|
26
|
-
$ python -m pip install --user virtualenv
|
|
27
|
-
```
|
|
28
|
-
##Replicate locally the dev virtualenv
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
$ virtualenv env/
|
|
32
|
-
```
|
|
33
|
-
## Activate the virtual environment
|
|
34
|
-
```
|
|
35
|
-
$ source env/bin/activate
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Extract power_profile file from device
|
|
39
|
-
|
|
40
|
-
(In progress)
|
|
41
|
-
|
|
42
|
-
## Install required packages
|
|
43
|
-
```
|
|
44
|
-
$ pip install -r requirements.txt
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
# Example
|
|
48
|
-
```
|
|
49
|
-
# getting the energy consumed in a profiling session (between first and last measurement)
|
|
50
|
-
g = GreenStats(power_profile=DEFAULT_PROFILE, timezone="EST")
|
|
51
|
-
g.init()
|
|
52
|
-
g.start()
|
|
53
|
-
do_some_work()
|
|
54
|
-
batstats_out_file, perfetto_out_file = g.stop()
|
|
55
|
-
g.parseResults( DEFAULT_PROFILE, batstats_out_file , perfetto_out_file )
|
|
56
|
-
begin = g.bat_events.events[0].time
|
|
57
|
-
end = g.bat_events.events[-1].time
|
|
58
|
-
consumption = g.getConsumptionInBetween(begin, end)
|
|
59
|
-
print("Energy consumed: %f Joules" % consumption)
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
# TODO
|
|
63
|
-
- calibrate the model
|
|
64
|
-
- test using flashlight
|
manafa-0.2.1/manafa/emanafa.py
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
|
|
3
|
-
from manafa.services.batteryStatsService import BatteryStatsService
|
|
4
|
-
from manafa.services.service import *
|
|
5
|
-
from manafa.services.perfettoService import PerfettoService
|
|
6
|
-
from manafa.perfetto.perfettoParser import PerfettoCPUfreqParser
|
|
7
|
-
from manafa.batteryStats.BatteryStatsParser import BatteryStatsParser
|
|
8
|
-
import argparse
|
|
9
|
-
from manafa.utils.Logger import log, LogSeverity
|
|
10
|
-
|
|
11
|
-
#DEFAULT_PROFILE="samples/profiles/power_profile.xml"
|
|
12
|
-
#DEFAULT_PROFILE="samples/profiles/power_profile_pixel3a_grapheneos.xml"
|
|
13
|
-
from manafa.utils.Utils import execute_shell_command
|
|
14
|
-
|
|
15
|
-
DEFAULT_PROFILE="resources/profiles/power_profile_pixel4a_grapheneos.xml"
|
|
16
|
-
DEFAULT_TIMEZONE="GMT"
|
|
17
|
-
|
|
18
|
-
def getLastBootTime():
|
|
19
|
-
res,out,err = execute_shell_command("adb shell cat /proc/stat | grep btime | awk '{print $2}'") #executeShCommand("adb shell cat /proc/stat | grep btime | awk '{print $2}'")
|
|
20
|
-
if res !=0 or len(out) == 0:
|
|
21
|
-
boot_time = 1605110840
|
|
22
|
-
log( "no device connected. Assuming Boot time %d" % boot_time, LogSeverity.ERROR )
|
|
23
|
-
#print("[Warning]: no device connected. Assuming Boot time %d" % boot_time)
|
|
24
|
-
return boot_time
|
|
25
|
-
return float(out.strip())
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class EManafa(Service):
|
|
29
|
-
"""docstring for GreenStats"""
|
|
30
|
-
def __init__(self,power_profile,timezone="EST"):
|
|
31
|
-
Service.__init__(self)
|
|
32
|
-
self.batterystats = BatteryStatsService()
|
|
33
|
-
self.bat_events = None
|
|
34
|
-
self.perf_events = None
|
|
35
|
-
self.perfetto = PerfettoService()
|
|
36
|
-
self.timezone = timezone
|
|
37
|
-
|
|
38
|
-
def config(self,**kwargs):
|
|
39
|
-
pass
|
|
40
|
-
|
|
41
|
-
def init(self):
|
|
42
|
-
self.batterystats.init()
|
|
43
|
-
self.perfetto.init()
|
|
44
|
-
|
|
45
|
-
def start(self):
|
|
46
|
-
self.batterystats.start()
|
|
47
|
-
self.perfetto.start()
|
|
48
|
-
|
|
49
|
-
def stop(self):
|
|
50
|
-
b_out = self.batterystats.stop()
|
|
51
|
-
p_out = self.perfetto.stop()
|
|
52
|
-
return b_out, p_out
|
|
53
|
-
|
|
54
|
-
def clean(self):
|
|
55
|
-
self.batterystats.clean()
|
|
56
|
-
self.perfetto.clean()
|
|
57
|
-
|
|
58
|
-
def parseResults(self, pp_file=DEFAULT_PROFILE, bts_file="", pf_file=""):
|
|
59
|
-
if bts_file== "" or pf_file == "":
|
|
60
|
-
log("Empty result files", LogSeverity.FATAL)
|
|
61
|
-
raise Exception()
|
|
62
|
-
self.bat_events = BatteryStatsParser(powerProfile=pp_file, timezone=self.timezone)
|
|
63
|
-
self.bat_events.parseFile(bts_file)
|
|
64
|
-
b_time = getLastBootTime()
|
|
65
|
-
self.perf_events = PerfettoCPUfreqParser(pp_file, b_time, timezone=self.timezone)
|
|
66
|
-
self.perf_events.parseFile(pf_file)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# energy calc related stuff
|
|
70
|
-
def getConsumptionInBetween(self,start_time=0, end_time=9905715380):
|
|
71
|
-
return self.calculateNonCpuEnergy(start_time, end_time) \
|
|
72
|
-
+ self.calculateCPUEnergy(start_time, end_time)
|
|
73
|
-
|
|
74
|
-
def calculateNonCpuEnergy(self, start_time, end_time):
|
|
75
|
-
c_beg_bef, c_beg_aft = getClosestPair(self.bat_events.events, start_time)
|
|
76
|
-
total = 0
|
|
77
|
-
last_event = self.bat_events.events[c_beg_bef]
|
|
78
|
-
last_time = start_time
|
|
79
|
-
for i, x in enumerate(self.bat_events.events[c_beg_aft:]):
|
|
80
|
-
if x.time > end_time:
|
|
81
|
-
break
|
|
82
|
-
delta_time = abs(x.time - last_time)
|
|
83
|
-
total += last_event.getCurrentOfBatStatEvent() * (last_event.getVoltageValue()) * (delta_time)
|
|
84
|
-
last_event = x
|
|
85
|
-
last_time = x.time
|
|
86
|
-
|
|
87
|
-
delta_time = end_time - last_time
|
|
88
|
-
if delta_time < 0.0:
|
|
89
|
-
log(time.time(), "Error calculating delta (<0) ", LogSeverity.FATAL )
|
|
90
|
-
print("fatal error")
|
|
91
|
-
total += last_event.getCurrentOfBatStatEvent() * (last_event.getVoltageValue()) * (delta_time)
|
|
92
|
-
|
|
93
|
-
return total
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def calculateCPUEnergy(self,start_time,end_time):
|
|
97
|
-
c_beg_bef,c_beg_aft = getClosestPair(self.perf_events.events, start_time)
|
|
98
|
-
#c_end_bef,c_end_aft = getClosestPair(self.perf_events.events, end_time)
|
|
99
|
-
total = 0
|
|
100
|
-
last_event = self.perf_events.events[c_beg_bef]
|
|
101
|
-
last_time = start_time
|
|
102
|
-
tot_time=0
|
|
103
|
-
for i, x in enumerate(self.perf_events.events[c_beg_aft:]):
|
|
104
|
-
if x.time > end_time:
|
|
105
|
-
break
|
|
106
|
-
#print("between %f - %f" %(last_time,x.time) )
|
|
107
|
-
# get different states of cpu btween perf event interval
|
|
108
|
-
#print( x.time - last_time )
|
|
109
|
-
l = self.bat_events.getCPUSamplesInBetween(last_time,x.time)
|
|
110
|
-
# TODO : test to assert if x.time - last_time = sum( deltas_of_L )
|
|
111
|
-
for sample in l:
|
|
112
|
-
delta,state,voltage = sample[0],sample[1],sample[2]
|
|
113
|
-
cpus_current= last_event.calculateCPUsCurrent(state,self.perf_events.power_profile)
|
|
114
|
-
tot_time +=delta
|
|
115
|
-
total += ( cpus_current) * delta * voltage
|
|
116
|
-
last_event = x
|
|
117
|
-
last_time = x.time
|
|
118
|
-
|
|
119
|
-
# after calcs'''
|
|
120
|
-
# TODO merge with cycle just like with non cpu
|
|
121
|
-
l = self.bat_events.getCPUSamplesInBetween(last_time,end_time)
|
|
122
|
-
for sample in l:
|
|
123
|
-
delta,state,voltage = sample[0],sample[1],sample[2]
|
|
124
|
-
cpus_current= last_event.calculateCPUsCurrent(state,self.perf_events.power_profile)
|
|
125
|
-
#print("cpucu- "+str(cpus_current))
|
|
126
|
-
#print("delta- "+str(delta))
|
|
127
|
-
#print("volta- "+str(voltage))
|
|
128
|
-
tot_time +=delta
|
|
129
|
-
total += ( cpus_current) * delta * voltage
|
|
130
|
-
#print("total- " + str(total))
|
|
131
|
-
#print()
|
|
132
|
-
|
|
133
|
-
# TODO just like non cpu
|
|
134
|
-
#print(tot_time)
|
|
135
|
-
return total
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def getClosestPair(events, time ):
|
|
139
|
-
lasti = 0
|
|
140
|
-
for i, x in enumerate(events):
|
|
141
|
-
if x.time>time:
|
|
142
|
-
return lasti, i
|
|
143
|
-
lasti = i
|
|
144
|
-
return lasti,lasti
|
|
145
|
-
|
|
146
|
-
def inferPowerProfile():
|
|
147
|
-
return DEFAULT_PROFILE#TODO
|
|
148
|
-
|
|
149
|
-
def inferTimezone():
|
|
150
|
-
res,out,err = execute_shell_command("adb shell date")
|
|
151
|
-
default_tz = DEFAULT_TIMEZONE
|
|
152
|
-
if res ==0 and len(out)>0:
|
|
153
|
-
default_tz = out.split(" ")[-2]
|
|
154
|
-
log("Using timezone: %s" % default_tz)
|
|
155
|
-
return default_tz
|
|
156
|
-
|
|
157
|
-
if __name__ == '__main__':
|
|
158
|
-
parser = argparse.ArgumentParser()
|
|
159
|
-
parser.add_argument("-p", "--profile", default=inferPowerProfile(), type=str)
|
|
160
|
-
parser.add_argument("-t", "--timezone", default=inferTimezone(), type=str)
|
|
161
|
-
args = parser.parse_args()
|
|
162
|
-
g = EManafa(power_profile=args.profile, timezone=args.timezone)
|
|
163
|
-
g.init()
|
|
164
|
-
g.start()
|
|
165
|
-
time.sleep(7)# do work
|
|
166
|
-
bts_file, pf_file = g.stop()
|
|
167
|
-
#bts_file = "results/batterystats/bstats-1615831762.log"
|
|
168
|
-
#pf_file = "results/perfetto/trace-1615831762.systrace"
|
|
169
|
-
g.parseResults(DEFAULT_PROFILE, bts_file , pf_file )
|
|
170
|
-
begin = g.bat_events.events[0].time
|
|
171
|
-
end = g.bat_events.events[-1].time
|
|
172
|
-
consumption = g.getConsumptionInBetween(begin, end)
|
|
173
|
-
log("Energy consumed: %f Joules" % consumption, log_sev=LogSeverity.SUCCESS)
|
|
174
|
-
|
|
175
|
-
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: manafa
|
|
3
|
-
Version: 0.2.1
|
|
4
|
-
Summary: E-MANAFA: Energy Monitor and ANAlyzer For Android
|
|
5
|
-
Home-page: https://github.com/RRua/e-manafa
|
|
6
|
-
Author: Rui Rua
|
|
7
|
-
Author-email: rui.rrua@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Project-URL: Bug Tracker, https://github.com/RRua/e-manafa/issues
|
|
10
|
-
Description: # petra-like
|
|
11
|
-
|
|
12
|
-
This tool is a software model-based tool, for performing fine-grained estimates of energy consumption on Android devices. For this purpose, it uses the values contained in the power_profile.xml file for each device and the BatteryStats and Perfetto services to estimate the energy consumption of each resource / component of the device.
|
|
13
|
-
|
|
14
|
-
# SETUP
|
|
15
|
-
|
|
16
|
-
In order to run this tool, the following components are required:
|
|
17
|
-
- An Android rooted device (running Android 9 or above);
|
|
18
|
-
- A * nix-based environment;
|
|
19
|
-
- Android Sdk tools (https://developer.android.com/studio/releases/platform-tools)-
|
|
20
|
-
|
|
21
|
-
# Installation
|
|
22
|
-
|
|
23
|
-
## define environment variables
|
|
24
|
-
|
|
25
|
-
In order to run this tool, there are at least 2 env. variables that need to be defined in the shell startup script (e.g .bashrc or .bash_profile file)
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
export ANDROID_HOME=$HOME/android-sdk/
|
|
29
|
-
export PATH=$ANDROID_HOME/platform-tools:$PATH
|
|
30
|
-
```
|
|
31
|
-
## Replicate the enviroment
|
|
32
|
-
|
|
33
|
-
Install virtual virtualenv enviroment (via python-pip):
|
|
34
|
-
```
|
|
35
|
-
$ python -m pip install --user virtualenv
|
|
36
|
-
```
|
|
37
|
-
##Replicate locally the dev virtualenv
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
$ virtualenv env/
|
|
41
|
-
```
|
|
42
|
-
## Activate the virtual environment
|
|
43
|
-
```
|
|
44
|
-
$ source env/bin/activate
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Extract power_profile file from device
|
|
48
|
-
|
|
49
|
-
(In progress)
|
|
50
|
-
|
|
51
|
-
## Install required packages
|
|
52
|
-
```
|
|
53
|
-
$ pip install -r requirements.txt
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
# Example
|
|
57
|
-
```
|
|
58
|
-
# getting the energy consumed in a profiling session (between first and last measurement)
|
|
59
|
-
g = GreenStats(power_profile=DEFAULT_PROFILE, timezone="EST")
|
|
60
|
-
g.init()
|
|
61
|
-
g.start()
|
|
62
|
-
do_some_work()
|
|
63
|
-
batstats_out_file, perfetto_out_file = g.stop()
|
|
64
|
-
g.parseResults( DEFAULT_PROFILE, batstats_out_file , perfetto_out_file )
|
|
65
|
-
begin = g.bat_events.events[0].time
|
|
66
|
-
end = g.bat_events.events[-1].time
|
|
67
|
-
consumption = g.getConsumptionInBetween(begin, end)
|
|
68
|
-
print("Energy consumed: %f Joules" % consumption)
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
# TODO
|
|
72
|
-
- calibrate the model
|
|
73
|
-
- test using flashlight
|
|
74
|
-
|
|
75
|
-
Platform: UNKNOWN
|
|
76
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
77
|
-
Classifier: Intended Audience :: Science/Research
|
|
78
|
-
Classifier: Operating System :: OS Independent
|
|
79
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
80
|
-
Requires-Python: >=3.8
|
|
81
|
-
Description-Content-Type: text/markdown
|
manafa-0.2.1/setup.cfg
DELETED
manafa-0.2.1/setup.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import setuptools
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
with open("README.md", "r", encoding='utf-8') as fh:
|
|
5
|
-
long_description = fh.read()
|
|
6
|
-
|
|
7
|
-
setup(
|
|
8
|
-
name='manafa',
|
|
9
|
-
version='0.2.1',
|
|
10
|
-
description='E-MANAFA: Energy Monitor and ANAlyzer For Android',
|
|
11
|
-
long_description=long_description,
|
|
12
|
-
long_description_content_type='text/markdown',
|
|
13
|
-
author='Rui Rua',
|
|
14
|
-
author_email='rui.rrua@gmail.com',
|
|
15
|
-
url='https://github.com/RRua/e-manafa',
|
|
16
|
-
license='MIT',
|
|
17
|
-
#package_dir={"": "manafa"},
|
|
18
|
-
packages=setuptools.find_packages(),
|
|
19
|
-
install_requires=[
|
|
20
|
-
'pytz==2021.1',
|
|
21
|
-
'termcolor==1.1.0',
|
|
22
|
-
'python-textops3==3.1.0',
|
|
23
|
-
'python-dateutil==2.8.1',
|
|
24
|
-
"setuptools>=42",
|
|
25
|
-
"wheel"
|
|
26
|
-
],
|
|
27
|
-
include_package_data=True,
|
|
28
|
-
classifiers=[
|
|
29
|
-
'License :: OSI Approved :: MIT License',
|
|
30
|
-
'Intended Audience :: Science/Research',
|
|
31
|
-
'Operating System :: OS Independent',
|
|
32
|
-
'Programming Language :: Python :: 3.8',
|
|
33
|
-
],
|
|
34
|
-
project_urls = {
|
|
35
|
-
'Bug Tracker': 'https://github.com/RRua/e-manafa/issues'
|
|
36
|
-
},
|
|
37
|
-
python_requires=">=3.8",
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
'''setup(
|
|
41
|
-
name='e-manafa',
|
|
42
|
-
version='0.1.0',
|
|
43
|
-
packages=['tests', 'tests.perfetto', 'tests.batterystats', 'manafa', 'manafa.utils', 'manafa.perfetto',
|
|
44
|
-
'manafa.services', 'manafa.batteryStats', 'manafa.powerProfile'],
|
|
45
|
-
url='https://github.com/RRua/e-manafa',
|
|
46
|
-
license='MIT',
|
|
47
|
-
author='ruirua',
|
|
48
|
-
author_email='rui.rrua@gmail.com',
|
|
49
|
-
description='e-manafa tool'
|
|
50
|
-
)'''
|
{manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{manafa-0.2.1 → Users/ruirua/repos/emanafa/venv/lib/python3.8/site-packages}/manafa/utils/Logger.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|