mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-05 16:08:40 +00:00
Add support to profile the daemon using the --profile option
This commit is contained in:
parent
bf2f4ee860
commit
8c587f7330
1 changed files with 15 additions and 0 deletions
|
@ -143,6 +143,8 @@ def start_daemon():
|
||||||
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
|
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
|
||||||
parser.add_option("-q", "--quiet", dest="quiet",
|
parser.add_option("-q", "--quiet", dest="quiet",
|
||||||
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False)
|
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False)
|
||||||
|
parser.add_option("--profile", dest="profile", action="store_true", default=False,
|
||||||
|
help="Profiles the daemon" )
|
||||||
|
|
||||||
# Get the options and args from the OptionParser
|
# Get the options and args from the OptionParser
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
@ -189,6 +191,10 @@ def start_daemon():
|
||||||
deluge.log.setupLogger(level=options.loglevel, filename=options.logfile)
|
deluge.log.setupLogger(level=options.loglevel, filename=options.logfile)
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
if options.profile:
|
||||||
|
import hotshot
|
||||||
|
hsp = hotshot.Profile(deluge.configmanager.get_config_dir("deluged.profile"))
|
||||||
|
hsp.start()
|
||||||
try:
|
try:
|
||||||
from deluge.core.daemon import Daemon
|
from deluge.core.daemon import Daemon
|
||||||
Daemon(options, args)
|
Daemon(options, args)
|
||||||
|
@ -200,3 +206,12 @@ def start_daemon():
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
finally:
|
||||||
|
if options.profile:
|
||||||
|
hsp.stop()
|
||||||
|
hsp.close()
|
||||||
|
import hotshot.stats
|
||||||
|
stats = hotshot.stats.load(deluge.configmanager.get_config_dir("deluged.profile"))
|
||||||
|
stats.strip_dirs()
|
||||||
|
stats.sort_stats("time", "calls")
|
||||||
|
stats.print_stats(400)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue