~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: Robert Collins
  • Date: 2009-07-07 04:32:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4524.
  • Revision ID: robertc@robertcollins.net-20090707043213-4hjjhgr40iq7gk2d
More informative assertions in xml serialisation.

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., 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
 
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
29
32
 
30
33
 
31
34
def stack_add(name, frame_name, frame_lineno, scope_name=None):
131
134
 
132
135
    this = stack_add(extra + name, frame_name, frame_lineno, scope_name)
133
136
 
134
 
    tstart = time.time()
 
137
    tstart = _timer()
135
138
    try:
136
139
        # Do the import
137
140
        mod = _real_import(name, globals, locals, fromlist)
138
141
    finally:
139
 
        tload = time.time()-tstart
 
142
        tload = _timer()-tstart
140
143
        stack_finish(this, tload)
141
144
 
142
145
    return mod
160
163
    frame_lineno = frame.f_lineno
161
164
    this = stack_add(extra+repr(args[0]), frame_name, frame_lineno)
162
165
 
163
 
    tstart = time.time()
 
166
    tstart = _timer()
164
167
    try:
165
168
        # Measure the compile time
166
169
        comp = _real_compile(*args, **kwargs)
167
170
    finally:
168
 
        tcompile = time.time() - tstart
 
171
        tcompile = _timer() - tstart
169
172
        stack_finish(this, tcompile)
170
173
 
171
174
    return comp