diff --git a/development.ini b/development.ini --- a/development.ini +++ b/development.ini @@ -45,16 +45,16 @@ cache_dir = %(here)s/data keys = root, routes, pylons_app, sqlalchemy [handlers] -keys = console +keys = console,chainsaw [formatters] -keys = generic +keys = generic,xmllayout ############# ## LOGGERS ## ############# [logger_root] -level = INFO +level = NOTSET handlers = console [logger_routes] @@ -84,6 +84,12 @@ args = (sys.stderr,) level = NOTSET formatter = generic +[handler_chainsaw] +class = xmllayout.RawSocketHandler +args = ('localhost', 4448) +level = NOTSET +formatter = xmllayout + ################ ## FORMATTERS ## ################ @@ -92,3 +98,6 @@ formatter = generic format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s datefmt = %H:%M:%S +[formatter_xmllayout] +class = xmllayout.XMLLayout + diff --git a/hgwebdir.config b/hgwebdir.config --- a/hgwebdir.config +++ b/hgwebdir.config @@ -8,7 +8,7 @@ hgext.highlight= [web] push_ssl = false -contact = marcin.kuzminski@etelko.pl +contact = develop@etelko.pl allow_archive = gz zip bz2 allow_push = * style = gitweb diff --git a/pylons_app/lib/profiler.py b/pylons_app/lib/profiler.py new file mode 100644 --- /dev/null +++ b/pylons_app/lib/profiler.py @@ -0,0 +1,53 @@ +from __future__ import with_statement + +import cProfile +import pstats +import cgi +import pprint +import threading + +from StringIO import StringIO + +class ProfilingMiddleware(object): + def __init__(self, app): + self.lock = threading.Lock() + self.app = app + + + def __call__(self, environ, start_response): + with self.lock: + profiler = cProfile.Profile() + def run_app(*a, **kw): + self.response = self.app(environ, start_response) + + profiler.runcall(run_app, environ, start_response) + + profiler.snapshot_stats() + + stats = pstats.Stats(profiler) + stats.sort_stats('cumulative') + + # Redirect output + out = StringIO() + stats.stream = out + + stats.print_stats() + + resp = ''.join(self.response) + + # Lets at least only put this on html-like responses. + if resp.strip().startswith('<'): + ## The profiling info is just appended to the response. + ## Browsers don't mind this. + resp += '
'
+                resp += cgi.escape(out.getvalue(), True)
+                
+                output = StringIO()
+                pprint.pprint(environ, output, depth=3)
+                
+                resp += cgi.escape(output.getvalue(), True)
+                resp += '
' + + return resp + +