-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path01metrics.py
More file actions
executable file
·78 lines (64 loc) · 2.11 KB
/
01metrics.py
File metadata and controls
executable file
·78 lines (64 loc) · 2.11 KB
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
import copy
import json
import os
import sys
def merge(a, b, path=None):
"merges b into a"
if path is None: path = []
for key in b:
if key in a:
if isinstance(a[key], dict) and isinstance(b[key], dict):
# merge dics
merge(a[key], b[key], path + [str(key)])
elif isinstance(a[key], list) and isinstance(b[key], list):
# concatenate lists
a[key] = a[key] + b[key]
elif a[key] == b[key]:
pass # same leaf value
else:
raise Exception('Conflict at %s' % '.'.join(path + [str(key)]))
else:
a[key] = b[key]
return a
def extract_json_metrics(output):
metrics = {}
lines = iter(output.split("\n"))
for line in lines:
if line.startswith("{"):
try:
metric = json.loads(line)
metrics = merge(metrics, metric)
except json.decoder.JSONDecodeError:
pass
return metrics
def main():
outdir = os.environ.get("output_dir", os.getcwd())
infile = os.path.join(outdir, "result.json")
outfile = os.path.join(outdir, "metrics.json")
try:
with open(infile, "r") as f:
d = json.load(f)
except FileNotFoundError:
print("cannot open %s. exiting." % infile)
sys.exit(1)
merged_metrics = {}
for job in d:
result = job["result"]
if result["status"] != 0:
continue
body = result["body"]
command = body["command"]
if not (command.startswith("./.murdock compile") or
command.startswith("./.murdock run_test")):
continue
metrics = extract_json_metrics(result["output"])
if metrics:
_command = command.split(" ")
app = _command[2]
board = _command[3]
merge(merged_metrics, { app : { board : copy.deepcopy(metrics) } })
result = { "metrics" : merged_metrics }
with open(outfile, "w") as f:
json.dump(result, f, sort_keys=True, indent=4)
if __name__=="__main__":
main()