summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMac Mollison <mollison@cs.unc.edu>2009-02-23 20:44:48 -0500
committerMac Mollison <mollison@cs.unc.edu>2009-02-23 20:44:48 -0500
commit06183c3957b7c25fdcafd802460aef28b9f11e61 (patch)
tree94975ec97b4d133a9956a710e10a0bf7ac94e0fc
parent7502cdd1b1bb8a74a22c16be255b4f5674b66e29 (diff)
Major update completed. Everything merged back into one file. Created
run.py as "launchpad" (see README).
-rwxr-xr-xrun.py79
-rwxr-xr-xsta.py138
2 files changed, 198 insertions, 19 deletions
diff --git a/run.py b/run.py
index c1eac09..b1710fe 100755
--- a/run.py
+++ b/run.py
@@ -1,12 +1,71 @@
1#!/usr/bin/python3 1#!/usr/bin/python3
2
3import sta 2import sta
4import list 3
5trace = sta.Trace(list.list) 4######################################
6#trace.filter("exec_time>8828") 5# Sched Trace Analyzer LaunchPad #
7#trace.filter("job==12") 6######################################
8#trace.filter("when>2000000000") 7
9#trace.filter("when<2500000000") 8def main():
10trace.filter("forced?==True") 9
11for record in trace.iter: 10 #trace = sta.Trace(short_list)
12 sta.print_record_verbose(record) 11 trace = sta.Trace(g6_list)
12
13 #trace.filter("exec_time>8828")
14 #trace.filter("job==12")
15 #trace.filter("when>2000000000")
16 #trace.filter("when<2500000000")
17 #trace.filter("forced?==True")
18
19 #trace.filter("type==1")
20 #trace.sort(lambda x: x['pid'] or 0)
21
22 for record in trace.iter:
23 sta.print_record_verbose(record)
24
25
26
27
28
29######################################
30# Put lists of your trace files here #
31######################################
32
33
34full_list = [
35'/home/mollison/sta-alt/traces/st-g6-0.bin',
36'/home/mollison/sta-alt/traces/st-g6-1.bin',
37'/home/mollison/sta-alt/traces/st-g6-2.bin',
38'/home/mollison/sta-alt/traces/st-g6-3.bin',
39'/home/mollison/sta-alt/traces/st-x19-0.bin',
40'/home/mollison/sta-alt/traces/st-x19-1.bin',
41'/home/mollison/sta-alt/traces/st-x19-2.bin',
42'/home/mollison/sta-alt/traces/st-x19-3.bin',
43'/home/mollison/sta-alt/traces/st0.fg',
44'/home/mollison/sta-alt/traces/st1.fg']
45
46short_list = [
47'/home/mollison/sta-alt/traces/st-x19-2.bin']
48
49g6_list = [
50'/home/mollison/sta-alt/traces/st-g6-0.bin',
51'/home/mollison/sta-alt/traces/st-g6-1.bin',
52'/home/mollison/sta-alt/traces/st-g6-2.bin',
53'/home/mollison/sta-alt/traces/st-g6-3.bin']
54
55x19_list = [
56'/home/mollison/sta-alt/traces/st-x19-0.bin',
57'/home/mollison/sta-alt/traces/st-x19-1.bin',
58'/home/mollison/sta-alt/traces/st-x19-2.bin',
59'/home/mollison/sta-alt/traces/st-x19-3.bin']
60
61simple_list = [
62'/home/mollison/sta-alt/traces/st0.fg',
63'/home/mollison/sta-alt/traces/st1.fg']
64
65
66##############
67# start main #
68##############
69
70if __name__=='__main__':
71 main()
diff --git a/sta.py b/sta.py
index 0354495..49cbd5d 100755
--- a/sta.py
+++ b/sta.py
@@ -6,12 +6,10 @@
6################## 6##################
7 7
8import sys 8import sys
9from sta_output import * 9import struct
10from sta_types import *
11
12 10
13################## 11##################
14# Business logic # 12# Trace class #
15################## 13##################
16class Trace: 14class Trace:
17 """Object representing a trace (i.e. set of records)""" 15 """Object representing a trace (i.e. set of records)"""
@@ -25,17 +23,24 @@ class Trace:
25 for file in files: 23 for file in files:
26 f = open(file,'rb') 24 f = open(file,'rb')
27 while True: 25 while True:
26 data = f.read(24)
27 try:
28 typenum = struct.unpack_from('b',data)[0]
29 except struct.error:
30 #We read to the end of the file
31 f.close()
32 break
33 type = get_type(typenum)
28 try: 34 try:
29 data = f.read(st_record_size)
30 typenum = struct.unpack_from('<b',data)[0]
31 type = get_type(typenum)
32 values = struct.unpack_from(StHeader.format + 35 values = struct.unpack_from(StHeader.format +
33 type.format,data) 36 type.format,data)
34 record = dict(zip(type.keys,values)) 37 record = dict(zip(type.keys,values))
35 yield record
36 except struct.error: 38 except struct.error:
37 f.close() 39 f.close()
38 break 40 print("Invalid record detected, stopping.")
41 exit()
42 yield record
43
39 def filter(self, criteria): 44 def filter(self, criteria):
40 """Apply a filter to the trace""" 45 """Apply a filter to the trace"""
41 46
@@ -61,3 +66,118 @@ class Trace:
61 except KeyError: 66 except KeyError:
62 return False 67 return False
63 self.iter = filter(func, self.iter) 68 self.iter = filter(func, self.iter)
69
70 def count(self):
71 """Return the number of records in the trace"""
72 return len(list(self.iter))
73
74 def sort(self, func):
75 """Return the records sorted by some key"""
76 self.iter = sorted(self.iter, key=func)
77
78
79####################################
80# Types for binary data conversion #
81####################################
82
83import struct
84
85class StHeader:
86 format = '<bbhi'
87 formatStr = struct.Struct(format)
88 keys = ['type','cpu','pid','job']
89 message = 'The header.'
90
91
92class StNameData:
93 format = '16s'
94 formatStr = struct.Struct(StHeader.format + format)
95 keys = StHeader.keys + ['name']
96 message = 'The name of the executable of this process.'
97
98# Untested because this never appears in my sample files
99# ACTUALLY: None in 0, none in 1, a bunch in 2, and none in 3
100class StParamData:
101 format = 'IIIc'
102 #format = 'ccccc'
103 formatStr = struct.Struct(StHeader.format + format)
104 keys = StHeader.keys + ['wcet','period','phase','partition']
105 message = 'Regular parameters.'
106
107
108class StReleaseData:
109 format = 'LL'
110 formatStr = struct.Struct(StHeader.format + format)
111 keys = StHeader.keys + ['release_time','deadline']
112 message = 'A job was/is going to be released.'
113
114
115class StAssignedData:
116 format = 'Lc'
117 formatStr = struct.Struct(StHeader.format + format)
118 keys = StHeader.keys + ['when','target']
119 message = 'A job was assigned to a CPU.'
120
121class StSwitchToData:
122 format = 'LI'
123 formatStr = struct.Struct(StHeader.format + format)
124 keys = StHeader.keys + ['when','exec_time']
125 message = 'A process was switched to on a given CPU.'
126
127
128class StSwitchAwayData:
129 format = 'LI'
130 formatStr = struct.Struct(StHeader.format + format)
131 keys = StHeader.keys + ['when','exec_time']
132 message = 'A process was away on a given CPU.'
133
134class StCompletionData:
135 format = 'L7x?c'
136 formatStr = struct.Struct(StHeader.format + format)
137 keys = StHeader.keys + ['when','forced?','flags']
138 message = 'A job completed.'
139
140
141class StBlockData:
142 format = 'L'
143 formatStr = struct.Struct(StHeader.format + format)
144 keys = StHeader.keys + ['when']
145 message = 'A task blocks.'
146
147
148class StResumeData:
149 format = 'L'
150 formatStr = struct.Struct(StHeader.format + format)
151 keys = StHeader.keys + ['when']
152 message = 'A task resumes.'
153
154
155class StSysReleaseData:
156 format = 'LL'
157 formatStr = struct.Struct(StHeader.format + format)
158 keys = StHeader.keys + ['when','release']
159 message = 'StSysReleaseData (no details).'
160
161def get_type(type_num):
162 """Return the binary data type, given the type_num"""
163 types = [None,StNameData,StParamData,StReleaseData,StAssignedData,
164 StSwitchToData,StSwitchAwayData,StCompletionData,StBlockData,
165 StResumeData,StSysReleaseData]
166 return types[type_num]
167
168
169####################################
170# Output formatting functions #
171####################################
172
173def print_record_verbose(record):
174 """Prints a record verbosely, given the record as a dict."""
175 print(50*'=')
176 print(get_type(record['type']).message)
177 for k,v in record.items():
178 print(k +":", v)
179
180def print_record_type(record):
181 """Prints the type of a record."""
182 print(record['type'])
183