Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ucyo committed Dec 21, 2022
1 parent e634db0 commit abc17c2
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 13 deletions.
48 changes: 35 additions & 13 deletions annotate.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import sys
import subprocess as sp
import json
from dataclasses import dataclass, field

""" Piped commands not working currently
"""

def main(keyword, hyperfine_json, cmd):
result = execute_cmd(cmd)
print(keyword, hyperfine_json, cmd, result)
@dataclass
class Annotation:
json: str
data: dict = field(init=False)

def __post_init__(self):
with open(self.json, 'r') as f:
self.data = json.load(f)

def execute_cmd(self, key, cmd):
try:
result = sp.check_output(cmd, shell=True).decode('ascii')
except sp.CalledProcessError as err:
print(f"Failed w/ {err}")
raise
else:
tmp = self.data["results"][0]
if hasattr(tmp,"annotations"):
tmp["annotations"][key] = result
else:
tmp["annotations"] = {key:result}
self.data["results"][0] = tmp

def execute_cmd(cmd):
try:
result = sp.check_output(cmd, shell=True)
except sp.CalledProcessError as err:
print(f"Failed w/ {err}")
raise
else:
return result
def export(self):
with open('new_' + self.json, 'w') as f:
json.dump(self.data, f, indent=2)


def main(keyword, hyperfine_json, cmd):
annon = Annotation(hyperfine_json)
annon.execute_cmd(keyword, cmd)
annon.export()

if __name__ == '__main__':
keyword = sys.argv[1]
json = sys.argv[2]
js = sys.argv[2]
command = sys.argv[3:]
main(keyword = keyword, hyperfine_json = json, cmd = command)
main(keyword = keyword, hyperfine_json = js, cmd = command)
77 changes: 77 additions & 0 deletions test2.json.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"results": [
{
"command": "rsync",
"exit_codes": [
0,
0,
0,
0,
0
],
"max": 0.07392307326,
"mean": 0.07207379846,
"median": 0.07090162326,
"min": 0.07073374126000001,
"stddev": 0.0016844171805740977,
"system": 0.0122821,
"times": [
0.07391188326,
0.07073374126000001,
0.07089867126,
0.07392307326,
0.07090162326
],
"user": 0.02015368,
"filesize": "s"
},
{
"command": "dd",
"exit_codes": [
0,
0,
0,
0,
0
],
"max": 0.00985483132,
"mean": 0.003623512319999999,
"median": 0.0014402743199999984,
"min": 0.0008693063199999985,
"stddev": 0.003894471471097009,
"system": 0.0018644,
"times": [
0.00985483132,
0.005056125319999999,
0.0014402743199999984,
0.000897024319999998,
0.0008693063199999985
],
"user": 0.001715668
},
{
"command": "cp",
"exit_codes": [
0,
0,
0,
0,
0
],
"max": 0.003891476679999999,
"mean": 0.002352617079999999,
"median": 0.001960960679999999,
"min": 0.001558529679999999,
"stddev": 0.0009546999751138052,
"system": 0.00177618,
"times": [
0.003891476679999999,
0.0026404966799999986,
0.001960960679999999,
0.001558529679999999,
0.0017116216799999986
],
"user": 0.0008574720000000001
}
]
}

0 comments on commit abc17c2

Please sign in to comment.