本文整理匯總了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))
示例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)
示例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)
示例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)
示例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
示例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)