diff options
author | Mac Mollison <mollison@cs.unc.edu> | 2009-02-01 21:55:18 -0500 |
---|---|---|
committer | Mac Mollison <mollison@cs.unc.edu> | 2009-02-01 21:55:18 -0500 |
commit | 0c95b7332d08cbf45f25fae04bb5595489ba6dec (patch) | |
tree | 7b2f1665c317033aed6114de458a968af81cc1c6 | |
parent | 00301e7f56ae8baad48155c22ff294666576fedf (diff) |
Added more complicated filter mechanism, added run.py which demonstrates the current abilities of STA, and added list.py, which is used by run.py. Updated DEV_NOTES.
-rw-r--r-- | DEV_NOTES | 10 | ||||
-rw-r--r-- | list.py | 14 | ||||
-rwxr-xr-x | run.py | 12 | ||||
-rwxr-xr-x | sta.py | 30 |
4 files changed, 60 insertions, 6 deletions
@@ -4,13 +4,15 @@ File Summary: | |||
4 | -sta.py : business logic | 4 | -sta.py : business logic |
5 | -sta_types.py : specifies binary format of sched trace data | 5 | -sta_types.py : specifies binary format of sched trace data |
6 | -sta_output.py : output formatting function(s) | 6 | -sta_output.py : output formatting function(s) |
7 | -run.py : gives an example of how to use sta.py | ||
8 | -list.py : list of trace files. (you would have to change this file to be | ||
9 | point to trace files on the local machine.) | ||
7 | 10 | ||
11 | To test: | ||
12 | 1) Modify list.py to point to trace files on your local machine | ||
13 | 2) execute run.py (e.g. run.py > out) | ||
8 | 14 | ||
9 | Likely next steps: | 15 | Likely next steps: |
10 | - Try to get StParamData working | 16 | - Try to get StParamData working |
11 | - Define convenience comparisons for ordering by earliest time for sort, | ||
12 | - and lambdas for filtering by job or PID or CPU or whatever | ||
13 | - and change read_trace to possibly take multiple traces. | ||
14 | - and /maybe/ allow for saving /loading previously saved traces. | ||
15 | 17 | ||
16 | 18 | ||
@@ -0,0 +1,14 @@ | |||
1 | full_list = [ | ||
2 | '/home/mollison/sta-alt/traces/st-g6-0.bin', | ||
3 | '/home/mollison/sta-alt/traces/st-g6-1.bin', | ||
4 | '/home/mollison/sta-alt/traces/st-g6-2.bin', | ||
5 | '/home/mollison/sta-alt/traces/st-g6-3.bin', | ||
6 | '/home/mollison/sta-alt/traces/st-x19-0.bin', | ||
7 | '/home/mollison/sta-alt/traces/st-x19-1.bin', | ||
8 | '/home/mollison/sta-alt/traces/st-x19-2.bin', | ||
9 | '/home/mollison/sta-alt/traces/st-x19-3.bin', | ||
10 | '/home/mollison/sta-alt/traces/st0.fg', | ||
11 | '/home/mollison/sta-alt/traces/st1.fg'] | ||
12 | |||
13 | list = [ | ||
14 | '/home/mollison/sta-alt/traces/st0.fg'] | ||
@@ -0,0 +1,12 @@ | |||
1 | #!/usr/bin/python3 | ||
2 | |||
3 | import sta | ||
4 | import list | ||
5 | trace = sta.Trace(list.list) | ||
6 | #trace.filter("exec_time>8828") | ||
7 | #trace.filter("job==12") | ||
8 | #trace.filter("when>2000000000") | ||
9 | #trace.filter("when<2500000000") | ||
10 | trace.filter("forced?==True") | ||
11 | for record in trace.iter: | ||
12 | sta.print_record_verbose(record) | ||
@@ -14,9 +14,14 @@ from sta_types import * | |||
14 | # Business logic # | 14 | # Business logic # |
15 | ################## | 15 | ################## |
16 | class Trace: | 16 | class Trace: |
17 | """Object representing a trace (i.e. set of records)""" | ||
18 | |||
17 | def __init__(self,files): | 19 | def __init__(self,files): |
20 | """Initialize the Trace object with an iterator""" | ||
18 | self.iter = self.make_iter(files) | 21 | self.iter = self.make_iter(files) |
22 | |||
19 | def make_iter(self, files): | 23 | def make_iter(self, files): |
24 | """Make the iterator for this Trace object""" | ||
20 | for file in files: | 25 | for file in files: |
21 | f = open(file,'rb') | 26 | f = open(file,'rb') |
22 | while True: | 27 | while True: |
@@ -32,6 +37,27 @@ class Trace: | |||
32 | f.close() | 37 | f.close() |
33 | break | 38 | break |
34 | def filter(self, criteria): | 39 | def filter(self, criteria): |
35 | func = eval("lambda x: " + criteria) | 40 | """Apply a filter to the trace""" |
36 | self.iter = filter(func, self.iter) | ||
37 | 41 | ||
42 | #Determine if they want to filter by >, <, or == | ||
43 | comp = None | ||
44 | seps = ['>','<','=='] | ||
45 | for sep in seps: | ||
46 | if criteria.find(sep) > 0: | ||
47 | comp = sep | ||
48 | if not comp: | ||
49 | print("Your filter is invalid: " + criteria) | ||
50 | exit() | ||
51 | |||
52 | #Apply the filter | ||
53 | field, comp, value = criteria.partition(comp) | ||
54 | test = "rec['" + field + "']" + comp + "int(" + value + ")" | ||
55 | def func(rec): | ||
56 | try: | ||
57 | if eval(test): | ||
58 | return True | ||
59 | else: | ||
60 | return False | ||
61 | except KeyError: | ||
62 | return False | ||
63 | self.iter = filter(func, self.iter) | ||