當前位置: 首頁>>代碼示例>>Python>>正文


Python stats.load方法代碼示例

本文整理匯總了Python中hotshot.stats.load方法的典型用法代碼示例。如果您正苦於以下問題:Python stats.load方法的具體用法?Python stats.load怎麽用?Python stats.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hotshot.stats的用法示例。


在下文中一共展示了stats.load方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: gather_stats

# 需要導入模塊: from hotshot import stats [as 別名]
# 或者: from hotshot.stats import load [as 別名]
def gather_stats(p):
    profiles = {}
    for f in os.listdir(p):
        if f.endswith('.agg.prof'):
            path = f[:-9]
            prof = pstats.Stats(os.path.join(p, f))
        elif f.endswith('.prof'):
            bits = f.split('.')
            path = ".".join(bits[:-3])
            prof = stats.load(os.path.join(p, f))
        else:
            continue
        print("Processing %s" % f)
        if path in profiles:
            profiles[path].add(prof)
        else:
            profiles[path] = prof
        os.unlink(os.path.join(p, f))
    for (path, prof) in profiles.items():
        prof.dump_stats(os.path.join(p, "%s.agg.prof" % path)) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:22,代碼來源:gather_profile_stats.py

示例2: runProfiler

# 需要導入模塊: from hotshot import stats [as 別名]
# 或者: from hotshot.stats import load [as 別名]
def runProfiler(logger, func, args=tuple(), kw={}, verbose=True, nb_func=25, sort_by=('cumulative', 'calls')):
    profile_filename = "/tmp/profiler"
    prof = Profile(profile_filename)
    try:
        logger.warning("Run profiler")
        result = prof.runcall(func, *args, **kw)
        prof.close()
        logger.error("Profiler: Process data...")
        stat = loadStats(profile_filename)
        stat.strip_dirs()
        stat.sort_stats(*sort_by)

        logger.error("Profiler: Result:")
        log = StringIO()
        stat.stream = log
        stat.print_stats(nb_func)
        log.seek(0)
        for line in log:
            logger.error(line.rstrip())
        return result
    finally:
        unlink(profile_filename) 
開發者ID:tuwid,項目名稱:darkc0de-old-stuff,代碼行數:24,代碼來源:profiler.py

示例3: test_load_stats

# 需要導入模塊: from hotshot import stats [as 別名]
# 或者: from hotshot.stats import load [as 別名]
def test_load_stats(self):
        def start(prof):
            prof.start()
        # Make sure stats can be loaded when start and stop of profiler
        # are not executed in the same stack frame.
        profiler = self.new_profiler()
        start(profiler)
        profiler.stop()
        profiler.close()
        stats.load(self.logfn)
        os.unlink(self.logfn) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_hotshot.py

示例4: begin

# 需要導入模塊: from hotshot import stats [as 別名]
# 或者: from hotshot.stats import load [as 別名]
def begin(self):
        """Create profile stats file and load profiler.
        """
        if not self.available():
            return
        self._create_pfile()
        self.prof = hotshot.Profile(self.pfile) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:9,代碼來源:prof.py

示例5: report

# 需要導入模塊: from hotshot import stats [as 別名]
# 或者: from hotshot.stats import load [as 別名]
def report(self, stream):
        """Output profiler report.
        """
        log.debug('printing profiler report')
        self.prof.close()
        prof_stats = stats.load(self.pfile)
        prof_stats.sort_stats(self.sort)

        # 2.5 has completely different stream handling from 2.4 and earlier.
        # Before 2.5, stats objects have no stream attribute; in 2.5 and later
        # a reference sys.stdout is stored before we can tweak it.
        compat_25 = hasattr(prof_stats, 'stream')
        if compat_25:
            tmp = prof_stats.stream
            prof_stats.stream = stream
        else:
            tmp = sys.stdout
            sys.stdout = stream
        try:
            if self.restrict:
                log.debug('setting profiler restriction to %s', self.restrict)
                prof_stats.print_stats(*self.restrict)
            else:
                prof_stats.print_stats()
        finally:
            if compat_25:
                prof_stats.stream = tmp
            else:
                sys.stdout = tmp 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:31,代碼來源:prof.py

示例6: runProfiler

# 需要導入模塊: from hotshot import stats [as 別名]
# 或者: from hotshot.stats import load [as 別名]
def runProfiler(func, args=tuple(), kw={}, verbose=True, nb_func=25, sort_by=('cumulative', 'calls')):
    profile_filename = "/tmp/profiler"
    prof = Profile(profile_filename)
    try:
        if verbose:
            print "[+] Run profiler"
        result = prof.runcall(func, *args, **kw)
        prof.close()
        if verbose:
            print "[+] Stop profiler"
            print "[+] Process data..."
        stat = loadStats(profile_filename)
        if verbose:
            print "[+] Strip..."
        stat.strip_dirs()
        if verbose:
            print "[+] Sort data..."
        stat.sort_stats(*sort_by)
        if verbose:
            print
            print "[+] Display statistics"
            print
        stat.print_stats(nb_func)
        return result
    finally:
        unlink(profile_filename) 
開發者ID:Yukinoshita47,項目名稱:Yuki-Chan-The-Auto-Pentest,代碼行數:28,代碼來源:profiler.py


注:本文中的hotshot.stats.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。