本文整理汇总了Python中pstats.Stats.print_callees方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.print_callees方法的具体用法?Python Stats.print_callees怎么用?Python Stats.print_callees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pstats.Stats
的用法示例。
在下文中一共展示了Stats.print_callees方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callees [as 别名]
def tearDown(self):
if ENABLE_PROFILE:
if DUMP_PROFILE:
self.pr.dump_stats('profile.out')
p = Stats(self.pr)
p.strip_dirs()
p.sort_stats('time')
p.print_stats(40)
p.print_callees('types.py:846\(validate_value', 20)
p.print_callees('types.py:828\(_validate_primitive_value', 20)
p.print_callees('uploadsession.py:185\(write', 20)
TestBase.teardown(self)
示例2: filter
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callees [as 别名]
def filter(self, execution_func, prof_arg = None):
# put thie imports here so the app doesn't choke if profiling
# is not present (this is a debug-only feature anyway)
import cProfile as profile
from pstats import Stats
tmpfile = tempfile.NamedTemporaryFile()
file = line = func = None
sort_order = 'time'
if prof_arg:
tokens = prof_arg.split(',')
else:
tokens = ()
for token in tokens:
if token == "cum":
sort_order = "cumulative"
elif token == "name":
sort_order = "name"
else:
try:
file, line = prof_arg.split(':')
line, func = line.split('(')
func = func.strip(')')
except:
file = line = func = None
try:
profile.runctx('execution_func()',
globals(), locals(), tmpfile.name)
out = StringIO()
stats = Stats(tmpfile.name, stream=out)
stats.sort_stats(sort_order, 'calls')
def parse_table(t, ncol):
table = []
for s in t:
t = [x for x in s.split(' ') if x]
if len(t) > 1:
table += [t[:ncol-1] + [' '.join(t[ncol-1:])]]
return table
def cmp(n):
def _cmp(x, y):
return 0 if x[n] == y[n] else 1 if x[n] < y[n] else -1
return _cmp
if not file:
stats.print_stats()
stats_str = out.getvalue()
statdata = stats_str.split('\n')
headers = '\n'.join(statdata[:6])
table = parse_table(statdata[6:], 6)
from r2.lib.pages import Profiling
res = Profiling(header = headers, table = table,
path = request.path).render()
return [unicode(res)]
else:
query = "%s:%s" % (file, line)
stats.print_callees(query)
stats.print_callers(query)
statdata = out.getvalue()
data = statdata.split(query)
callee = data[2].split('->')[1].split('Ordered by')[0]
callee = parse_table(callee.split('\n'), 4)
callee.sort(cmp(1))
callee = [['ncalls', 'tottime', 'cputime']] + callee
i = 4
while '<-' not in data[i] and i < len(data): i+= 1
caller = data[i].split('<-')[1]
caller = parse_table(caller.split('\n'), 4)
caller.sort(cmp(1))
caller = [['ncalls', 'tottime', 'cputime']] + caller
from r2.lib.pages import Profiling
res = Profiling(header = prof_arg,
caller = caller, callee = callee,
path = request.path).render()
return [unicode(res)]
finally:
tmpfile.close()
示例3: CProfileVStats
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callees [as 别名]
class CProfileVStats(object):
"""Wrapper around pstats.Stats class."""
def __init__(self, output_file):
self.output_file = output_file
self.obj = Stats(output_file)
self.reset_stream()
def reset_stream(self):
self.obj.stream = StringIO()
def read(self):
value = self.obj.stream.getvalue()
self.reset_stream()
# process stats output
value = self._process_header(value)
value = self._process_lines(value)
return value
IGNORE_FUNC_NAMES = ['function', '']
STATS_LINE_REGEX = r'(.*)\((.*)\)$'
HEADER_LINE_REGEX = r'ncalls|tottime|cumtime'
DEFAULT_SORT_ARG = 'cumulative'
SORT_ARGS = {
'ncalls': 'calls',
'tottime': 'time',
'cumtime': 'cumulative',
'filename': 'module',
'lineno': 'nfl',
}
@classmethod
def _process_header(cls, output):
result = []
lines = output.splitlines(True)
for idx, line in enumerate(lines):
match = re.search(cls.HEADER_LINE_REGEX, line)
if match:
for key, val in cls.SORT_ARGS.iteritems():
url_link = template(
"<a href='{{ url }}'>{{ key }}</a>",
url=get_href(SORT_KEY, val),
key=key)
line = line.replace(key, url_link)
lines[idx] = line
break
return ''.join(lines)
@classmethod
def _process_lines(cls, output):
lines = output.splitlines(True)
for idx, line in enumerate(lines):
match = re.search(cls.STATS_LINE_REGEX, line)
if match:
prefix = match.group(1)
func_name = match.group(2)
if func_name not in cls.IGNORE_FUNC_NAMES:
url_link = template(
"<a href='{{ url }}'>{{ func_name }}</a>",
url=get_href(FUNC_NAME_KEY, func_name),
func_name=func_name)
lines[idx] = template(
"{{ prefix }}({{ !url_link }})\n",
prefix=prefix, url_link=url_link)
return ''.join(lines)
def show(self, restriction=''):
self.obj.print_stats(restriction)
return self
def show_callers(self, func_name):
self.obj.print_callers(func_name)
return self
def show_callees(self, func_name):
self.obj.print_callees(func_name)
return self
def sort(self, sort=''):
sort = sort or self.DEFAULT_SORT_ARG
self.obj.sort_stats(sort)
return self
示例4: filter
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callees [as 别名]
def filter(self, execution_func, prof_arg=None):
# put thie imports here so the app doesn't choke if profiling
# is not present (this is a debug-only feature anyway)
import cProfile as profile
from pstats import Stats
tmpfile = tempfile.NamedTemporaryFile()
try:
file, line = prof_arg.split(":")
line, func = line.split("(")
func = func.strip(")")
except:
file = line = func = None
try:
profile.runctx("execution_func()", globals(), locals(), tmpfile.name)
out = StringIO()
stats = Stats(tmpfile.name, stream=out)
stats.sort_stats("time", "calls")
def parse_table(t, ncol):
table = []
for s in t:
t = [x for x in s.split(" ") if x]
if len(t) > 1:
table += [t[: ncol - 1] + [" ".join(t[ncol - 1 :])]]
return table
def cmp(n):
def _cmp(x, y):
return 0 if x[n] == y[n] else 1 if x[n] < y[n] else -1
return _cmp
if not file:
stats.print_stats()
stats_str = out.getvalue()
statdata = stats_str.split("\n")
headers = "\n".join(statdata[:6])
table = parse_table(statdata[6:], 6)
from r2.lib.pages import Profiling
res = Profiling(header=headers, table=table, path=request.path).render()
return [unicode(res)]
else:
query = "%s:%s" % (file, line)
stats.print_callees(query)
stats.print_callers(query)
statdata = out.getvalue()
data = statdata.split(query)
callee = data[2].split("->")[1].split("Ordered by")[0]
callee = parse_table(callee.split("\n"), 4)
callee.sort(cmp(1))
callee = [["ncalls", "tottime", "cputime"]] + callee
i = 4
while "<-" not in data[i] and i < len(data):
i += 1
caller = data[i].split("<-")[1]
caller = parse_table(caller.split("\n"), 4)
caller.sort(cmp(1))
caller = [["ncalls", "tottime", "cputime"]] + caller
from r2.lib.pages import Profiling
res = Profiling(header=prof_arg, caller=caller, callee=callee, path=request.path).render()
return [unicode(res)]
finally:
tmpfile.close()