Commit 5575ff18 authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

tools/stats-viewer.py: add counter filter.

Review URL: http://codereview.chromium.org/2838028

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4975 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 65018d91
......@@ -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 <stats data>|<test_shell pid>"
parser = optparse.OptionParser("usage: %prog [--filter=re] "
"<stats data>|<test_shell pid>")
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))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment