当前位置: 首页>>代码示例>>Python>>正文


Python Stats.print_callers方法代码示例

本文整理汇总了Python中pstats.Stats.print_callers方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.print_callers方法的具体用法?Python Stats.print_callers怎么用?Python Stats.print_callers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pstats.Stats的用法示例。


在下文中一共展示了Stats.print_callers方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print_stats

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callers [as 别名]
def print_stats(profiler, printCallers=False):
    from pstats import Stats
    
    stats = Stats(profiler)
    stats.strip_dirs()
    stats.sort_stats('cumulative')
    
    if printCallers is True:
        stats.print_callers()
    else:    
        stats.print_stats()
开发者ID:,项目名称:,代码行数:13,代码来源:

示例2: filter

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callers [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()
开发者ID:JediWatchman,项目名称:reddit,代码行数:83,代码来源:middleware.py

示例3: Stats

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callers [as 别名]
"""
Created on Jan 13, 2014

@Company: PBS Biotech
@Author: Nathan Starkweather
"""

from pstats import Stats

stats_file = "C:\\Users\\PBS Biotech\\Documents\\Personal\\PBS_Office\\MSOffice\\officelib\\pbslib\\test\\profile2.txt"

from datetime import datetime

s = Stats(stats_file)
s.strip_dirs()
s.sort_stats('time')

s.print_callers(0.1)


开发者ID:nitetrain8,项目名称:pbslib,代码行数:20,代码来源:profileorsomething.py

示例4: CProfileVStats

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callers [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
开发者ID:virtuald,项目名称:cprofilev,代码行数:87,代码来源:cprofilev.py

示例5: Profile

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callers [as 别名]
# from cProfile import Profile
# profiler = Profile()
# profiler.runcall(test)

# import sys
# from pstats import Stats
# stats = Stats(profiler)
# stats.strip_dirs()
# stats.sort_stats('cumulative')
# stats.print_stats()

# 
from bisect import bisect_left
def insert_value(array, value):
	i = bisect_left(array, value)
	array.insert(i, value)


from cProfile import Profile
profiler = Profile()
profiler.runcall(test)

import sys
from pstats import Stats
stats = Stats(profiler)
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats()
stats.print_callers()
开发者ID:kji0205,项目名称:py,代码行数:31,代码来源:bw58.py

示例6: filter

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callers [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()
开发者ID:rajbot,项目名称:tikical,代码行数:70,代码来源:middleware.py

示例7: range

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_callers [as 别名]
    for i in range(100):
        c += a * b

def first_func():
    for _ in range(1000):
        my_utility(4, 5)

def second_func():
    for _ in range(10):
        my_utility(1, 3)

def my_program():
    for _ in range(20):
        first_func()
        second_func()


profiler = Profile()
profiler.runcall(my_program)
stats = Stats(profiler, stream=STDOUT)
stats.strip_dirs()
stats.sort_stats('cumulative')
print('함수 테스트')
stats.print_stats()


stats = Stats(profiler, stream=STDOUT)
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_callers() # 호출된 함수를 왼쪽에 보여주고, 누가 호출하는지를 오른쪽에 보여준다
开发者ID:JoshuaSangwook,项目名称:EffectivePython,代码行数:32,代码来源:bw58_profile.py


注:本文中的pstats.Stats.print_callers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。