/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
 
101
101
_real_import = __import__
102
102
 
103
 
def timed_import(name, globals=None, locals=None, fromlist=None, level=None):
 
103
def timed_import(name, globals=None, locals=None, fromlist=None, level=-1):
104
104
    """Wrap around standard importer to log import time"""
105
105
    # normally there are 4, but if this is called as __import__ eg by
106
106
    # /usr/lib/python2.6/email/__init__.py then there may be only one
118
118
        if scope_name is None:
119
119
            scope_name = globals.keys()
120
120
        else:
121
 
            # Trim out paths before bzrlib
122
 
            loc = scope_name.find('bzrlib')
 
121
            # Trim out paths before breezy
 
122
            loc = scope_name.find('breezy')
123
123
            if loc != -1:
124
124
                scope_name = scope_name[loc:]
125
125
            # For stdlib, trim out early paths
150
150
    tstart = _timer()
151
151
    try:
152
152
        # Do the import
153
 
        mod = _real_import(name, globals, locals, fromlist)
 
153
        return _real_import(name, globals, locals, fromlist, level=level)
154
154
    finally:
155
155
        tload = _timer()-tstart
156
156
        stack_finish(this, tload)
157
157
 
158
 
    return mod
 
158
 
 
159
def _repr_regexp(pattern, max_len=30):
 
160
    """Present regexp pattern for logging, truncating if over max_len."""
 
161
    if len(pattern) > max_len:
 
162
        return repr(pattern[:max_len-3]) + "..."
 
163
    return repr(pattern)
159
164
 
160
165
 
161
166
_real_compile = re._compile
175
180
        frame = sys._getframe(5)
176
181
        frame_name = frame.f_globals.get('__name__', '<unknown>')
177
182
    frame_lineno = frame.f_lineno
178
 
    this = stack_add(extra+repr(args[0]), frame_name, frame_lineno)
 
183
    this = stack_add(extra+_repr_regexp(args[0]), frame_name, frame_lineno)
179
184
 
180
185
    tstart = _timer()
181
186
    try: