Changeset - c8265b4f0c2a
[Not reviewed]
default
0 2 1
Marcin Kuzminski - 16 years ago 2010-02-21 14:24:50

added log4j to development,
3 files changed with 66 insertions and 4 deletions:
0 comments (0 inline, 0 general)
development.ini
Show inline comments
 
@@ -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
 

	
hgwebdir.config
Show inline comments
 
@@ -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
pylons_app/lib/profiler.py
Show inline comments
 
new file 100644
 
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 += '<pre style="text-align:left; border-top: 4px dashed red; padding: 1em;">'
 
                resp += cgi.escape(out.getvalue(), True)
 
                
 
                output = StringIO()
 
                pprint.pprint(environ, output, depth=3)
 
                
 
                resp += cgi.escape(output.getvalue(), True)
 
                resp += '</pre>'
 
                
 
            return resp
 
    
 

	
0 comments (0 inline, 0 general)