diff options
Diffstat (limited to 'unit_trace')
| -rw-r--r-- | unit_trace/trace_reader.py | 32 | ||||
| -rw-r--r-- | unit_trace/warning_printer.py | 26 |
2 files changed, 43 insertions, 15 deletions
diff --git a/unit_trace/trace_reader.py b/unit_trace/trace_reader.py index a4c3c05..db36c13 100644 --- a/unit_trace/trace_reader.py +++ b/unit_trace/trace_reader.py | |||
| @@ -34,7 +34,7 @@ import sys | |||
| 34 | ############################################################################### | 34 | ############################################################################### |
| 35 | 35 | ||
| 36 | # Generator function returning an iterable over records in a trace file. | 36 | # Generator function returning an iterable over records in a trace file. |
| 37 | def trace_reader(files): | 37 | def trace_reader(files, buffsize): |
| 38 | 38 | ||
| 39 | # Yield a record containing the input files | 39 | # Yield a record containing the input files |
| 40 | # This is used by progress.py to calculate progress | 40 | # This is used by progress.py to calculate progress |
| @@ -66,17 +66,15 @@ def trace_reader(files): | |||
| 66 | # Forget that file iter | 66 | # Forget that file iter |
| 67 | file_iters.pop() | 67 | file_iters.pop() |
| 68 | 68 | ||
| 69 | # We keep 200 records in each buffer and then keep the buffer sorted | 69 | # We keep some number of records (given as buffsize) in each buffer and |
| 70 | # This is because records may have been recorded slightly out of order | 70 | # then keep the buffer sorted. This is because records may have been |
| 71 | # This cannot guarantee records are produced in order, but it makes it | 71 | # recorded slightly out of order. The 'try' and 'except' catches the case |
| 72 | # overwhelmingly probably. | 72 | # where there are less than buffsize records in a file (throwing a |
| 73 | # The 'try' and 'except' catches the case where there are less than 200 | 73 | # StopIteration) which otherwise would propogate up and cause the |
| 74 | # records in a file (throwing a StopIteration) which otherwise would | 74 | # trace_reader generator itself to throw a StopIteration. |
| 75 | # propogate up and cause the trace_reader generator itself to throw a | ||
| 76 | # StopIteration. | ||
| 77 | for x in range(0,len(file_iter_buff)): | 75 | for x in range(0,len(file_iter_buff)): |
| 78 | try: | 76 | try: |
| 79 | for y in range(0,200): | 77 | for y in range(0,buffsize): |
| 80 | file_iter_buff[x].append(file_iters[x].next()) | 78 | file_iter_buff[x].append(file_iters[x].next()) |
| 81 | except StopIteration: | 79 | except StopIteration: |
| 82 | pass | 80 | pass |
| @@ -119,16 +117,20 @@ def trace_reader(files): | |||
| 119 | del file_iter_buff[buff_to_refill] | 117 | del file_iter_buff[buff_to_refill] |
| 120 | del file_iters[buff_to_refill] | 118 | del file_iters[buff_to_refill] |
| 121 | 119 | ||
| 120 | # Give the record an id number | ||
| 121 | id += 1 | ||
| 122 | earliest.id = id | ||
| 123 | |||
| 122 | # Check for monotonically increasing time | 124 | # Check for monotonically increasing time |
| 123 | if last_time is not None and earliest.when < last_time: | 125 | if last_time is not None and earliest.when < last_time: |
| 124 | exit("FATAL ERROR: trace_reader.py: out-of-order record produced") | 126 | record = Obj() |
| 127 | record.record_type = "meta" | ||
| 128 | record.type_name = "out_of_order_warning" | ||
| 129 | record.id = earliest.id | ||
| 130 | yield record | ||
| 125 | else: | 131 | else: |
| 126 | last_time = earliest.when | 132 | last_time = earliest.when |
| 127 | 133 | ||
| 128 | # Give the record an id number | ||
| 129 | id += 1 | ||
| 130 | earliest.id = id | ||
| 131 | |||
| 132 | # Yield the record | 134 | # Yield the record |
| 133 | yield earliest | 135 | yield earliest |
| 134 | 136 | ||
diff --git a/unit_trace/warning_printer.py b/unit_trace/warning_printer.py new file mode 100644 index 0000000..0f726ff --- /dev/null +++ b/unit_trace/warning_printer.py | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | ############################################################################### | ||
| 2 | # Description | ||
| 3 | ############################################################################### | ||
| 4 | |||
| 5 | # Display any warnings | ||
| 6 | |||
| 7 | ############################################################################### | ||
| 8 | # Imports | ||
| 9 | ############################################################################### | ||
| 10 | |||
| 11 | import sys | ||
| 12 | |||
| 13 | ############################################################################### | ||
| 14 | # Public functions | ||
| 15 | ############################################################################### | ||
| 16 | |||
| 17 | def warning_printer(stream): | ||
| 18 | out_of_order_ids = [] | ||
| 19 | for record in stream: | ||
| 20 | if (record.record_type == "meta" and | ||
| 21 | record.type_name == "out_of_order_warning"): | ||
| 22 | out_of_order_ids.append(record.id) | ||
| 23 | if len(out_of_order_ids) > 0: | ||
| 24 | sys.stderr.write( | ||
| 25 | "WARNING: The following {0} records were out of order:\n{1}\n".format( | ||
| 26 | len(out_of_order_ids), out_of_order_ids)) | ||
