##// END OF EJS Templates
ENH: Add configuration for profiling completions....
Scott Sanderson -
Show More
@@ -121,6 +121,7 b' import string'
121 121 import sys
122 122 import time
123 123 import unicodedata
124 import uuid
124 125 import warnings
125 126 from contextlib import contextmanager
126 127 from importlib import import_module
@@ -133,8 +134,9 b' from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol'
133 134 from IPython.core.oinspect import InspectColors
134 135 from IPython.utils import generics
135 136 from IPython.utils.dir2 import dir2, get_real_method
137 from IPython.utils.path import ensure_dir_exists
136 138 from IPython.utils.process import arg_split
137 from traitlets import Bool, Enum, Int, observe
139 from traitlets import Bool, Enum, Int, Unicode, observe
138 140 from traitlets.config.configurable import Configurable
139 141
140 142 import __main__
@@ -1049,6 +1051,15 b' class IPCompleter(Completer):'
1049 1051 """,
1050 1052 ).tag(config=True)
1051 1053
1054 profile_completions = Bool(
1055 default_value=False,
1056 help="If True, emit profiling data for completion subsystem using cProfile."
1057 ).tag(config=True)
1058
1059 profiler_output_dir = Unicode(
1060 default_value=".completion_profiles",
1061 help="Template for path at which to output profile data for completions."
1062 ).tag(config=True)
1052 1063 @observe('limit_to__all__')
1053 1064 def _limit_to_all_changed(self, change):
1054 1065 warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration '
@@ -1824,6 +1835,13 b' class IPCompleter(Completer):'
1824 1835
1825 1836 seen = set()
1826 1837 try:
1838 if self.profile_completions:
1839 import cProfile
1840 profiler = cProfile.Profile()
1841 profiler.enable()
1842 else:
1843 profiler = None
1844
1827 1845 for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000):
1828 1846 if c and (c in seen):
1829 1847 continue
@@ -1833,6 +1851,13 b' class IPCompleter(Completer):'
1833 1851 """if completions take too long and users send keyboard interrupt,
1834 1852 do not crash and return ASAP. """
1835 1853 pass
1854 finally:
1855 if profiler is not None:
1856 profiler.disable()
1857 ensure_dir_exists(self.profiler_output_dir)
1858 output_path = os.path.join(self.profiler_output_dir, str(uuid.uuid4()))
1859 print("Writing profiler output to", output_path)
1860 profiler.dump_stats(output_path)
1836 1861
1837 1862 def _completions(self, full_text: str, offset: int, *, _timeout)->Iterator[Completion]:
1838 1863 """
General Comments 0
You need to be logged in to leave comments. Login now