usenetbinary-newsreaderqnaptautullifanartsickbeardtvseriesplexswizzinembyseedboxtvdbnzbgetsubtitlewebuiquickboxtraktkodistabletvshows
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
953 B
33 lines
953 B
11 years ago
|
from hotshot import Profile
|
||
|
from hotshot.stats import load as loadStats
|
||
|
from os import unlink
|
||
|
|
||
7 years ago
|
|
||
|
def runProfiler(func, args=tuple(), kw={}, verbose=True, nb_func=25,
|
||
|
sort_by=('cumulative', 'calls')):
|
||
11 years ago
|
profile_filename = "/tmp/profiler"
|
||
|
prof = Profile(profile_filename)
|
||
|
try:
|
||
|
if verbose:
|
||
6 years ago
|
print('[+] Run profiler')
|
||
11 years ago
|
result = prof.runcall(func, *args, **kw)
|
||
|
prof.close()
|
||
|
if verbose:
|
||
6 years ago
|
print('[+] Stop profiler')
|
||
|
print('[+] Process data...')
|
||
11 years ago
|
stat = loadStats(profile_filename)
|
||
|
if verbose:
|
||
6 years ago
|
print('[+] Strip...')
|
||
11 years ago
|
stat.strip_dirs()
|
||
|
if verbose:
|
||
6 years ago
|
print('[+] Sort data...')
|
||
11 years ago
|
stat.sort_stats(*sort_by)
|
||
|
if verbose:
|
||
6 years ago
|
print('')
|
||
|
print('[+] Display statistics')
|
||
|
print('')
|
||
11 years ago
|
stat.print_stats(nb_func)
|
||
|
return result
|
||
|
finally:
|
||
|
unlink(profile_filename)
|