blob: 79f01af8a77dbe656f808f226409808b2b5137c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/env python
import webob
def make_middleware(app):
from repoze.profile.profiler import AccumulatingProfileMiddleware
return AccumulatingProfileMiddleware(
app,
log_filename='/tmp/profile.log',
discard_first_request=True,
flush_at_shutdown=True,
path='/__profile__')
def simple_app(environ, start_response):
resp = webob.Response('Hello world!')
return resp(environ, start_response)
if __name__ == '__main__':
import sys
import os
import signal
if sys.argv[1:]:
arg = sys.argv[1]
else:
arg = None
if arg in ['open', 'run']:
import subprocess
import webbrowser
import time
os.environ['SHOW_OUTPUT'] = '0'
proc = subprocess.Popen([sys.executable, __file__])
time.sleep(1)
subprocess.call(['ab', '-n', '1000', 'http://localhost:8080/'])
if arg == 'open':
webbrowser.open('http://localhost:8080/__profile__')
print 'Hit ^C to end'
try:
while 1:
raw_input()
finally:
os.kill(proc.pid, signal.SIGKILL)
else:
from paste.httpserver import serve
if os.environ.get('SHOW_OUTPUT') != '0':
print 'Note you can also use:'
print ' %s %s open' % (sys.executable, __file__)
print 'to run ab and open a browser (or "run" to just run ab)'
print 'Now do:'
print 'ab -n 1000 http://localhost:8080/'
print 'wget -O - http://localhost:8080/__profile__'
serve(make_middleware(simple_app))
|