diff options
Diffstat (limited to 'experiment/tracer.py')
-rw-r--r-- | experiment/tracer.py | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/experiment/tracer.py b/experiment/tracer.py new file mode 100644 index 0000000..d7743ad --- /dev/null +++ b/experiment/tracer.py | |||
@@ -0,0 +1,118 @@ | |||
1 | import litmus_util | ||
2 | import os | ||
3 | from operator import methodcaller | ||
4 | from executable.ftcat import FTcat,Executable | ||
5 | from config.config import FILES,BINS | ||
6 | |||
7 | class Tracer(object): | ||
8 | def __init__(self, name, output_dir): | ||
9 | self.name = name | ||
10 | self.output_dir = output_dir | ||
11 | self.bins = [] | ||
12 | |||
13 | def start_tracing(self): | ||
14 | map(methodcaller("execute"), self.bins) | ||
15 | |||
16 | def stop_tracing(self): | ||
17 | map(methodcaller('terminate'), self.bins) | ||
18 | map(methodcaller('wait'), self.bins) | ||
19 | |||
20 | |||
21 | class LinuxTracer(Tracer): | ||
22 | EVENT_ROOT = "/sys/kernel/debug/tracing" | ||
23 | LITMUS_EVENTS = "%s/events/litmus" % EVENT_ROOT | ||
24 | |||
25 | def __init__(self, output_dir): | ||
26 | super(LinuxTracer, self).__init__("trace-cmd", output_dir) | ||
27 | |||
28 | extra_args = ["record", "-e", "sched:sched_switch", | ||
29 | "-e", "litmus:*", | ||
30 | "-o", "%s/%s" % (output_dir, FILES['linux_data'])] | ||
31 | stdout = open('%s/trace-cmd-stdout.txt' % self.output_dir, 'w') | ||
32 | stderr = open('%s/trace-cmd-stderr.txt' % self.output_dir, 'w') | ||
33 | |||
34 | execute = Executable(BINS['trace-cmd'], extra_args, stdout, stderr) | ||
35 | self.bins.append(execute) | ||
36 | |||
37 | @staticmethod | ||
38 | def enabled(): | ||
39 | return os.path.exists(LinuxTracer.LITMUS_EVENTS) | ||
40 | |||
41 | def stop_tracing(self): | ||
42 | map(methodcaller('interrupt'), self.bins) | ||
43 | map(methodcaller('wait'), self.bins) | ||
44 | |||
45 | |||
46 | class LogTracer(Tracer): | ||
47 | DEVICE_STR = '/dev/litmus/log' | ||
48 | |||
49 | def __init__(self, output_dir): | ||
50 | super(LogTracer, self).__init__("Logger", output_dir) | ||
51 | |||
52 | out_file = open("%s/%s" % (self.output_dir, FILES['log_data']), 'w') | ||
53 | |||
54 | cat = (Executable("/bin/cat", [LogTracer.DEVICE_STR])) | ||
55 | cat.stdout_file = out_file | ||
56 | |||
57 | self.bins.append(cat) | ||
58 | |||
59 | @staticmethod | ||
60 | def enabled(): | ||
61 | return litmus_util.is_device(LogTracer.DEVICE_STR) | ||
62 | |||
63 | |||
64 | class SchedTracer(Tracer): | ||
65 | EVENTS = range(501, 510) # not including 511 | ||
66 | DEVICE_STR = '/dev/litmus/sched_trace' | ||
67 | |||
68 | def __init__(self, output_dir): | ||
69 | super(SchedTracer, self).__init__("Sched Trace", output_dir) | ||
70 | |||
71 | if SchedTracer.enabled(): | ||
72 | for cpu in range(litmus_util.num_cpus()): | ||
73 | # Executable will close the stdout/stderr files | ||
74 | stdout_f = open('%s/st-%d.bin' % (self.output_dir, cpu), 'w') | ||
75 | stderr_f = open('%s/st-%d-stderr.txt' % (self.output_dir, cpu), 'w') | ||
76 | dev = '{0}{1}'.format(SchedTracer.DEVICE_STR, cpu) | ||
77 | ftc = FTcat(BINS['ftcat'], stdout_f, stderr_f, dev, SchedTracer.EVENTS, cpu=cpu) | ||
78 | |||
79 | self.bins.append(ftc) | ||
80 | |||
81 | @staticmethod | ||
82 | def enabled(): | ||
83 | return litmus_util.is_device("%s%d" % (SchedTracer.DEVICE_STR, 0)) | ||
84 | |||
85 | |||
86 | class OverheadTracer(Tracer): | ||
87 | DEVICE_STR = '/dev/litmus/ft_trace0' | ||
88 | EVENTS = [# 'SCHED_START', 'SCHED_END', 'SCHED2_START', 'SCHED2_END', | ||
89 | 'RELEASE_START', 'RELEASE_END', | ||
90 | 'LVLA_RELEASE_START', 'LVLA_RELEASE_END', | ||
91 | 'LVLA_SCHED_START', 'LVLA_SCHED_END', | ||
92 | 'LVLB_RELEASE_START', 'LVLB_RELEASE_END', | ||
93 | 'LVLB_SCHED_START', 'LVLB_SCHED_END', | ||
94 | 'LVLC_RELEASE_START', 'LVLC_RELEASE_END', | ||
95 | 'LVLC_SCHED_START', 'LVLC_SCHED_END'] | ||
96 | |||
97 | def __init__(self, output_dir): | ||
98 | super(OverheadTracer, self).__init__("Overhead Trace", output_dir) | ||
99 | |||
100 | stdout_f = open('{0}/{1}'.format(self.output_dir, FILES['ft_data']), 'w') | ||
101 | stderr_f = open('{0}/{1}.stderr.txt'.format(self.output_dir, FILES['ft_data']), 'w') | ||
102 | ftc = FTcat(BINS['ftcat'], stdout_f, stderr_f, | ||
103 | OverheadTracer.DEVICE_STR, OverheadTracer.EVENTS) | ||
104 | |||
105 | self.bins.append(ftc) | ||
106 | |||
107 | @staticmethod | ||
108 | def enabled(): | ||
109 | return litmus_util.is_device(OverheadTracer.DEVICE_STR) | ||
110 | |||
111 | |||
112 | class PerfTracer(Tracer): | ||
113 | def __init__(self, output_dir): | ||
114 | super(PerfTracer, self).__init__("CPU perf counters", output_dir) | ||
115 | |||
116 | @staticmethod | ||
117 | def enabled(): | ||
118 | return False | ||