Show More
@@ -0,0 +1,53 b'' | |||
|
1 | from __future__ import with_statement | |
|
2 | ||
|
3 | import cProfile | |
|
4 | import pstats | |
|
5 | import cgi | |
|
6 | import pprint | |
|
7 | import threading | |
|
8 | ||
|
9 | from StringIO import StringIO | |
|
10 | ||
|
11 | class ProfilingMiddleware(object): | |
|
12 | def __init__(self, app): | |
|
13 | self.lock = threading.Lock() | |
|
14 | self.app = app | |
|
15 | ||
|
16 | ||
|
17 | def __call__(self, environ, start_response): | |
|
18 | with self.lock: | |
|
19 | profiler = cProfile.Profile() | |
|
20 | def run_app(*a, **kw): | |
|
21 | self.response = self.app(environ, start_response) | |
|
22 | ||
|
23 | profiler.runcall(run_app, environ, start_response) | |
|
24 | ||
|
25 | profiler.snapshot_stats() | |
|
26 | ||
|
27 | stats = pstats.Stats(profiler) | |
|
28 | stats.sort_stats('cumulative') | |
|
29 | ||
|
30 | # Redirect output | |
|
31 | out = StringIO() | |
|
32 | stats.stream = out | |
|
33 | ||
|
34 | stats.print_stats() | |
|
35 | ||
|
36 | resp = ''.join(self.response) | |
|
37 | ||
|
38 | # Lets at least only put this on html-like responses. | |
|
39 | if resp.strip().startswith('<'): | |
|
40 | ## The profiling info is just appended to the response. | |
|
41 | ## Browsers don't mind this. | |
|
42 | resp += '<pre style="text-align:left; border-top: 4px dashed red; padding: 1em;">' | |
|
43 | resp += cgi.escape(out.getvalue(), True) | |
|
44 | ||
|
45 | output = StringIO() | |
|
46 | pprint.pprint(environ, output, depth=3) | |
|
47 | ||
|
48 | resp += cgi.escape(output.getvalue(), True) | |
|
49 | resp += '</pre>' | |
|
50 | ||
|
51 | return resp | |
|
52 | ||
|
53 |
@@ -1,94 +1,103 b'' | |||
|
1 | 1 | ################################################################################ |
|
2 | 2 | ################################################################################ |
|
3 | 3 | # pylons_app - Pylons environment configuration # |
|
4 | 4 | # # |
|
5 | 5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
6 | 6 | ################################################################################ |
|
7 | 7 | |
|
8 | 8 | [DEFAULT] |
|
9 | 9 | debug = true |
|
10 | 10 | ############################################ |
|
11 | 11 | ## Uncomment and replace with the address ## |
|
12 | 12 | ## which should receive any error reports ## |
|
13 | 13 | ############################################ |
|
14 | 14 | #email_to = marcin.kuzminski@etelko.pl |
|
15 | 15 | #smtp_server = mail.etelko.pl |
|
16 | 16 | #error_email_from = paste_error@localhost |
|
17 | 17 | #smtp_username = |
|
18 | 18 | #smtp_password = |
|
19 | 19 | #error_message = 'mercurial crash !' |
|
20 | 20 | |
|
21 | 21 | [server:main] |
|
22 | 22 | use = egg:Paste#http |
|
23 | 23 | host = 127.0.0.1 |
|
24 | 24 | port = 5000 |
|
25 | 25 | |
|
26 | 26 | [app:main] |
|
27 | 27 | use = egg:pylons_app |
|
28 | 28 | full_stack = true |
|
29 | 29 | static_files = true |
|
30 | 30 | lang=en |
|
31 | 31 | cache_dir = %(here)s/data |
|
32 | 32 | |
|
33 | 33 | ################################################################################ |
|
34 | 34 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
|
35 | 35 | ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ## |
|
36 | 36 | ## execute malicious code after an exception is raised. ## |
|
37 | 37 | ################################################################################ |
|
38 | 38 | #set debug = false |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | ################################ |
|
42 | 42 | ### LOGGING CONFIGURATION #### |
|
43 | 43 | ################################ |
|
44 | 44 | [loggers] |
|
45 | 45 | keys = root, routes, pylons_app, sqlalchemy |
|
46 | 46 | |
|
47 | 47 | [handlers] |
|
48 | keys = console | |
|
48 | keys = console,chainsaw | |
|
49 | 49 | |
|
50 | 50 | [formatters] |
|
51 | keys = generic | |
|
51 | keys = generic,xmllayout | |
|
52 | 52 | |
|
53 | 53 | ############# |
|
54 | 54 | ## LOGGERS ## |
|
55 | 55 | ############# |
|
56 | 56 | [logger_root] |
|
57 |
level = |
|
|
57 | level = NOTSET | |
|
58 | 58 | handlers = console |
|
59 | 59 | |
|
60 | 60 | [logger_routes] |
|
61 | 61 | level = INFO |
|
62 | 62 | handlers = console |
|
63 | 63 | qualname = routes.middleware |
|
64 | 64 | # "level = DEBUG" logs the route matched and routing variables. |
|
65 | 65 | |
|
66 | 66 | [logger_pylons_app] |
|
67 | 67 | level = DEBUG |
|
68 | 68 | handlers = console |
|
69 | 69 | qualname = pylons_app |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | [logger_sqlalchemy] |
|
73 | 73 | level = DEBUG |
|
74 | 74 | handlers = console |
|
75 | 75 | qualname = sqlalchemy.engine |
|
76 | 76 | |
|
77 | 77 | ############## |
|
78 | 78 | ## HANDLERS ## |
|
79 | 79 | ############## |
|
80 | 80 | |
|
81 | 81 | [handler_console] |
|
82 | 82 | class = StreamHandler |
|
83 | 83 | args = (sys.stderr,) |
|
84 | 84 | level = NOTSET |
|
85 | 85 | formatter = generic |
|
86 | 86 | |
|
87 | [handler_chainsaw] | |
|
88 | class = xmllayout.RawSocketHandler | |
|
89 | args = ('localhost', 4448) | |
|
90 | level = NOTSET | |
|
91 | formatter = xmllayout | |
|
92 | ||
|
87 | 93 | ################ |
|
88 | 94 | ## FORMATTERS ## |
|
89 | 95 | ################ |
|
90 | 96 | |
|
91 | 97 | [formatter_generic] |
|
92 | 98 | format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
93 | 99 | datefmt = %H:%M:%S |
|
94 | 100 | |
|
101 | [formatter_xmllayout] | |
|
102 | class = xmllayout.XMLLayout | |
|
103 |
@@ -1,20 +1,20 b'' | |||
|
1 | 1 | [hooks] |
|
2 | 2 | #to do push with autoupdate |
|
3 | 3 | changegroup = hg update >&2 |
|
4 | 4 | |
|
5 | 5 | [extensions] |
|
6 | 6 | hgext.highlight= |
|
7 | 7 | #hgk= |
|
8 | 8 | |
|
9 | 9 | [web] |
|
10 | 10 | push_ssl = false |
|
11 |
contact = |
|
|
11 | contact = develop@etelko.pl | |
|
12 | 12 | allow_archive = gz zip bz2 |
|
13 | 13 | allow_push = * |
|
14 | 14 | style = gitweb |
|
15 | 15 | pygments_style = trac |
|
16 | 16 | staticurl = /static |
|
17 | 17 | baseurl = / |
|
18 | 18 | |
|
19 | 19 | [paths] |
|
20 | 20 | / = /home/marcink/python_workspace/** |
General Comments 0
You need to be logged in to leave comments.
Login now