Commit 566d76fb authored by Guido van Rossum's avatar Guido van Rossum

After the previous changes, func_normalize() turned out to be redundant.

This simplified some other places in the code.
parent b8290f61
...@@ -41,15 +41,6 @@ import string ...@@ -41,15 +41,6 @@ import string
import marshal import marshal
# Global variables
func_norm_dict = {}
func_norm_counter = 0
if hasattr(os, 'getpid'):
pid_string = `os.getpid()`
else:
pid_string = ''
# Sample timer for use with # Sample timer for use with
#i_count = 0 #i_count = 0
#def integer_timer(): #def integer_timer():
...@@ -126,15 +117,6 @@ def help(): ...@@ -126,15 +117,6 @@ def help():
# [5] = A dictionary indicating for each function name, the number of times # [5] = A dictionary indicating for each function name, the number of times
# it was called by us. # it was called by us.
#************************************************************************** #**************************************************************************
# We produce function names via a repr() call on the f_code object during
# profiling. This save a *lot* of CPU time. This results in a string that
# always looks like:
# <code object main at 87090, file "/a/lib/python-local/myfib.py", line 76>
# After we "normalize it, it is a tuple of filename, line, function-name.
# We wait till we are done profiling to do the normalization.
# *IF* this repr format changes, then only the normalization routine should
# need to be fixed.
#**************************************************************************
class Profile: class Profile:
def __init__(self, timer=None): def __init__(self, timer=None):
...@@ -350,44 +332,11 @@ class Profile: ...@@ -350,44 +332,11 @@ class Profile:
self.stats = {} self.stats = {}
for func in self.timings.keys(): for func in self.timings.keys():
cc, ns, tt, ct, callers = self.timings[func] cc, ns, tt, ct, callers = self.timings[func]
nor_func = self.func_normalize(func) callers = callers.copy()
nor_callers = {}
nc = 0 nc = 0
for func_caller in callers.keys(): for func_caller in callers.keys():
nor_callers[self.func_normalize(func_caller)]=\
callers[func_caller]
nc = nc + callers[func_caller] nc = nc + callers[func_caller]
self.stats[nor_func] = cc, nc, tt, ct, nor_callers self.stats[func] = cc, nc, tt, ct, callers
# Override the following function if you can figure out
# a better name for the binary f_code entries. I just normalize
# them sequentially in a dictionary. It would be nice if we could
# *really* see the name of the underlying C code :-). Sometimes
# you can figure out what-is-what by looking at caller and callee
# lists (and knowing what your python code does).
def func_normalize(self, func_name):
global func_norm_dict
global func_norm_counter
global func_sequence_num
if func_norm_dict.has_key(func_name):
return func_norm_dict[func_name]
if type(func_name) == type(""):
long_name = string.split(func_name)
file_name = long_name[-3][1:-2]
func = long_name[2]
lineno = long_name[-1][:-1]
if '?' == func: # Until I find out how to may 'em...
file_name = 'python'
func_norm_counter = func_norm_counter + 1
func = pid_string + ".C." + `func_norm_counter`
result = file_name , string.atoi(lineno) , func
else:
result = func_name
func_norm_dict[func_name] = result
return result
# The following two methods can be called by clients to use # The following two methods can be called by clients to use
...@@ -553,14 +502,11 @@ class OldProfile(Profile): ...@@ -553,14 +502,11 @@ class OldProfile(Profile):
self.stats = {} self.stats = {}
for func in self.timings.keys(): for func in self.timings.keys():
tt, ct, callers = self.timings[func] tt, ct, callers = self.timings[func]
nor_func = self.func_normalize(func) callers = callers.copy()
nor_callers = {}
nc = 0 nc = 0
for func_caller in callers.keys(): for func_caller in callers.keys():
nor_callers[self.func_normalize(func_caller)]=\
callers[func_caller]
nc = nc + callers[func_caller] nc = nc + callers[func_caller]
self.stats[nor_func] = nc, nc, tt, ct, nor_callers self.stats[func] = nc, nc, tt, ct, callers
...@@ -605,8 +551,7 @@ class HotProfile(Profile): ...@@ -605,8 +551,7 @@ class HotProfile(Profile):
self.stats = {} self.stats = {}
for func in self.timings.keys(): for func in self.timings.keys():
nc, tt = self.timings[func] nc, tt = self.timings[func]
nor_func = self.func_normalize(func) self.stats[func] = nc, nc, tt, 0, {}
self.stats[nor_func] = nc, nc, tt, 0, {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment