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


Python hotshot.log方法代码示例

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


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

示例1: __init__

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def __init__(self, fn, skip=0, filename=None, immediate=False, dirs=False,
                 sort=None, entries=40, stdout=True):
        """Creates a profiler for a function.

        Every profiler has its own log file (the name of which is derived
        from the function name).

        FuncProfile registers an atexit handler that prints profiling
        information to sys.stderr when the program terminates.
        """
        self.fn = fn
        self.skip = skip
        self.filename = filename
        self._immediate = immediate
        self.stdout = stdout
        self.dirs = dirs
        self.sort = sort or ('cumulative', 'time', 'calls')
        if isinstance(self.sort, str):
            self.sort = (self.sort, )
        self.entries = entries
        self.reset_stats()
        if not self.immediate:
            atexit.register(self.atexit) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:25,代码来源:profilehooks.py

示例2: __call__

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def __call__(self, *args, **kw):
        """Profile a singe call to the function."""
        fn = self.fn
        timer = self.timer
        self.ncalls += 1
        start = timer()
        try:
            return fn(*args, **kw)
        finally:
            duration = timer() - start
            self.totaltime += duration
            if self.immediate:
                funcname = fn.__name__
                filename = fn.__code__.co_filename
                lineno = fn.__code__.co_firstlineno
                message = "%s (%s:%s):\n    %.3f seconds\n\n" % (
                    funcname, filename, lineno, duration,
                )
                if self.logger:
                    self.logger.log(self.log_level, message)
                else:
                    sys.stderr.write("\n  " + message)
                    sys.stderr.flush() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:25,代码来源:profilehooks.py

示例3: __init__

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def __init__(self, fn, skip=0, filename=None, immediate=False, dirs=False,
                 sort=None, entries=40):
        """Creates a profiler for a function.

        Every profiler has its own log file (the name of which is derived
        from the function name).

        FuncProfile registers an atexit handler that prints profiling
        information to sys.stderr when the program terminates.
        """
        self.fn = fn
        self.skip = skip
        self.filename = filename
        self.immediate = immediate
        self.dirs = dirs
        self.sort = sort or ('cumulative', 'time', 'calls')
        if isinstance(self.sort, str):
            self.sort = (self.sort, )
        self.entries = entries
        self.reset_stats()
        atexit.register(self.atexit) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:23,代码来源:profilehooks.py

示例4: atexit

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def atexit(self):
            """Stop profiling and print profile information to sys.stderr.

            This function is registered as an atexit hook.
            """
            self.profiler.close()
            funcname = self.fn.__name__
            filename = self.fn.__code__.co_filename
            lineno = self.fn.__code__.co_firstlineno
            print("")
            print("*** COVERAGE RESULTS ***")
            print("%s (%s:%s)" % (funcname, filename, lineno))
            print("function called %d times" % self.ncalls)
            print("")
            fs = FuncSource(self.fn)
            reader = hotshot.log.LogReader(self.logfilename)
            for what, (filename, lineno, funcname), tdelta in reader:
                if filename != fs.filename:
                    continue
                if what == hotshot.log.LINE:
                    fs.mark(lineno)
                if what == hotshot.log.ENTER:
                    # hotshot gives us the line number of the function
                    # definition and never gives us a LINE event for the first
                    # statement in a function, so if we didn't perform this
                    # mapping, the first statement would be marked as never
                    # executed
                    if lineno == fs.firstlineno:
                        lineno = fs.firstcodelineno
                    fs.mark(lineno)
            reader.close()
            print(fs)
            never_executed = fs.count_never_executed()
            if never_executed:
                print("%d lines were not executed." % never_executed) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:37,代码来源:profilehooks.py

