From 19dae75b53787717de3a1173f8e3506eb0c6ea4a Mon Sep 17 00:00:00 2001 From: Thijs Vermeir Date: Tue, 1 Jan 2008 17:10:32 +0000 Subject: [PATCH] tools/gst-plot-timeline.py: Add more options to gst-plot-timeline Original commit message from CVS: * tools/gst-plot-timeline.py: Add more options to gst-plot-timeline --- ChangeLog | 5 +++ tools/gst-plot-timeline.py | 62 +++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8494df7dcb..0e5d789fb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-01-01 Thijs Vermeir + + * tools/gst-plot-timeline.py: + Add more options to gst-plot-timeline + 2007-12-31 Wim Taymans * docs/design/part-synchronisation.txt: diff --git a/tools/gst-plot-timeline.py b/tools/gst-plot-timeline.py index 60ef829556..a1e17f2c92 100755 --- a/tools/gst-plot-timeline.py +++ b/tools/gst-plot-timeline.py @@ -35,6 +35,11 @@ mark_log_group = 3 success_result = "0" +skip_lines = 0 +max_lines = 500 +filter_regex = re.compile ('') +skip_regex = re.compile('') + class BaseMark: colors = 0, 0, 0 def __init__(self, timestamp, log): @@ -102,11 +107,31 @@ class SyscallParser: def parse_strace(filename): parser = SyscallParser () + global skip_lines + global max_lines + global skip_regex + + skip_found = False + for line in file(filename, "r").readlines(): if line == "": break - parser.add_line (line) + if not skip_found: + if skip_regex.search(line): + skip_found = True + else: + continue + + if skip_lines > 0: + skip_lines -= 1 + continue + + if len(parser.syscalls) >= max_lines: + break + + if filter_regex.search(line): + parser.add_line (line) return parser.syscalls @@ -127,10 +152,10 @@ def compute_syscall_metrics(syscalls): metrics.width = PLOT_WIDTH last_timestamp = syscalls[num_syscalls - 1].timestamp - num_seconds = int(math.ceil(last_timestamp)) - time_height = num_seconds * PIXELS_PER_SECOND + time_height = int(math.ceil(last_timestamp * PIXELS_PER_SECOND)) line_height = num_syscalls * PIXELS_PER_LINE + if time_height > line_height: metrics.height = time_height print "Adjusting PIXELS_PER_LINE = %d" % PIXELS_PER_LINE @@ -139,7 +164,7 @@ def compute_syscall_metrics(syscalls): else: metrics.height = line_height print "Adjusting PIXELS_PER_SECOND %d" % PIXELS_PER_SECOND - PIXELS_PER_SECOND = metrics.height / num_seconds + PIXELS_PER_SECOND = int(math.ceil(metrics.height / last_timestamp)) print " PIXELS_PER_SECOND %d" % PIXELS_PER_SECOND text_ypos = 0 @@ -216,12 +241,28 @@ def plot_syscalls_to_surface(syscalls, metrics): return surface def main(args): + + global skip_lines + global max_lines + global filter_regex + global skip_regex + option_parser = optparse.OptionParser( usage="usage: %prog -o output.png ") option_parser.add_option("-o", "--output", dest="output", metavar="FILE", help="Name of output file (output is a PNG file)") + option_parser.add_option("-s", + "--skip", dest="skip", + metavar="LINES", + help="Skip a number of loglines at the beginning of the file or wait till a regular expression happens") + option_parser.add_option("-m", + "--max-lines", dest="max", + help="max lines that need to be plotted") + option_parser.add_option("-f", + "--filter", dest="filter", + help="filter the log lines on a regular expression") options, args = option_parser.parse_args() @@ -236,6 +277,19 @@ def main(args): in_filename = args[0] out_filename = options.output + if options.skip: + try: + skip_lines = int(options.skip) + except: + skip_regex = re.compile(options.skip) + skip_lines = 0 + + if options.max: + max_lines = int(options.max) + + if options.filter: + filter_regex = re.compile(options.filter) + syscalls = [] for syscall in parse_strace(in_filename): syscalls.append(syscall)