aboutsummaryrefslogtreecommitdiffstats
path: root/parse/sched.py
diff options
context:
space:
mode:
Diffstat (limited to 'parse/sched.py')
-rw-r--r--parse/sched.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/parse/sched.py b/parse/sched.py
new file mode 100644
index 0000000..ec4d917
--- /dev/null
+++ b/parse/sched.py
@@ -0,0 +1,89 @@
1import config.config as conf
2import os
3import re
4import numpy as np
5import subprocess
6
7from collections import namedtuple
8from point import Measurement
9
10Task = namedtuple('Task', ['pid', 'period'])
11
12def get_st_output(data_dir, out_dir):
13 bin_files = conf.FILES['sched_data'].format(".*")
14 bins = [f for f in os.listdir(data_dir) if re.match(bin_files, f)]
15
16 output_file = "%s/out-st" % out_dir
17
18 if os.path.isfile(output_file):
19 return output_file
20
21 if len(bins) != 0:
22 cmd_arr = [conf.BINS['st_show']]
23 cmd_arr.extend(bins)
24 with open(output_file, "w") as f:
25 subprocess.call(cmd_arr, cwd=data_dir, stdout=f)
26 else:
27 return None
28 return output_file
29
30def get_tasks(data):
31 reg = r"PARAM.*?(\d+).*?cost:\s+[\d\.]+ms.*?period.*?([\d.]+)"
32 return [Task(x[0], x[1]) for x in re.findall(reg, data)]
33
34def extract_tardy_vals(data, exp_point):
35 ratios = []
36 tards = []
37
38 for t in get_tasks(data):
39 reg = r"TARDY.*?" + t.pid + "/(\d+).*?Tot.*?([\d.]+).*?ms.*([\d.]+).*?ms.*?([\d.]+)"
40 matches = re.findall(reg, data)
41 if len(matches) != 0:
42 jobs = float(matches[0][0])
43 total_tard = float(matches[0][1])
44 # max_tard = float(matches[0][2])
45 misses = float(matches[0][3])
46 rel_tard = (total_tard / jobs) / float(t.period)
47 if misses != 0:
48 miss_ratio = (misses / jobs)
49 else:
50 miss_ratio = 0
51
52 ratios.append(miss_ratio)
53 tards.append(rel_tard)
54
55 for (array, name) in ((tards, "rel-tard"), (ratios, "miss-ratio")):
56 exp_point[name] = Measurement().from_array(array)
57
58def extract_variance(data, exp_point):
59 varz = []
60 for t in get_tasks(data):
61 reg = r"COMPLETION.*?" + t.pid + r".*?([\d\.]+)ms"
62 matches = re.findall(reg, data)
63
64 if len(matches) == 0:
65 return 0
66
67 job_times = np.array(filter(lambda x: float(x) != 0, matches), dtype=np.float)
68
69 # Coefficient of variation
70 cv = job_times.std() / job_times.mean()
71 # Correction, assuming normal distributions
72 corrected = (1 + 1/(4 * len(job_times))) * cv
73
74 varz.append(corrected)
75
76 exp_point['var'] = Measurement().from_array(varz)
77
78def get_sched_data(data_file, result):
79 with open(data_file, 'r') as f:
80 data = f.read()
81
82 # if conf != BASE:
83 # (our_values, their_values) = extract_exec_vals(our_data, their_data)
84 # conf_result = get_stats(our_values, their_values)
85 # for key in conf_result.keys():
86 # result[key][conf] = conf_result[key]
87
88 extract_tardy_vals(data, result)
89 extract_variance(data, result)