示例5: load

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def load(self):
        # The timer selected by the profiler should never be used, so make
        # sure it doesn't work:
        p = Profile()
        p.get_time = _brokentimer
        log = hotshot.log.LogReader(self._logfn)
        taccum = 0
        for event in log:
            what, (filename, lineno, funcname), tdelta = event
            if tdelta > 0:
                taccum += tdelta

            # We multiply taccum to convert from the microseconds we
            # have to the seconds that the profile/pstats module work
            # with; this allows the numbers to have some basis in
            # reality (ignoring calibration issues for now).

            if what == ENTER:
                frame = self.new_frame(filename, lineno, funcname)
                p.trace_dispatch_call(frame, taccum * .000001)
                taccum = 0

            elif what == EXIT:
                frame = self.pop_frame()
                p.trace_dispatch_return(frame, taccum * .000001)
                taccum = 0

            # no further work for line events

        assert not self._stack
        return pstats.Stats(p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:stats.py

示例6: atexit

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def atexit(self):
            """Stop profiling and print profile information to sys.stderr.

            This function is registered as an atexit hook.
            """
            self.profiler.close()
            funcname = self.fn.__name__
            filename = self.fn.__code__.co_filename
            lineno = self.fn.__code__.co_firstlineno
            print("")
            print("*** COVERAGE RESULTS ***")
            print("%s (%s:%s)" % (funcname, filename, lineno))
            print("function called %d times" % self.ncalls)
            print("")
            fs = FuncSource(self.fn)
            reader = hotshot.log.LogReader(self.logfilename)
            for what, (filename, lineno, funcname), tdelta in reader:
                if filename != fs.filename:
                    continue
                if what == hotshot.log.LINE:
                    fs.mark(lineno)
                if what == hotshot.log.ENTER:
                    # hotshot gives us the line number of the function definition
                    # and never gives us a LINE event for the first statement in
                    # a function, so if we didn't perform this mapping, the first
                    # statement would be marked as never executed
                    if lineno == fs.firstlineno:
                        lineno = fs.firstcodelineno
                    fs.mark(lineno)
            reader.close()
            print(fs) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:33,代码来源:profilehooks.py

示例7: __init__

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def __init__(self, logfn):
        self.__logfn = logfn
        hotshot.log.LogReader.__init__(self, logfn) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:5,代码来源:test_hotshot.py

示例8: next

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def next(self, index=None):
        try:
            return hotshot.log.LogReader.next(self)
        except StopIteration:
            self.close()
            os.unlink(self.__logfn)
            raise 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:9,代码来源:test_hotshot.py

示例9: test_addinfo

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def test_addinfo(self):
        def f(p):
            p.addinfo("test-key", "test-value")
        profiler = self.new_profiler()
        profiler.runcall(f, profiler)
        profiler.close()
        log = self.get_logreader()
        info = log._info
        list(log)
        self.failUnless(info["test-key"] == ["test-value"]) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:12,代码来源:test_hotshot.py

示例10: atexit

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import log [as 别名]
def atexit(self):
            """Stop profiling and print profile information to sys.stderr.

            This function is registered as an atexit hook.
            """
            self.profiler.close()
            funcname = self.fn.__name__
            filename = self.fn.func_code.co_filename
            lineno = self.fn.func_code.co_firstlineno
            print
            print "*** COVERAGE RESULTS ***"
            print "%s (%s:%s)" % (funcname, filename, lineno)
            print "function called %d times" % self.ncalls
            print
            fs = FuncSource(self.fn)
            reader = hotshot.log.LogReader(self.logfilename)
            for what, (filename, lineno, funcname), tdelta in reader:
                if filename != fs.filename:
                    continue
                if what == hotshot.log.LINE:
                    fs.mark(lineno)
                if what == hotshot.log.ENTER:
                    # hotshot gives us the line number of the function definition
                    # and never gives us a LINE event for the first statement in
                    # a function, so if we didn't perform this mapping, the first
                    # statement would be marked as never executed
                    if lineno == fs.firstlineno:
                        lineno = fs.firstcodelineno
                    fs.mark(lineno)
            reader.close()
            print fs 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:33,代码来源:profilehooks.py


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