MCPcopy Create free account
hub / github.com/comaps/comaps / read_file

Method read_file

tools/python/InstrumentsTraceParser.py:25–44  ·  view source on GitHub ↗
(self, file_path)

Source from the content-addressed store, hash-verified

23
24
25 def read_file(self, file_path):
26 binary = bytearray()
27 with open(file_path, "r") as f:
28 binary = bytearray(f.read())
29
30 for i in range(0, len(binary) - 24, 24):
31 res = struct.unpack(">ddd", binary[i:i+24])
32
33 current_duration = res[0]
34 if not current_duration > self.duration:
35 print("Unexpected elapsed time value, lower than the previous one.")
36 exit(2) # this should never happen because the file is written sequentially
37
38 current_consumption = res[2]
39 self.averages.append(current_consumption / (current_duration - self.duration))
40 self.duration = current_duration
41
42 self.consumption.append(current_consumption)
43
44 self.calculate_stats()
45
46
47 def calculate_stats(self):

Callers 1

Calls 3

calculate_statsMethod · 0.95
readMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected