changeset 2249:d48a4d0a0c70

pycallgraph support
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 24 Jun 2007 22:36:14 +0200
parents 0131f0aabb18
children 07fdbda38be2
files MoinMoin/server/STANDALONE.py moin.py
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/server/STANDALONE.py	Fri Jun 22 14:05:40 2007 +0200
+++ b/MoinMoin/server/STANDALONE.py	Sun Jun 24 22:36:14 2007 +0200
@@ -485,8 +485,17 @@
 
 def quit(signo, stackframe):
     """ Signal handler for aborting signals """
-    global httpd
+    global httpd, config
     logging.info("Thanks for using MoinMoin!")
+
+    fname = config.pycallgraph_output
+    if fname:
+         import pycallgraph
+         if fname.endswith('.png'):
+             pycallgraph.make_dot_graph(fname)
+         elif fname.endswith('.dot'):
+             pycallgraph.save_dot(fname)
+         
     if httpd:
         httpd.die()
 
@@ -550,7 +559,7 @@
     # Development options
     memoryProfile = None
     hotshotProfile = None
-
+    pycallgraph_output = None
 
 def run(configClass):
     """ Create and run a moin server
@@ -580,6 +589,20 @@
         MoinRequestHandler.serve_moin = memoryProfileDecorator(
             MoinRequestHandler.serve_moin, config.memoryProfile)
 
+    # initialize pycallgraph, if wanted
+    if config.pycallgraph_output:
+        try:
+            import pycallgraph
+            pycallgraph.settings['include_stdlib'] = False
+            pcg_filter = pycallgraph.GlobbingFilter(exclude=['pycallgraph.*',
+                                                             'unknown.*',
+                                                    ],
+                                                    max_depth=9999)
+            pycallgraph.start_trace(reset=True, filter_func=pcg_filter)
+        except ImportError:
+            config.pycallgraph_output = None
+
+
     registerSignalHandlers(quit)
     httpd = makeServer(config)
 
--- a/moin.py	Fri Jun 22 14:05:40 2007 +0200
+++ b/moin.py	Sun Jun 24 22:36:14 2007 +0200
@@ -127,6 +127,11 @@
     # Not compatible with threads - use with SimpleServer only.
     ## hotshotProfile = name + '.prof'
 
+    # Using pycallgraph to make nice graphics of how moin works internally
+    # hint: using zgrviewer to view .dot is much more effective than using
+    #       some .png viewer
+    ##pycallgraph_output = 'moin-pycallgraph.dot' # can be either .dot or .png
+    ##serverClass = 'SimpleServer' # pycallgraph doesn't support multithreading
 
 try:
     from wikiserverconfig import Config