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 | # pylons_app - Pylons environment configuration # |
|
3 | # pylons_app - Pylons environment configuration # | |
4 | # # |
|
4 | # # | |
5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
5 | # The %(here)s variable will be replaced with the parent directory of this file# | |
6 | ################################################################################ |
|
6 | ################################################################################ | |
7 |
|
7 | |||
8 | [DEFAULT] |
|
8 | [DEFAULT] | |
9 | debug = true |
|
9 | debug = true | |
10 | ############################################ |
|
10 | ############################################ | |
11 | ## Uncomment and replace with the address ## |
|
11 | ## Uncomment and replace with the address ## | |
12 | ## which should receive any error reports ## |
|
12 | ## which should receive any error reports ## | |
13 | ############################################ |
|
13 | ############################################ | |
14 | #email_to = marcin.kuzminski@etelko.pl |
|
14 | #email_to = marcin.kuzminski@etelko.pl | |
15 | #smtp_server = mail.etelko.pl |
|
15 | #smtp_server = mail.etelko.pl | |
16 | #error_email_from = paste_error@localhost |
|
16 | #error_email_from = paste_error@localhost | |
17 | #smtp_username = |
|
17 | #smtp_username = | |
18 | #smtp_password = |
|
18 | #smtp_password = | |
19 | #error_message = 'mercurial crash !' |
|
19 | #error_message = 'mercurial crash !' | |
20 |
|
20 | |||
21 | [server:main] |
|
21 | [server:main] | |
22 | use = egg:Paste#http |
|
22 | use = egg:Paste#http | |
23 | host = 127.0.0.1 |
|
23 | host = 127.0.0.1 | |
24 | port = 5000 |
|
24 | port = 5000 | |
25 |
|
25 | |||
26 | [app:main] |
|
26 | [app:main] | |
27 | use = egg:pylons_app |
|
27 | use = egg:pylons_app | |
28 | full_stack = true |
|
28 | full_stack = true | |
29 | static_files = true |
|
29 | static_files = true | |
30 | lang=en |
|
30 | lang=en | |
31 | cache_dir = %(here)s/data |
|
31 | cache_dir = %(here)s/data | |
32 |
|
32 | |||
33 | ################################################################################ |
|
33 | ################################################################################ | |
34 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
|
34 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## | |
35 | ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ## |
|
35 | ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ## | |
36 | ## execute malicious code after an exception is raised. ## |
|
36 | ## execute malicious code after an exception is raised. ## | |
37 | ################################################################################ |
|
37 | ################################################################################ | |
38 | #set debug = false |
|
38 | #set debug = false | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | ################################ |
|
41 | ################################ | |
42 | ### LOGGING CONFIGURATION #### |
|
42 | ### LOGGING CONFIGURATION #### | |
43 | ################################ |
|
43 | ################################ | |
44 | [loggers] |
|
44 | [loggers] | |
45 | keys = root, routes, pylons_app, sqlalchemy |
|
45 | keys = root, routes, pylons_app, sqlalchemy | |
46 |
|
46 | |||
47 | [handlers] |
|
47 | [handlers] | |
48 | keys = console |
|
48 | keys = console,chainsaw | |
49 |
|
49 | |||
50 | [formatters] |
|
50 | [formatters] | |
51 | keys = generic |
|
51 | keys = generic,xmllayout | |
52 |
|
52 | |||
53 | ############# |
|
53 | ############# | |
54 | ## LOGGERS ## |
|
54 | ## LOGGERS ## | |
55 | ############# |
|
55 | ############# | |
56 | [logger_root] |
|
56 | [logger_root] | |
57 |
level = |
|
57 | level = NOTSET | |
58 | handlers = console |
|
58 | handlers = console | |
59 |
|
59 | |||
60 | [logger_routes] |
|
60 | [logger_routes] | |
61 | level = INFO |
|
61 | level = INFO | |
62 | handlers = console |
|
62 | handlers = console | |
63 | qualname = routes.middleware |
|
63 | qualname = routes.middleware | |
64 | # "level = DEBUG" logs the route matched and routing variables. |
|
64 | # "level = DEBUG" logs the route matched and routing variables. | |
65 |
|
65 | |||
66 | [logger_pylons_app] |
|
66 | [logger_pylons_app] | |
67 | level = DEBUG |
|
67 | level = DEBUG | |
68 | handlers = console |
|
68 | handlers = console | |
69 | qualname = pylons_app |
|
69 | qualname = pylons_app | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | [logger_sqlalchemy] |
|
72 | [logger_sqlalchemy] | |
73 | level = DEBUG |
|
73 | level = DEBUG | |
74 | handlers = console |
|
74 | handlers = console | |
75 | qualname = sqlalchemy.engine |
|
75 | qualname = sqlalchemy.engine | |
76 |
|
76 | |||
77 | ############## |
|
77 | ############## | |
78 | ## HANDLERS ## |
|
78 | ## HANDLERS ## | |
79 | ############## |
|
79 | ############## | |
80 |
|
80 | |||
81 | [handler_console] |
|
81 | [handler_console] | |
82 | class = StreamHandler |
|
82 | class = StreamHandler | |
83 | args = (sys.stderr,) |
|
83 | args = (sys.stderr,) | |
84 | level = NOTSET |
|
84 | level = NOTSET | |
85 | formatter = generic |
|
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 | ## FORMATTERS ## |
|
94 | ## FORMATTERS ## | |
89 | ################ |
|
95 | ################ | |
90 |
|
96 | |||
91 | [formatter_generic] |
|
97 | [formatter_generic] | |
92 | format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s |
|
98 | format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s | |
93 | datefmt = %H:%M:%S |
|
99 | datefmt = %H:%M:%S | |
94 |
|
100 | |||
|
101 | [formatter_xmllayout] | |||
|
102 | class = xmllayout.XMLLayout | |||
|
103 |
@@ -1,20 +1,20 b'' | |||||
1 | [hooks] |
|
1 | [hooks] | |
2 | #to do push with autoupdate |
|
2 | #to do push with autoupdate | |
3 | changegroup = hg update >&2 |
|
3 | changegroup = hg update >&2 | |
4 |
|
4 | |||
5 | [extensions] |
|
5 | [extensions] | |
6 | hgext.highlight= |
|
6 | hgext.highlight= | |
7 | #hgk= |
|
7 | #hgk= | |
8 |
|
8 | |||
9 | [web] |
|
9 | [web] | |
10 | push_ssl = false |
|
10 | push_ssl = false | |
11 |
contact = |
|
11 | contact = develop@etelko.pl | |
12 | allow_archive = gz zip bz2 |
|
12 | allow_archive = gz zip bz2 | |
13 | allow_push = * |
|
13 | allow_push = * | |
14 | style = gitweb |
|
14 | style = gitweb | |
15 | pygments_style = trac |
|
15 | pygments_style = trac | |
16 | staticurl = /static |
|
16 | staticurl = /static | |
17 | baseurl = / |
|
17 | baseurl = / | |
18 |
|
18 | |||
19 | [paths] |
|
19 | [paths] | |
20 | / = /home/marcink/python_workspace/** |
|
20 | / = /home/marcink/python_workspace/** |
General Comments 0
You need to be logged in to leave comments.
Login now