From eaa6c7656aa008d57ef5f447230a2414f58795cb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 20 Oct 2016 10:04:59 +0530 Subject: [PATCH] Add an option to dump profiling data --- kitty/main.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kitty/main.py b/kitty/main.py index ccb78b67a..29ae4f93e 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -83,9 +83,17 @@ def option_parser(): a('--exec', '-e', dest='child', default=pwd.getpwuid(os.geteuid()).pw_shell or '/bin/sh', help=_('Run the specified command instead of the shell')) a('-d', '--directory', default='.', help=_('Change to the specified directory when launching')) a('--version', action='version', version='{} {} by Kovid Goyal'.format(appname, '.'.join(str_version))) + a('--profile', action='store_true', default=False, help=_('Show profiling data after exit')) return parser +def run_app(): + try: + return QApplication.instance().exec_() + except KeyboardInterrupt: + pass + + def main(): args = option_parser().parse_args() if args.cmd: @@ -105,7 +113,13 @@ def main(): raise SystemExit(str(err)) from None w = MainWindow(opts) w.show() - try: - app.exec_() - except KeyboardInterrupt: - pass + if args.profile: + import cProfile + pr = cProfile.Profile() + pr.enable() + ret = run_app() + pr.print_stats('cumtime') + pr.disable() + else: + ret = run_app() + return ret