paste
that
.com
Share code, files, images, and links.
Twitter
Delicious
Reddit
Yahoo!
Google
StumbleUpon
Digg
Furl
New
Profiling Middleware
Post Follow-up
Download
Login/Register
Recent Pastes
Post Follow-up
Text
File / Image
Link
Syntax:
(Automatic)
ActionScript
ActionScript 3
Bash
Brainfuck
C
C#
C++
CSS
Diff
Django/Jinja
ERB
Erlang
Genshi
Genshi Text
Gettext Catalog
HTML
INI
Java
JavaScript
Lua
Mako
Myghty
MySQL
Objective-C
Perl
PHP
Plaintext
Python
Python 3
Python console session
Python Traceback
Ruby
Ruby irb session
RHTML
Smarty
SQL
VB.net
XML
XSLT
Text:
import sys try: import cProfile as profile except ImportError: import profile try: from cStringIO import StringIO except ImportError: import StringIO from django.conf import settings class ProfilerMiddleware(object): def can(self, request): return settings.PROFILING and 'prof' in request.GET \ and (not settings.INTERNAL_IPS or \ request.META['REMOTE_ADDR'] in settings.INTERNAL_IPS) def process_view(self, request, callback, callback_args, callback_kwargs): if self.can(request): self.profiler = profile.Profile() args = (request,) + callback_args return self.profiler.runcall(callback, *args, **callback_kwargs) def process_response(self, request, response): if self.can(request): self.profiler.create_stats() out = StringIO() old_stdout, sys.stdout = sys.stdout, out self.profiler.print_stats(1) sys.stdout = old_stdout response.content = '<pre>%s</pre>' % out.getvalue() return response from django.db import connection class DatabaseProfilerMiddleware(object): def can(self, request): return settings.PROFILING and 'dbprof' in request.GET \ and (not settings.INTERNAL_IPS or \ request.META['REMOTE_ADDR'] in settings.INTERNAL_IPS) def process_request(self, request): if self.can(request): self.DEBUG = settings.DEBUG settings.DEBUG = True def process_response(self, request, response): if self.can(request): out = StringIO() out.write('time\tsql\n') total_time = 0 for query in reversed(sorted(connection.queries, key=lambda x: x['time'])): total_time += float(query['time'])*1000 out.write('%s\t%s\n' % (query['time'], query['sql'])) response.content = '<pre style="white-space:pre-wrap">%d queries executed in %.3f seconds\n\n%s</pre>' % (len(connection.queries), total_time/1000, out.getvalue()) settings.DEBUG = self.DEBUG return response
Title:
Slug:
http://www.pastethat.com/
You may specify the URL slug to use for your paste. Minimum 5 characters.
Allow others to browse and search for this paste.
File:
Slug:
http://www.pastethat.com/
You may specify the URL slug to use for your paste. Minimum 5 characters.
Allow others to browse and search for this paste.
URL:
Slug:
http://www.pastethat.com/
You may specify the URL slug to use for your paste. Minimum 5 characters.
Allow others to browse and search for this paste.