mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-25 17:45:26 +00:00
[WebUI] Changed --profile to use cProfile
This commit is contained in:
parent
6c74e2d19c
commit
30705d6fc9
@ -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
|
self.server.install_signal_handlers()
|
||||||
hsp = hotshot.Profile(deluge.configmanager.get_config_dir("deluge-web.profile"))
|
self.server.start()
|
||||||
hsp.start()
|
|
||||||
|
|
||||||
self.server.install_signal_handlers()
|
|
||||||
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user