Revision: 4975
Author: [email protected]
Date: Tue Jun 29 04:30:34 2010
Log: tools/stats-viewer.py: add counter filter.

Review URL: http://codereview.chromium.org/2838028
http://code.google.com/p/v8/source/detail?r=4975

Modified:
 /branches/bleeding_edge/tools/stats-viewer.py

=======================================
--- /branches/bleeding_edge/tools/stats-viewer.py       Mon Dec 14 09:05:38 2009
+++ /branches/bleeding_edge/tools/stats-viewer.py       Tue Jun 29 04:30:34 2010
@@ -34,8 +34,8 @@
 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 @@
 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 @@
     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 @@
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))

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to