103
103
_real_import = __import__
105
def timed_import(name, globals, locals, fromlist, level=None):
105
def timed_import(name, globals=None, locals=None, fromlist=None, level=None):
106
106
"""Wrap around standard importer to log import time"""
107
# normally there are 4, but if this is called as __import__ eg by
108
# /usr/lib/python2.6/email/__init__.py then there may be only one
107
110
# level is only passed by python2.6
109
scope_name = globals.get('__name__', None)
110
if scope_name is None:
111
scope_name = globals.get('__file__', None)
112
if scope_name is None:
113
scope_name = globals.keys()
113
# can't determine the scope name afaics; we could peek up the stack to
114
# see where this is being called from, but it should be a rare case.
115
# Trim out paths before bzrlib
116
loc = scope_name.find('bzrlib')
118
scope_name = scope_name[loc:]
119
# For stdlib, trim out early paths
120
loc = scope_name.find('python2.4')
122
scope_name = scope_name[loc:]
117
scope_name = globals.get('__name__', None)
118
if scope_name is None:
119
scope_name = globals.get('__file__', None)
120
if scope_name is None:
121
scope_name = globals.keys()
123
# Trim out paths before bzrlib
124
loc = scope_name.find('bzrlib')
126
scope_name = scope_name[loc:]
127
# For stdlib, trim out early paths
128
loc = scope_name.find('python2.4')
130
scope_name = scope_name[loc:]
124
132
# Figure out the frame that is doing the importing
125
133
frame = sys._getframe(1)