[WebUI] Changed --profile to use cProfile

This commit is contained in:
bendikro 2014-03-06 15:56:19 +01:00 committed by Calum Lind
parent 6c74e2d19c
commit 30705d6fc9

View File

@ -146,22 +146,26 @@ class Web(_UI):
if self.options.ensure_value("ssl", None): if self.options.ensure_value("ssl", None):
self.server.https = self.options.ssl self.server.https = self.options.ssl
if self.options.profile: def run_server():
import hotshot
hsp = hotshot.Profile(deluge.configmanager.get_config_dir("deluge-web.profile"))
hsp.start()
self.server.install_signal_handlers() self.server.install_signal_handlers()
self.server.start() self.server.start()
if self.options.profile: if self.options.profile:
hsp.stop() import cProfile
hsp.close() profiler = cProfile.Profile()
import hotshot.stats profile_output = deluge.configmanager.get_config_dir("delugeweb.profile")
stats = hotshot.stats.load(deluge.configmanager.get_config_dir("deluge-web.profile"))
stats.strip_dirs() # Twisted catches signals to terminate
stats.sort_stats("time", "calls") def save_profile_stats():
stats.print_stats(400) profiler.dump_stats(profile_output)
print "Profile stats saved to %s" % profile_output
from twisted.internet import reactor
reactor.addSystemEventTrigger("before", "shutdown", save_profile_stats)
print "Running with profiler..."
profiler.runcall(run_server)
else:
run_server()
def start(): def start():
web = Web() web = Web()