~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: Martin Pool
  • Date: 2008-07-04 04:32:12 UTC
  • mfrom: (3350.9.1 stacking-annotate)
  • mto: This revision was merged to the branch mainline in revision 3527.
  • Revision ID: mbp@sourcefrog.net-20080704043212-jmwl1vrqhtao5gy3
Merge unoptimized annotate code for stacking, and only use it when needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""A custom importer and regex compiler which logs time spent."""
19
19
 
26
26
_total_stack = {}
27
27
_info = {}
28
28
_cur_id = 0
29
 
_timer = time.time
30
 
if sys.platform == 'win32':
31
 
    _timer = time.clock
32
29
 
33
30
 
34
31
def stack_add(name, frame_name, frame_lineno, scope_name=None):
134
131
 
135
132
    this = stack_add(extra + name, frame_name, frame_lineno, scope_name)
136
133
 
137
 
    tstart = _timer()
 
134
    tstart = time.time()
138
135
    try:
139
136
        # Do the import
140
137
        mod = _real_import(name, globals, locals, fromlist)
141
138
    finally:
142
 
        tload = _timer()-tstart
 
139
        tload = time.time()-tstart
143
140
        stack_finish(this, tload)
144
141
 
145
142
    return mod
163
160
    frame_lineno = frame.f_lineno
164
161
    this = stack_add(extra+repr(args[0]), frame_name, frame_lineno)
165
162
 
166
 
    tstart = _timer()
 
163
    tstart = time.time()
167
164
    try:
168
165
        # Measure the compile time
169
166
        comp = _real_compile(*args, **kwargs)
170
167
    finally:
171
 
        tcompile = _timer() - tstart
 
168
        tcompile = time.time() - tstart
172
169
        stack_finish(this, tcompile)
173
170
 
174
171
    return comp