diff --git a/tools/stats-viewer.py b/tools/stats-viewer.py index 14b214768f..05cb762882 100755 --- a/tools/stats-viewer.py +++ b/tools/stats-viewer.py @@ -34,8 +34,8 @@ The stats viewer reads counters from a binary file and displays them in a window, re-reading and re-displaying with regular intervals. """ - import mmap +import optparse import os import re import struct @@ -60,13 +60,15 @@ CHROME_COUNTERS_FILE_MAGIC_NUMBER = 0x13131313 class StatsViewer(object): """The main class that keeps the data used by the stats viewer.""" - def __init__(self, data_name): + def __init__(self, data_name, name_filter): """Creates a new instance. Args: data_name: the name of the file containing the counters. + name_filter: The regexp filter to apply to counter names. """ self.data_name = data_name + self.name_filter = name_filter # The handle created by mmap.mmap to the counters file. We need # this to clean it up on exit. @@ -224,17 +226,19 @@ class StatsViewer(object): sorted_groups.sort() for counter_name in sorted_groups: counter_objs = groups[counter_name] - name = Tkinter.Label(self.root, width=50, anchor=Tkinter.W, - text=counter_name) - name.grid(row=index, column=0, padx=1, pady=1) + if self.name_filter.match(counter_name): + name = Tkinter.Label(self.root, width=50, anchor=Tkinter.W, + text=counter_name) + name.grid(row=index, column=0, padx=1, pady=1) count = len(counter_objs) for i in xrange(count): counter = counter_objs[i] name = counter.Name() var = Tkinter.StringVar() - value = Tkinter.Label(self.root, width=15, anchor=Tkinter.W, - textvariable=var) - value.grid(row=index, column=(1 + i), padx=1, pady=1) + if self.name_filter.match(name): + value = Tkinter.Label(self.root, width=15, anchor=Tkinter.W, + textvariable=var) + value.grid(row=index, column=(1 + i), padx=1, pady=1) # If we know how to interpret the prefix of this counter then # add an appropriate formatting to the variable @@ -440,17 +444,25 @@ class ChromeCounterCollection(object): self.counter_values_offset + i * self.max_threads * 4) -def Main(data_file): +def Main(data_file, name_filter): """Run the stats counter. Args: data_file: The counters file to monitor. + name_filter: The regexp filter to apply to counter names. """ - StatsViewer(data_file).Run() + StatsViewer(data_file, name_filter).Run() if __name__ == "__main__": - if len(sys.argv) != 2: - print "Usage: stats-viewer.py |" + parser = optparse.OptionParser("usage: %prog [--filter=re] " + "|") + parser.add_option("--filter", + default=".*", + help=("regexp filter for counter names " + "[default: %default]")) + (options, args) = parser.parse_args() + if len(args) != 1: + parser.print_help() sys.exit(1) - Main(sys.argv[1]) + Main(args[0], re.compile(options.filter))