summaryrefslogtreecommitdiffstats
path: root/unit-trace
blob: fd7b4309e47dfcb14c875aaeef015ce1cd38cfdd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python

################################################################################
# Description
################################################################################
# Control script for unit-trace

################################################################################
# Setup
################################################################################

# Get trace files from command line arguments
from optparse import OptionParser
usage = "usage: %prog [options] <one or more trace files>"
parser = OptionParser(usage=usage)
parser.add_option("-s", "--skip", dest="skipnum", default=0, type=int,
    help="Skip over a fixed number of records")
parser.add_option("-m", "--max", dest="maxnum", default=0, type=int,
    help="Maximum number of records to parse")
parser.add_option("-p", "--progress", action="store_true", dest="progress",
    default=False, help="Show parsing progress")
parser.add_option("-g", "--gedf", action="store_true", dest="gedf",
    default=False, help="Run G-EDF test")
parser.add_option("-i", "--info", dest="num_inversions", default=-1, type=int,
    help="Print the n longest inversions, plus statistical info")
parser.add_option("-o", "--stdout", action="store_true", dest="stdout",
    default=False, help="Use stdout_printer")
parser.add_option("-v", "--visual", action="store_true", dest="visualize",
    default=False, help="Use visualizer")
parser.add_option("-t", "--time-per-maj", default='10ms', type=str,
    dest="time_per_maj", help="Time interval between major ticks, in the visualizer")
parser.add_option("-c", "--clean", action="store_true", dest="clean",
    default=False, help="Use sanitizer to clean garbage records")
parser.add_option("-e", "--earliest", default=0, type=int, dest="earliest",
    help="Earliest timestamp of interest")
parser.add_option("-l", "--latest", default=0, type=int, dest="latest",
    help="Latest timestamp of interest")
(options, traces) = parser.parse_args()
traces = list(traces)
if len(traces) < 1:
    parser.print_help()
    exit()

################################################################################
# Pipeline
################################################################################

# Import the unit_trace module
import unit_trace

# Read events from traces
from unit_trace import trace_reader
stream = trace_reader.trace_reader(traces)

# Skip over records
if options.skipnum > 0:
    from unit_trace import skipper
    stream = skipper.skipper(stream, options.skipnum)

# Enforce max number of records to parse
if options.maxnum > 0:
    from unit_trace import maxer
    stream = maxer.maxer(stream, options.maxnum)

# Enfore earliest timestamp
if options.earliest > 0:
    from unit_trace import earliest
    stream = earliest.earliest(stream,options.earliest)

# Enfore latest timestamp
if options.latest > 0:
    from unit_trace import latest
    stream = latest.latest(stream,options.latest)

# Filter out garbage events
if options.clean is True:
    from unit_trace import sanitizer
    stream = sanitizer.sanitizer(stream)

# Display progress information using stderr
# e.g. # records completed so far, total time, etc.
if options.progress is True:
    from unit_trace import progress
    stream = progress.progress(stream)

# Produce G-EDF error records
if options.gedf is True:
    from unit_trace import gedf_test
    stream = gedf_test.gedf_test(stream)

# Filter some records out
#def my_filter(record):
#    if record.record_type == 'error' and record.type_name == 'inversion_end':
#        if record.job.inversion_end - record.job.inversion_start < 4000000:
#            return False
#    return True
#stream = filter(my_filter, stream)

# Tee by the number of possible outputs
# This might cause a performance bottleneck that could be eliminated by
# checking how many we actually need :-)
import itertools
stream1, stream2, stream3 = itertools.tee(stream,3)

# Call standard out printer
if options.stdout is True:
    from unit_trace import stdout_printer
    stdout_printer.stdout_printer(stream1)

# Print G_EDF inversion statistics
if options.num_inversions > -1:
    if options.gedf is not True:
        import sys
        sys.stderr.write("You must enable the G-EDF test module to print" +
            " G-EDF inversion statistics\n")
    else:
        from unit_trace import gedf_inversion_stat_printer
        gedf_inversion_stat_printer.gedf_inversion_stat_printer(stream2,options.num_inversions)

# Call visualizer
if options.visualize is True:
    from unit_trace import viz
    try:
        nsec_time_per_maj = viz.util.parse_time(options.time_per_maj)
        viz.visualizer.visualizer(stream3, nsec_time_per_maj)
    except ValueError:
        import sys
        sys.stderr.write("Time expression should be of the form [TIME] [UNIT]")