summaryrefslogtreecommitdiffstats
path: root/Lib/profile.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-08 15:23:02 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-08 15:23:02 (GMT)
commitcbf3dd53b449995f3fa5fce89161985766cfe8cf (patch)
tree3b352ec46beb5b5229a8956e74bd9003b2e3698f /Lib/profile.py
parent45ac47c0b2798cc3a29cf5111694aba5e9347e08 (diff)
downloadcpython-cbf3dd53b449995f3fa5fce89161985766cfe8cf.zip
cpython-cbf3dd53b449995f3fa5fce89161985766cfe8cf.tar.gz
cpython-cbf3dd53b449995f3fa5fce89161985766cfe8cf.tar.bz2
Use better timer on the mac
Open files in binary mode (Jack)
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-xLib/profile.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/profile.py b/Lib/profile.py
index 582bd8a..ae5182a 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -152,6 +152,11 @@ class Profile:
if hasattr(os, 'times'):
self.timer = os.times
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:
self.timer = time.time
self.dispatcher = self.trace_dispatch_i
@@ -175,6 +180,8 @@ class Profile:
t = reduce(lambda x,y: x+y, t, 0)
return t
+ def get_time_mac(self):
+ return self.timer()/60.0
# Heavily optimized dispatch routine for os.times() timer
@@ -202,6 +209,16 @@ class Profile:
else:
self.t = self.timer() - t # put back unrecorded delta
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
@@ -338,7 +355,7 @@ class Profile:
print_stats()
def dump_stats(self, file):
- f = open(file, 'w')
+ f = open(file, 'wb')
self.create_stats()
marshal.dump(self.stats, f)
f.close()