diff options
author | Nicholas Bastin <nick.bastin@gmail.com> | 2004-03-24 21:57:10 +0000 |
---|---|---|
committer | Nicholas Bastin <nick.bastin@gmail.com> | 2004-03-24 21:57:10 +0000 |
commit | 10c5d1a05e07ef108096f7fcb27e1790879d15ac (patch) | |
tree | 716d539c1df4acc18fd4058cb1de223f35a7e46f /Lib/profile.py | |
parent | aafa9179f5db7388f85612d73046af6c19bd628e (diff) | |
download | cpython-10c5d1a05e07ef108096f7fcb27e1790879d15ac.tar.gz |
Enable the profiling of C functions (builtins and extensions)
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-x | Lib/profile.py | 31 |
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, } |