summaryrefslogtreecommitdiff
path: root/Lib/profile.py
diff options
context:
space:
mode:
authorNicholas Bastin <nick.bastin@gmail.com>2004-03-24 21:57:10 +0000
committerNicholas Bastin <nick.bastin@gmail.com>2004-03-24 21:57:10 +0000
commitc69ebe8d50529eae281275c841428eb9b375a442 (patch)
treeb8150da59983ca89c192b45311eeee050a0b4a16 /Lib/profile.py
parenta1dde13389cf47ac626394796740925504e3e272 (diff)
downloadcpython-git-c69ebe8d50529eae281275c841428eb9b375a442.tar.gz
Enable the profiling of C functions (builtins and extensions)
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-xLib/profile.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/profile.py b/Lib/profile.py
index cf22377653..99a5b626e1 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -163,6 +163,7 @@ class Profile:
self.timings = {}
self.cur = None
self.cmd = ""
+ self.c_func_name = ""
if bias is None:
bias = self.bias
@@ -214,6 +215,9 @@ class Profile:
t = timer()
t = t[0] + t[1] - self.t - self.bias
+ if event == "c_call":
+ self.c_func_name = arg
+
if self.dispatch[event](self, frame,t):
t = timer()
self.t = t[0] + t[1]
@@ -227,7 +231,11 @@ class Profile:
def trace_dispatch_i(self, frame, event, arg):
timer = self.timer
t = timer() - self.t - self.bias
- if self.dispatch[event](self, frame,t):
+
+ if event == "c_call":
+ self.c_func_name = arg
+
+ if self.dispatch[event](self, frame, t):
self.t = timer()
else:
self.t = timer() - t # put back unrecorded delta
@@ -238,6 +246,10 @@ class Profile:
def trace_dispatch_mac(self, frame, event, arg):
timer = self.timer
t = timer()/60.0 - self.t - self.bias
+
+ if event == "c_call":
+ self.c_func_name = arg
+
if self.dispatch[event](self, frame, t):
self.t = timer()/60.0
else:
@@ -249,6 +261,9 @@ class Profile:
get_time = self.get_time
t = get_time() - self.t - self.bias
+ if event == "c_call":
+ self.c_func_name = arg
+
if self.dispatch[event](self, frame, t):
self.t = get_time()
else:
@@ -291,6 +306,17 @@ class Profile:
timings[fn] = 0, 0, 0, 0, {}
return 1
+ def trace_dispatch_c_call (self, frame, t):
+ fn = ("", 0, self.c_func_name)
+ self.cur = (t, 0, 0, fn, frame, self.cur)
+ timings = self.timings
+ if timings.has_key(fn):
+ cc, ns, tt, ct, callers = timings[fn]
+ timings[fn] = cc, ns+1, tt, ct, callers
+ else:
+ timings[fn] = 0, 0, 0, 0, {}
+ return 1
+
def trace_dispatch_return(self, frame, t):
if frame is not self.cur[-2]:
assert frame is self.cur[-2].f_back, ("Bad return", self.cur[-3])
@@ -333,6 +359,9 @@ class Profile:
"call": trace_dispatch_call,
"exception": trace_dispatch_exception,
"return": trace_dispatch_return,
+ "c_call": trace_dispatch_c_call,
+ "c_exception": trace_dispatch_exception,
+ "c_return": trace_dispatch_return,
}