Skip to content
Snippets Groups Projects
Commit bbb5a5d1 authored by ale's avatar ale
Browse files

add a --profile option to wrap the wsgi app with "repoze.profile"

parent 21144201
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ log = logging.getLogger(__name__)
def run_frontend(port, solr_url, db_url, lastfm_api_key, album_art_dir,
email_sender, markov_data_file):
email_sender, markov_data_file, do_profile):
init_db(db_url)
svcs['searcher'] = Searcher(solr_url)
......@@ -32,6 +32,18 @@ def run_frontend(port, solr_url, db_url, lastfm_api_key, album_art_dir,
log.error('Could not read Markov data from %s: %s' % (
markov_data_file, str(e)))
# Start the WSGI profiling middleware, if requested.
if do_profile:
from repoze.profile.profiler import AccumulatingProfileMiddleware
app.wsgi_app = AccumulatingProfileMiddleware(
app.wsgi_app,
log_filename='/var/tmp/djrandom-profile.log',
cachegrind_filename='/var/tmp/djrandom-profile.cachegrind',
discard_first_request=True,
flush_at_shutdown=True,
path='/__profile__'
)
http_server = WSGIServer(('0.0.0.0', port), app)
http_server.serve_forever()
......@@ -46,6 +58,7 @@ def main():
parser.add_option('--album_art_dir', default='/var/tmp/album-image-cache')
parser.add_option('--markov_data',
default='/var/lib/djrandom/djrandom-markov.dat')
parser.add_option('--profile', action='store_true')
daemonize.add_standard_options(parser)
utils.read_config_defaults(
parser, os.getenv('DJRANDOM_CONF', '/etc/djrandom.conf'))
......@@ -58,7 +71,7 @@ def main():
daemonize.daemonize(opts, run_frontend,
(opts.port, opts.solr_url, opts.db_url,
opts.lastfm_api_key, opts.album_art_dir,
opts.email_sender, opts.markov_data),
opts.email_sender, opts.markov_data, opts.profile),
support_gevent=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment