Collect profiling information from the child monitor thread as well
This commit is contained in:
parent
2de8c70bb8
commit
4144d46844
@ -28,6 +28,7 @@ class Boss(Thread):
|
||||
|
||||
def __init__(self, window, window_width, window_height, opts, args):
|
||||
Thread.__init__(self, name='ChildMonitor')
|
||||
self.profile = args.profile
|
||||
self.child_fd = create_pty()[0]
|
||||
self.loop = asyncio.get_event_loop()
|
||||
self.loop.add_signal_handler(signal.SIGINT, lambda: self.loop.call_soon_threadsafe(self.shutdown))
|
||||
@ -88,7 +89,17 @@ class Boss(Thread):
|
||||
self.char_grid.render()
|
||||
|
||||
def run(self):
|
||||
if self.profile:
|
||||
import cProfile
|
||||
import pstats
|
||||
pr = cProfile.Profile()
|
||||
pr.enable()
|
||||
self.loop.run_forever()
|
||||
if self.profile:
|
||||
pr.disable()
|
||||
pr.create_stats()
|
||||
s = pstats.Stats(pr)
|
||||
s.dump_stats(self.profile)
|
||||
|
||||
def close(self):
|
||||
if not self.shutting_down:
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import argparse
|
||||
import tempfile
|
||||
import os
|
||||
import sys
|
||||
import pwd
|
||||
@ -93,6 +94,8 @@ def main():
|
||||
child = args.args or [pwd.getpwuid(os.geteuid()).pw_shell or '/bin/sh']
|
||||
fork_child(child, args.directory, opts)
|
||||
if args.profile:
|
||||
tf = tempfile.NamedTemporaryFile(prefix='kitty-profiling-stats-')
|
||||
args.profile = tf.name
|
||||
import cProfile
|
||||
import pstats
|
||||
pr = cProfile.Profile()
|
||||
@ -101,6 +104,8 @@ def main():
|
||||
pr.disable()
|
||||
pr.create_stats()
|
||||
s = pstats.Stats(pr)
|
||||
s.add(args.profile)
|
||||
tf.close()
|
||||
s.strip_dirs()
|
||||
s.sort_stats('time', 'name')
|
||||
s.print_stats(30)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user