Created
June 4, 2019 14:54
-
-
Save saimn/bd275de04bfdb975c1781b0f666919de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py | |
index 8eaa0e215..62887098a 100644 | |
--- a/sphinx/builders/__init__.py | |
+++ b/sphinx/builders/__init__.py | |
@@ -452,12 +452,33 @@ class Builder: | |
def _read_serial(self, docnames): | |
# type: (List[str]) -> None | |
+ times = [] | |
+ import psutil | |
+ p = psutil.Process() | |
+ refmem = p.memory_info().rss | |
+ | |
for docname in status_iterator(docnames, __('reading sources... '), "purple", | |
len(docnames), self.app.verbosity): | |
# remove all inventory entries for that file | |
self.events.emit('env-purge-doc', self.env, docname) | |
self.env.clear_doc(docname) | |
+ t0 = time.time() | |
self.read_doc(docname) | |
+ mem = p.memory_info().rss | |
+ times.append((time.time() - t0, docname, (mem - refmem) / 1e6)) | |
+ refmem = mem | |
+ print(times[-1]) | |
+ | |
+ times.sort(reverse=True) | |
+ print('50 slowest tests:') | |
+ for t, name, mem in times[:50]: | |
+ print(f'{docname} : {t:.2f} sec., {mem:.2f} Mb') | |
+ | |
+ import operator | |
+ times.sort(key=operator.itemgetter(2), reverse=True) | |
+ print('50 biggest memory tests:') | |
+ for t, name, mem in times[:50]: | |
+ print(f'{docname} : {t:.2f} sec., {mem:.2f} Mb') | |
def _read_parallel(self, docnames, nproc): | |
# type: (List[str], int) -> None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment