Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log how long each extension module takes to import #1171

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions jupyter_server/extension/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Extension utilities."""
import importlib
import time
import warnings


Expand Down Expand Up @@ -62,7 +63,15 @@ def get_metadata(package_name, logger=None):
If it doesn't exist, return a basic metadata packet given
the module name.
"""
start_time = time.perf_counter()
module = importlib.import_module(package_name)
end_time = time.perf_counter()
duration = end_time - start_time
# Sometimes packages can take a *while* to import, so we report how long
# each module took to import. This makes it much easier for users to report
# slow loading modules upstream, as slow loading modules will block server startup
if logger:
logger.info(f"Package {package_name} took {duration:.4f}s to import")

try:
return module, module._jupyter_server_extension_points()
Expand Down