diff options
| author | Mac Mollison <mollison@cs.unc.edu> | 2010-03-14 04:20:38 -0400 |
|---|---|---|
| committer | Mac Mollison <mollison@cs.unc.edu> | 2010-03-14 04:20:38 -0400 |
| commit | c8210c3cef340e8280658e847cc70958be77eb26 (patch) | |
| tree | 32d851453fc02677ea3437c69f9c6ce373cd45e8 | |
| parent | 361d978921690a7c26a63b933b502d5d2fc3e3d5 (diff) | |
Add support for intervals
Can now filter by earliest record of interest and
latest record of interest, using -e and -l.
| -rwxr-xr-x | unit-trace.py | 14 | ||||
| -rw-r--r-- | unit_trace/earliest.py | 21 | ||||
| -rw-r--r-- | unit_trace/latest.py | 19 |
3 files changed, 54 insertions, 0 deletions
diff --git a/unit-trace.py b/unit-trace.py index 5d772e8..93ab169 100755 --- a/unit-trace.py +++ b/unit-trace.py | |||
| @@ -21,6 +21,8 @@ from unit_trace import visualizer | |||
| 21 | from unit_trace import progress | 21 | from unit_trace import progress |
| 22 | from unit_trace import skipper | 22 | from unit_trace import skipper |
| 23 | from unit_trace import maxer | 23 | from unit_trace import maxer |
| 24 | from unit_trace import earliest | ||
| 25 | from unit_trace import latest | ||
| 24 | 26 | ||
| 25 | # Get trace files from command line arguments | 27 | # Get trace files from command line arguments |
| 26 | from optparse import OptionParser | 28 | from optparse import OptionParser |
| @@ -42,6 +44,10 @@ parser.add_option("-v", "--visual", action="store_true", dest="visualize", | |||
| 42 | default=False, help="Use visualizer") | 44 | default=False, help="Use visualizer") |
| 43 | parser.add_option("-c", "--clean", action="store_true", dest="clean", | 45 | parser.add_option("-c", "--clean", action="store_true", dest="clean", |
| 44 | default=False, help="Use sanitizer to clean garbage records") | 46 | default=False, help="Use sanitizer to clean garbage records") |
| 47 | parser.add_option("-e", "--earliest", default=0, type=int, dest="earliest", | ||
| 48 | help="Earliest timestamp of interst") | ||
| 49 | parser.add_option("-l", "--latest", default=0, type=int, dest="latest", | ||
| 50 | help="Latest timestamp of interst") | ||
| 45 | (options, traces) = parser.parse_args() | 51 | (options, traces) = parser.parse_args() |
| 46 | traces = list(traces) | 52 | traces = list(traces) |
| 47 | if len(traces) < 1: | 53 | if len(traces) < 1: |
| @@ -63,6 +69,14 @@ if options.skipnum > 0: | |||
| 63 | if options.maxnum > 0: | 69 | if options.maxnum > 0: |
| 64 | stream = maxer.maxer(stream, options.maxnum) | 70 | stream = maxer.maxer(stream, options.maxnum) |
| 65 | 71 | ||
| 72 | # Enfore earliest timestamp | ||
| 73 | if options.earliest > 0: | ||
| 74 | stream = earliest.earliest(stream,options.earliest) | ||
| 75 | |||
| 76 | # Enfore latest timestamp | ||
| 77 | if options.latest > 0: | ||
| 78 | stream = latest.latest(stream,options.latest) | ||
| 79 | |||
| 66 | # Filter out garbage events | 80 | # Filter out garbage events |
| 67 | if options.clean is True: | 81 | if options.clean is True: |
| 68 | stream = sanitizer.sanitizer(stream) | 82 | stream = sanitizer.sanitizer(stream) |
diff --git a/unit_trace/earliest.py b/unit_trace/earliest.py new file mode 100644 index 0000000..eaf0cf8 --- /dev/null +++ b/unit_trace/earliest.py | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | ############################################################################### | ||
| 2 | # Description | ||
| 3 | ############################################################################### | ||
| 4 | |||
| 5 | # Enforce earliest record | ||
| 6 | |||
| 7 | ############################################################################### | ||
| 8 | # Public functions | ||
| 9 | ############################################################################### | ||
| 10 | |||
| 11 | def earliest(stream, earliest): | ||
| 12 | for record in stream: | ||
| 13 | if record.record_type=="event": | ||
| 14 | if record.when < earliest: | ||
| 15 | pass | ||
| 16 | else: | ||
| 17 | yield record | ||
| 18 | break | ||
| 19 | yield record | ||
| 20 | for record in stream: | ||
| 21 | yield record | ||
diff --git a/unit_trace/latest.py b/unit_trace/latest.py new file mode 100644 index 0000000..4abd3a2 --- /dev/null +++ b/unit_trace/latest.py | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | ############################################################################### | ||
| 2 | # Description | ||
| 3 | ############################################################################### | ||
| 4 | |||
| 5 | # Enforce latest record | ||
| 6 | |||
| 7 | ############################################################################### | ||
| 8 | # Public functions | ||
| 9 | ############################################################################### | ||
| 10 | |||
| 11 | def latest(stream, latest): | ||
| 12 | for record in stream: | ||
| 13 | if record.record_type=="event": | ||
| 14 | if record.when > latest: | ||
| 15 | break | ||
| 16 | else: | ||
| 17 | yield record | ||
| 18 | else: | ||
| 19 | yield record | ||
