changeset 837:7abe5a3e5e8c

thread_monitor can write dumps to data_dir, updated CHANGES (already done in 1.5 branch)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 15 Jun 2006 21:11:18 +0200
parents 538bf7495665
children 910ed4667859
files MoinMoin/action/thread_monitor.py docs/CHANGES
diffstat 2 files changed, 32 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/thread_monitor.py	Thu Jun 15 11:59:12 2006 +0200
+++ b/MoinMoin/action/thread_monitor.py	Thu Jun 15 21:11:18 2006 +0200
@@ -7,14 +7,30 @@
     @copyright: 2006 by MoinMoin:AlexanderSchremmer
     @license: GNU GPL, see COPYING for details.
 """
-
-from time import sleep
+import os, time
 from StringIO import StringIO
+ 
+from MoinMoin import wikiutil
+from MoinMoin.util import thread_monitor
+ 
+def execute_fs(pagename, request):
+    if thread_monitor.hook_enabled:
+        s = StringIO()
+        thread_monitor.trigger_dump(s)
+        time.sleep(5) # allow for all threads to dump to request
+        data = s.getvalue()
+        timestamp = time.time()
+        dump_fname = os.path.join(request.cfg.data_dir, "tm_%d.log" % timestamp)
+        f = file(dump_fname, "w")
+        f.write(data)
+        f.close()
+    else:
+        dump_fname = "nowhere"
 
-from MoinMoin.wikiutil import escape
-from MoinMoin.util import thread_monitor
+    request.http_headers()
+    request.write('<html><body>A dump has been saved to %s.</body></html>' % dump_fname)
 
-def execute(pagename, request):
+def execute_wiki(pagename, request):
     request.http_headers()
 
     request.theme.send_title("Thread monitor")
@@ -25,10 +41,12 @@
     else:
         s = StringIO()
         thread_monitor.trigger_dump(s)
-        sleep(5) # allow for all threads to dump to request
-        request.write(escape(s.getvalue()))
+        time.sleep(5) # allow for all threads to dump to request
+        request.write(wikiutil.escape(s.getvalue()))
         
     request.write('</pre>')
     request.theme.send_footer(pagename)
     request.theme.send_closing_html()
+  
+execute = execute_fs
 
--- a/docs/CHANGES	Thu Jun 15 11:59:12 2006 +0200
+++ b/docs/CHANGES	Thu Jun 15 21:11:18 2006 +0200
@@ -99,9 +99,14 @@
       types because the official ones suck)
     * renamed parsers to module names representing sane mimetypes, e.g.:
       parser.wiki -> parser.text_moin_wiki
-    * Added thread_monitor. It can be activated using:
+    * Added thread_monitor debugging aid. It can be activated using:
       from MoinMoin.util import thread_monitor; thread_monitor.activate_hook()
-      or by requesting URL ...?action=thread_monitor
+      and then triggered by requesting URL ...?action=thread_monitor - please
+      be aware that monitoring threads has a big performance impact on its own,
+      so you only want to temporarily enable this for debugging.
+      By default, it dumps its output to the data_dir as tm_<timestamp>.log,
+      you can change this at bottom of action/thread_monitor.py if you want to
+      see output in your browser.
     * Introduced scope parameter to CacheEntry() - if you specify 'farm', it
       will cache into a common directory for all wikis in the same farm, if you
       specify 'wiki', it will use a cache directory per wiki and if you specify