Show More
@@ -121,6 +121,7 b' import string' | |||||
121 | import sys |
|
121 | import sys | |
122 | import time |
|
122 | import time | |
123 | import unicodedata |
|
123 | import unicodedata | |
|
124 | import uuid | |||
124 | import warnings |
|
125 | import warnings | |
125 | from contextlib import contextmanager |
|
126 | from contextlib import contextmanager | |
126 | from importlib import import_module |
|
127 | from importlib import import_module | |
@@ -133,8 +134,9 b' from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol' | |||||
133 | from IPython.core.oinspect import InspectColors |
|
134 | from IPython.core.oinspect import InspectColors | |
134 | from IPython.utils import generics |
|
135 | from IPython.utils import generics | |
135 | from IPython.utils.dir2 import dir2, get_real_method |
|
136 | from IPython.utils.dir2 import dir2, get_real_method | |
|
137 | from IPython.utils.path import ensure_dir_exists | |||
136 | from IPython.utils.process import arg_split |
|
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 | from traitlets.config.configurable import Configurable |
|
140 | from traitlets.config.configurable import Configurable | |
139 |
|
141 | |||
140 | import __main__ |
|
142 | import __main__ | |
@@ -1049,6 +1051,15 b' class IPCompleter(Completer):' | |||||
1049 | """, |
|
1051 | """, | |
1050 | ).tag(config=True) |
|
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 | @observe('limit_to__all__') |
|
1063 | @observe('limit_to__all__') | |
1053 | def _limit_to_all_changed(self, change): |
|
1064 | def _limit_to_all_changed(self, change): | |
1054 | warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration ' |
|
1065 | warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration ' | |
@@ -1824,6 +1835,13 b' class IPCompleter(Completer):' | |||||
1824 |
|
1835 | |||
1825 | seen = set() |
|
1836 | seen = set() | |
1826 | try: |
|
1837 | try: | |
|
1838 | if self.profile_completions: | |||
|
1839 | import cProfile | |||
|
1840 | profiler = cProfile.Profile() | |||
|
1841 | profiler.enable() | |||
|
1842 | else: | |||
|
1843 | profiler = None | |||
|
1844 | ||||
1827 | for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000): |
|
1845 | for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000): | |
1828 | if c and (c in seen): |
|
1846 | if c and (c in seen): | |
1829 | continue |
|
1847 | continue | |
@@ -1833,6 +1851,13 b' class IPCompleter(Completer):' | |||||
1833 | """if completions take too long and users send keyboard interrupt, |
|
1851 | """if completions take too long and users send keyboard interrupt, | |
1834 | do not crash and return ASAP. """ |
|
1852 | do not crash and return ASAP. """ | |
1835 | pass |
|
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 | def _completions(self, full_text: str, offset: int, *, _timeout)->Iterator[Completion]: |
|
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