diff options
| author | Mac Mollison <mollison@cs.unc.edu> | 2009-02-24 17:34:07 -0500 |
|---|---|---|
| committer | Mac Mollison <mollison@cs.unc.edu> | 2009-02-24 17:34:07 -0500 |
| commit | 9fc7d10c40f19aea990dba776dd571d982da04e9 (patch) | |
| tree | f9df03c76642d14d550a3593d2f06810e5a07f36 | |
| parent | 150cdb350f75dc86bd6be23c6eb37719dc61d3cf (diff) | |
Major update.
-Completed sort method
-Moved print functions into Trace object, resuling in much nicer
interface
-Created ability to count records by type
| -rwxr-xr-x | run.py | 18 | ||||
| -rwxr-xr-x | sta.py | 44 |
2 files changed, 30 insertions, 32 deletions
| @@ -7,23 +7,21 @@ import sta | |||
| 7 | 7 | ||
| 8 | def main(): | 8 | def main(): |
| 9 | 9 | ||
| 10 | #trace = sta.Trace(short_list) | 10 | # A sample trace |
| 11 | trace = sta.Trace(g6_list) | 11 | trace = sta.Trace(g6_list) |
| 12 | trace.filter("pid==4125") | ||
| 13 | trace.sort('job') | ||
| 14 | trace.print_count(True) | ||
| 15 | trace.print_records() | ||
| 12 | 16 | ||
| 17 | #Some other things you can do (old commands I've used) | ||
| 13 | #trace.filter("exec_time>8828") | 18 | #trace.filter("exec_time>8828") |
| 14 | #trace.filter("job==12") | 19 | #trace.filter("job==12") |
| 15 | #trace.filter("when>2000000000") | 20 | #trace.filter("when>2000000000") |
| 16 | #trace.filter("when<2500000000") | 21 | #trace.filter("when<2500000000") |
| 17 | #trace.filter("forced?==True") | 22 | #trace.filter("forced?==True") |
| 18 | 23 | #trace.filter("type==1") | |
| 19 | trace.filter("type==1") | 24 | #trace.filter("type!=3") |
| 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 | 25 | ||
| 28 | 26 | ||
| 29 | ###################################### | 27 | ###################################### |
| @@ -67,11 +67,6 @@ class Trace: | |||
| 67 | return False | 67 | return False |
| 68 | self.iter = filter(func, self.iter) | 68 | self.iter = filter(func, self.iter) |
| 69 | 69 | ||
| 70 | def count(self): | ||
| 71 | """Return the number of records in the trace""" | ||
| 72 | return len(list(self.iter)) | ||
| 73 | |||
| 74 | #Needs to be tested/finished | ||
| 75 | def sort(self, key): | 70 | def sort(self, key): |
| 76 | """Return the records sorted by some key""" | 71 | """Return the records sorted by some key""" |
| 77 | def sortfunc(record): | 72 | def sortfunc(record): |
| @@ -81,6 +76,27 @@ class Trace: | |||
| 81 | return 0 | 76 | return 0 |
| 82 | self.iter = sorted(self.iter, key=sortfunc) | 77 | self.iter = sorted(self.iter, key=sortfunc) |
| 83 | 78 | ||
| 79 | def print_records(self): | ||
| 80 | """Prints all records in the trace""" | ||
| 81 | for record in self.iter: | ||
| 82 | print(50*'=') | ||
| 83 | print(get_type(record['type']).message) | ||
| 84 | for k,v in record.items(): | ||
| 85 | print(k +":", v) | ||
| 86 | |||
| 87 | def print_count(self,verbose=False): | ||
| 88 | """Prints the number of records in the trace.""" | ||
| 89 | print("Total Count: " + str(len(self.iter))) | ||
| 90 | if verbose: | ||
| 91 | counts = {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0} | ||
| 92 | for record in self.iter: | ||
| 93 | type = record['type'] | ||
| 94 | counts[type] += 1 | ||
| 95 | for key in counts.keys(): | ||
| 96 | print(get_type(key).__name__ + | ||
| 97 | ': ' + str(counts[key])) | ||
| 98 | print("") | ||
| 99 | |||
| 84 | 100 | ||
| 85 | #################################### | 101 | #################################### |
| 86 | # Types for binary data conversion # | 102 | # Types for binary data conversion # |
| @@ -130,7 +146,7 @@ class StSwitchAwayData: | |||
| 130 | format = 'LI' | 146 | format = 'LI' |
| 131 | formatStr = struct.Struct(StHeader.format + format) | 147 | formatStr = struct.Struct(StHeader.format + format) |
| 132 | keys = StHeader.keys + ['when','exec_time'] | 148 | keys = StHeader.keys + ['when','exec_time'] |
| 133 | message = 'A process was away on a given CPU.' | 149 | message = 'A process was switched away on a given CPU.' |
| 134 | 150 | ||
| 135 | class StCompletionData: | 151 | class StCompletionData: |
| 136 | format = 'L7x?c' | 152 | format = 'L7x?c' |
| @@ -163,19 +179,3 @@ def get_type(type_num): | |||
| 163 | StResumeData,StSysReleaseData] | 179 | StResumeData,StSysReleaseData] |
| 164 | return types[type_num] | 180 | return types[type_num] |
| 165 | 181 | ||
| 166 | |||
| 167 | #################################### | ||
| 168 | # Output formatting functions # | ||
| 169 | #################################### | ||
| 170 | |||
| 171 | def print_record_verbose(record): | ||
| 172 | """Prints a record verbosely, given the record as a dict.""" | ||
| 173 | print(50*'=') | ||
| 174 | print(get_type(record['type']).message) | ||
| 175 | for k,v in record.items(): | ||
| 176 | print(k +":", v) | ||
| 177 | |||
| 178 | def print_record_type(record): | ||
| 179 | """Prints the type of a record.""" | ||
| 180 | print(record['type']) | ||
| 181 | |||
