mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Use better timer on the mac
Open files in binary mode (Jack)
This commit is contained in:
parent
45ac47c0b2
commit
cbf3dd53b4
1 changed files with 18 additions and 1 deletions
|
@ -152,6 +152,11 @@ class Profile:
|
||||||
if hasattr(os, 'times'):
|
if hasattr(os, 'times'):
|
||||||
self.timer = os.times
|
self.timer = os.times
|
||||||
self.dispatcher = self.trace_dispatch
|
self.dispatcher = self.trace_dispatch
|
||||||
|
elif os.name == 'mac':
|
||||||
|
import MacOS
|
||||||
|
self.timer = MacOS.GetTicks
|
||||||
|
self.dispatcher = self.trace_dispatch_mac
|
||||||
|
self.get_time = self.get_time_mac
|
||||||
else:
|
else:
|
||||||
self.timer = time.time
|
self.timer = time.time
|
||||||
self.dispatcher = self.trace_dispatch_i
|
self.dispatcher = self.trace_dispatch_i
|
||||||
|
@ -175,6 +180,8 @@ class Profile:
|
||||||
t = reduce(lambda x,y: x+y, t, 0)
|
t = reduce(lambda x,y: x+y, t, 0)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
def get_time_mac(self):
|
||||||
|
return self.timer()/60.0
|
||||||
|
|
||||||
# Heavily optimized dispatch routine for os.times() timer
|
# Heavily optimized dispatch routine for os.times() timer
|
||||||
|
|
||||||
|
@ -203,6 +210,16 @@ class Profile:
|
||||||
self.t = self.timer() - t # put back unrecorded delta
|
self.t = self.timer() - t # put back unrecorded delta
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Dispatch routine for macintosh (timer returns time in ticks of 1/60th second)
|
||||||
|
|
||||||
|
def trace_dispatch_mac(self, frame, event, arg):
|
||||||
|
t = self.timer()/60.0 - self.t # - 1 # Integer calibration constant
|
||||||
|
if self.dispatch[event](frame,t):
|
||||||
|
self.t = self.timer()/60.0
|
||||||
|
else:
|
||||||
|
self.t = self.timer()/60.0 - t # put back unrecorded delta
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
# SLOW generic dispatch rountine for timer returning lists of numbers
|
# SLOW generic dispatch rountine for timer returning lists of numbers
|
||||||
|
|
||||||
|
@ -338,7 +355,7 @@ class Profile:
|
||||||
print_stats()
|
print_stats()
|
||||||
|
|
||||||
def dump_stats(self, file):
|
def dump_stats(self, file):
|
||||||
f = open(file, 'w')
|
f = open(file, 'wb')
|
||||||
self.create_stats()
|
self.create_stats()
|
||||||
marshal.dump(self.stats, f)
|
marshal.dump(self.stats, f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue