Skip to content

Commit abc17c2

Browse files
committed
Update
1 parent e634db0 commit abc17c2

File tree

2 files changed

+112
-13
lines changed

2 files changed

+112
-13
lines changed

annotate.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
import sys
22
import subprocess as sp
3+
import json
4+
from dataclasses import dataclass, field
35

6+
""" Piped commands not working currently
7+
"""
48

5-
def main(keyword, hyperfine_json, cmd):
6-
result = execute_cmd(cmd)
7-
print(keyword, hyperfine_json, cmd, result)
9+
@dataclass
10+
class Annotation:
11+
json: str
12+
data: dict = field(init=False)
13+
14+
def __post_init__(self):
15+
with open(self.json, 'r') as f:
16+
self.data = json.load(f)
817

18+
def execute_cmd(self, key, cmd):
19+
try:
20+
result = sp.check_output(cmd, shell=True).decode('ascii')
21+
except sp.CalledProcessError as err:
22+
print(f"Failed w/ {err}")
23+
raise
24+
else:
25+
tmp = self.data["results"][0]
26+
if hasattr(tmp,"annotations"):
27+
tmp["annotations"][key] = result
28+
else:
29+
tmp["annotations"] = {key:result}
30+
self.data["results"][0] = tmp
931

10-
def execute_cmd(cmd):
11-
try:
12-
result = sp.check_output(cmd, shell=True)
13-
except sp.CalledProcessError as err:
14-
print(f"Failed w/ {err}")
15-
raise
16-
else:
17-
return result
32+
def export(self):
33+
with open('new_' + self.json, 'w') as f:
34+
json.dump(self.data, f, indent=2)
1835

1936

37+
def main(keyword, hyperfine_json, cmd):
38+
annon = Annotation(hyperfine_json)
39+
annon.execute_cmd(keyword, cmd)
40+
annon.export()
41+
2042
if __name__ == '__main__':
2143
keyword = sys.argv[1]
22-
json = sys.argv[2]
44+
js = sys.argv[2]
2345
command = sys.argv[3:]
24-
main(keyword = keyword, hyperfine_json = json, cmd = command)
46+
main(keyword = keyword, hyperfine_json = js, cmd = command)

test2.json.backup

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"results": [
3+
{
4+
"command": "rsync",
5+
"exit_codes": [
6+
0,
7+
0,
8+
0,
9+
0,
10+
0
11+
],
12+
"max": 0.07392307326,
13+
"mean": 0.07207379846,
14+
"median": 0.07090162326,
15+
"min": 0.07073374126000001,
16+
"stddev": 0.0016844171805740977,
17+
"system": 0.0122821,
18+
"times": [
19+
0.07391188326,
20+
0.07073374126000001,
21+
0.07089867126,
22+
0.07392307326,
23+
0.07090162326
24+
],
25+
"user": 0.02015368,
26+
"filesize": "s"
27+
},
28+
{
29+
"command": "dd",
30+
"exit_codes": [
31+
0,
32+
0,
33+
0,
34+
0,
35+
0
36+
],
37+
"max": 0.00985483132,
38+
"mean": 0.003623512319999999,
39+
"median": 0.0014402743199999984,
40+
"min": 0.0008693063199999985,
41+
"stddev": 0.003894471471097009,
42+
"system": 0.0018644,
43+
"times": [
44+
0.00985483132,
45+
0.005056125319999999,
46+
0.0014402743199999984,
47+
0.000897024319999998,
48+
0.0008693063199999985
49+
],
50+
"user": 0.001715668
51+
},
52+
{
53+
"command": "cp",
54+
"exit_codes": [
55+
0,
56+
0,
57+
0,
58+
0,
59+
0
60+
],
61+
"max": 0.003891476679999999,
62+
"mean": 0.002352617079999999,
63+
"median": 0.001960960679999999,
64+
"min": 0.001558529679999999,
65+
"stddev": 0.0009546999751138052,
66+
"system": 0.00177618,
67+
"times": [
68+
0.003891476679999999,
69+
0.0026404966799999986,
70+
0.001960960679999999,
71+
0.001558529679999999,
72+
0.0017116216799999986
73+
],
74+
"user": 0.0008574720000000001
75+
}
76+
]
77+
}

0 commit comments

Comments
 (0)