forked from lttng/lttng-analyses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_sched_switch.py
executable file
·127 lines (100 loc) · 4.34 KB
/
write_sched_switch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
import sys
import tempfile
try:
from babeltrace import CTFWriter, CTFStringEncoding
except ImportError:
# quick fix for debian-based distros
sys.path.append("/usr/local/lib/python%d.%d/site-packages" %
(sys.version_info.major, sys.version_info.minor))
from babeltrace import CTFWriter, CTFStringEncoding
trace_path = tempfile.mkdtemp()
print("Writing trace at {}".format(trace_path))
writer = CTFWriter.Writer(trace_path)
clock = CTFWriter.Clock("A_clock")
clock.description = "Simple clock"
writer.add_clock(clock)
writer.add_environment_field("Python_version", str(sys.version_info))
stream_class = CTFWriter.StreamClass("test_stream")
stream_class.clock = clock
char8_type = CTFWriter.IntegerFieldDeclaration(8)
char8_type.signed = True
char8_type.encoding = CTFStringEncoding.UTF8
char8_type.alignment = 8
int32_type = CTFWriter.IntegerFieldDeclaration(32)
int32_type.signed = True
int32_type.alignment = 8
uint32_type = CTFWriter.IntegerFieldDeclaration(32)
uint32_type.signed = False
uint32_type.alignment = 8
int64_type = CTFWriter.IntegerFieldDeclaration(64)
int64_type.signed = True
int64_type.alignment = 8
array_type = CTFWriter.ArrayFieldDeclaration(char8_type, 16)
sched_switch = CTFWriter.EventClass("sched_switch")
sched_switch.add_field(array_type, "_prev_comm")
sched_switch.add_field(int32_type, "_prev_tid")
sched_switch.add_field(int32_type, "_prev_prio")
sched_switch.add_field(int64_type, "_prev_state")
sched_switch.add_field(array_type, "_next_comm")
sched_switch.add_field(int32_type, "_next_tid")
sched_switch.add_field(int32_type, "_next_prio")
sched_switch.add_field(uint32_type, "_cpu_id")
stream_class.add_event_class(sched_switch)
stream = writer.create_stream(stream_class)
def set_char_array(event, string):
if len(string) > 16:
string = string[0:16]
else:
string = "%s" % (string + "\0" * (16 - len(string)))
for i in range(len(string)):
a = event.field(i)
a.value = ord(string[i])
def set_int(event, value):
event.value = value
def write_sched_switch(time_ms, cpu_id, prev_comm, prev_tid, next_comm,
next_tid, prev_prio=20, prev_state=1,
next_prio=20):
event = CTFWriter.Event(sched_switch)
clock.time = time_ms * 1000000
set_char_array(event.payload("_prev_comm"), prev_comm)
set_int(event.payload("_prev_tid"), prev_tid)
set_int(event.payload("_prev_prio"), prev_prio)
set_int(event.payload("_prev_state"), prev_state)
set_char_array(event.payload("_next_comm"), next_comm)
set_int(event.payload("_next_tid"), next_tid)
set_int(event.payload("_next_prio"), next_prio)
set_int(event.payload("_cpu_id"), cpu_id)
stream.append_event(event)
stream.flush()
def sched_switch_50pc(start_time_ms, end_time_ms, cpu_id, period,
comm1, tid1, comm2, tid2):
current = start_time_ms
while current < end_time_ms:
write_sched_switch(current, cpu_id, comm1, tid1, comm2, tid2)
current += period
write_sched_switch(current, cpu_id, comm2, tid2, comm1, tid1)
current += period
def sched_switch_rr(start_time_ms, end_time_ms, cpu_id, period, task_list):
current = start_time_ms
while current < end_time_ms:
current_task = task_list[len(task_list) - 1]
for i in task_list:
write_sched_switch(current, cpu_id, current_task[0],
current_task[1], i[0], i[1])
current_task = i
current += period
write_sched_switch(1393345613900, 5, "swapper/5", 0, "prog100pc-cpu5", 42)
sched_switch_50pc(1393345614000, 1393345615000, 0, 100,
"swapper/0", 0, "prog50pc-cpu0", 30664)
sched_switch_50pc(1393345615000, 1393345616000, 1, 100,
"swapper/1", 0, "prog50pc-cpu1", 30665)
sched_switch_50pc(1393345616000, 1393345617000, 2, 100,
"swapper/2", 0, "prog50pc-cpu2", 30666)
sched_switch_50pc(1393345617000, 1393345618000, 3, 100,
"swapper/3", 0, "prog50pc-cpu3", 30667)
sched_switch_50pc(1393345618000, 1393345619000, 0, 100,
"swapper/0", 0, "prog50pc-cpu0", 30664)
proc_list = [("prog1", 10), ("prog2", 11), ("prog3", 12), ("prog4", 13)]
sched_switch_rr(1393345619000, 1393345622000, 4, 100, proc_list)
write_sched_switch(1393345622300, 5, "prog100pc-cpu5", 42, "swapper/5", 0)