Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: tools/stats-viewer.py

Issue 2838028: tools/stats-viewer.py: add counter filter. (Closed)
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/stats-viewer.py
diff --git a/tools/stats-viewer.py b/tools/stats-viewer.py
index 14b214768f3f384f020112beacdd7e0bbcb00d68..05cb76288282492ce31da264c9026f32f76acffe 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 <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))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698