/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 16:40:42 UTC
  • mfrom: (6653.6.7 rename-controldir)
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610164042-zrxqgy2htyduvke2
MergeĀ rename-controldirĀ branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import time
22
22
 
23
23
 
24
 
if sys.version_info < (2, 5, 0):
25
 
    import sre
26
 
    re = sre
27
 
else:
28
 
    import re
 
24
import re
29
25
 
30
26
 
31
27
_parent_stack = []
104
100
 
105
101
_real_import = __import__
106
102
 
107
 
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):
108
104
    """Wrap around standard importer to log import time"""
109
105
    # normally there are 4, but if this is called as __import__ eg by
110
106
    # /usr/lib/python2.6/email/__init__.py then there may be only one
122
118
        if scope_name is None:
123
119
            scope_name = globals.keys()
124
120
        else:
125
 
            # Trim out paths before bzrlib
126
 
            loc = scope_name.find('bzrlib')
 
121
            # Trim out paths before breezy
 
122
            loc = scope_name.find('breezy')
127
123
            if loc != -1:
128
124
                scope_name = scope_name[loc:]
129
125
            # For stdlib, trim out early paths
154
150
    tstart = _timer()
155
151
    try:
156
152
        # Do the import
157
 
        mod = _real_import(name, globals, locals, fromlist)
 
153
        return _real_import(name, globals, locals, fromlist, level=level)
158
154
    finally:
159
155
        tload = _timer()-tstart
160
156
        stack_finish(this, tload)
161
157
 
162
 
    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)
163
164
 
164
165
 
165
166
_real_compile = re._compile
179
180
        frame = sys._getframe(5)
180
181
        frame_name = frame.f_globals.get('__name__', '<unknown>')
181
182
    frame_lineno = frame.f_lineno
182
 
    this = stack_add(extra+repr(args[0]), frame_name, frame_lineno)
 
183
    this = stack_add(extra+_repr_regexp(args[0]), frame_name, frame_lineno)
183
184
 
184
185
    tstart = _timer()
185
186
    try: