blob: 67783def6978ce40a3fb789f8e6e7c313524330f [file] [log] [blame]
Daniel Wagner1d44e982022-06-29 17:42:39 +02001#!/usr/bin/env python3
2import argparse
3import platform
4import json
5
6# Transform rtla hist out data into the same format as rt-tests
7# framework is producing.
8
9
10def parse_args():
11 parser = argparse.ArgumentParser()
12 parser.add_argument(
13 "-r",
14 "--result-file",
15 dest="result_file",
16 required=True,
17 default="./result.txt",
18 help="Specify test result file.",
19 )
20 parser.add_argument(
21 "-t",
22 "--test-name",
23 required=True,
24 help="Specify test name.",
25 )
26 parser.add_argument(
27 "-o",
28 "--output",
29 dest="output",
30 help="Specify output file.",
31 )
32
33 args = parser.parse_args()
34 return args
35
36
37def get_sysinfo():
38 sysinfo = {}
39
40 uname = platform.uname()
41 sysinfo["sysname"] = uname.system
42 sysinfo["nodename"] = uname.node
43 sysinfo["release"] = uname.release
44 sysinfo["version"] = uname.version
45 sysinfo["machine"] = uname.machine
46
47 realtime = 0
48 try:
49 with open("/sys/kernel/realtime", "r") as rfl:
50 realtime = int(rfl.read(1))
51 except IOError:
52 pass
53 sysinfo["realtime"] = realtime
54
55 return sysinfo
56
57
58def parse_histogram(col, sel, i, hist):
59 if i not in hist:
60 hist[i] = {}
61 hist[i]["histogram"] = {}
62
63 if col[0].endswith(":"):
64 name = col[0][:-1]
65 hist[i][name] = int(col[sel])
66 else:
67 hist[i]["histogram"][col[0]] = int(col[sel])
68
69
70def parse_osnoise(result_file):
71 data = {}
72 threads = {}
73 for line in result_file.readlines():
74 if line.startswith(" "):
75 continue
76
77 col = line.split()
78
79 num_cols = len(col) - 1
80
81 for i, sel in zip(range(0, num_cols), range(1, len(col), 1)):
82 parse_histogram(col, sel, i, threads)
83
84 data["file_version"] = 2
85 data["return_code"] = 0
86 data["sysinfo"] = get_sysinfo()
87 data["num_threads"] = num_cols
88 data["resolution_in_ns"] = 0
89 data["thread"] = threads
90
91 return data
92
93
94def main(args):
95 with open(args.result_file, "r") as infile:
96 if args.test_name == "osnoise":
97 data = parse_osnoise(infile)
98
99 if args.output:
100 with open(args.output, "w") as outfile:
101 outfile.write(json.dumps(data, indent=2))
102 else:
103 print(json.dumps(data, indent=2))
104
105
106if __name__ == "__main__":
107 main(parse_args())