當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。