~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-10 15:46:03 UTC
  • mfrom: (4985.3.21 update)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: v.ladeuil+lp@free.fr-20100210154603-k4no1gvfuqpzrw7p
Update performs two merges in a more logical order but stop on conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006, 2009 by Canonical Ltd
2
2
# Written by John Arbash Meinel <john@arbash-meinel.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
"""A custom importer and regex compiler which logs time spent."""
19
19
 
20
 
import sre
21
20
import sys
22
21
import time
23
22
 
24
23
 
 
24
if sys.version_info < (2, 5, 0):
 
25
    import sre
 
26
    re = sre
 
27
else:
 
28
    import re
 
29
 
 
30
 
25
31
_parent_stack = []
26
32
_total_stack = {}
27
33
_info = {}
96
102
 
97
103
_real_import = __import__
98
104
 
99
 
def timed_import(name, globals, locals, fromlist):
 
105
def timed_import(name, globals, locals, fromlist, level=None):
100
106
    """Wrap around standard importer to log import time"""
 
107
    # level is only passed by python2.6
101
108
 
102
109
    scope_name = globals.get('__name__', None)
103
110
    if scope_name is None:
145
152
    return mod
146
153
 
147
154
 
148
 
_real_compile = sre._compile
 
155
_real_compile = re._compile
 
156
 
149
157
 
150
158
def timed_compile(*args, **kwargs):
151
159
    """Log how long it takes to compile a regex"""
177
185
def install():
178
186
    """Install the hooks for measuring import and regex compile time."""
179
187
    __builtins__['__import__'] = timed_import
180
 
    sre._compile = timed_compile
 
188
    re._compile = timed_compile
181
189
 
182
190
 
183
191
def uninstall():
184
192
    """Remove the import and regex compile timing hooks."""
185
193
    __builtins__['__import__'] = _real_import
186
 
    sre._compile = _real_compile
 
194
    re._compile = _real_compile
187
195