Python hotshot.Profile() Examples
The following are 30
code examples of hotshot.Profile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hotshot
, or try the search function
.
Example #1
Source File: prof.py From pdfminer3 with MIT License | 6 votes |
def prof_main(argv): import hotshot, hotshot.stats def usage(): print(('usage: %s module.function [args ...]' % argv[0])) return 100 args = argv[1:] if len(args) < 1: return usage() name = args.pop(0) prof = name+'.prof' i = name.rindex('.') (modname, funcname) = (name[:i], name[i+1:]) module = __import__(modname, fromlist=1) func = getattr(module, funcname) if args: args.insert(0, argv[0]) prof = hotshot.Profile(prof) prof.runcall(lambda : func(args)) prof.close() else: stats = hotshot.stats.load(prof) stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(1000) return
Example #2
Source File: stones.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def main(logfile): p = hotshot.Profile(logfile) benchtime, stones = p.runcall(test.pystone.pystones) p.close() print "Pystone(%s) time for %d passes = %g" % \ (test.pystone.__version__, test.pystone.LOOPS, benchtime) print "This machine benchmarks at %g pystones/second" % stones stats = hotshot.stats.load(logfile) stats.strip_dirs() stats.sort_stats('time', 'calls') try: stats.print_stats(20) except IOError, e: if e.errno != errno.EPIPE: raise
Example #3
Source File: hotshotmain.py From datafari with Apache License 2.0 | 6 votes |
def run_hotshot(filename, profile, args): prof = hotshot.Profile(profile) sys.path.insert(0, os.path.dirname(filename)) sys.argv = [filename] + args prof.run("execfile(%r)" % filename) prof.close() stats = hotshot.stats.load(profile) stats.sort_stats("time", "calls") # print_stats uses unadorned print statements, so the only way # to force output to stderr is to reassign sys.stdout temporarily save_stdout = sys.stdout sys.stdout = sys.stderr stats.print_stats() sys.stdout = save_stdout return 0
Example #4
Source File: tool.py From sequitur-g2p with GNU General Public License v2.0 | 6 votes |
def runMain(main, options, args): if options.profile: if True: import hotshot profile = hotshot.Profile(options.profile) profile.runcall(main, options, args) profile.close() import hotshot.stats stats = hotshot.stats.load(options.profile) else: import profile profile.run('main(options, args)', options.profile) import pstats stats = pstats.Stats(options.profile) stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(20) elif options.psyco: import psyco psyco.full() status = main(options, args) else: status = main(options, args) return status
Example #5
Source File: profilehooks.py From pyFileFixity with MIT License | 6 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" fn = self.fn timer = self.timer self.ncalls += 1 try: start = timer() 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 sys.stderr.write("\n %s (%s:%s):\n %.3f seconds\n\n" % ( funcname, filename, lineno, duration)) sys.stderr.flush()
Example #6
Source File: stones.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def main(logfile): p = hotshot.Profile(logfile) benchtime, stones = p.runcall(test.pystone.pystones) p.close() print "Pystone(%s) time for %d passes = %g" % \ (test.pystone.__version__, test.pystone.LOOPS, benchtime) print "This machine benchmarks at %g pystones/second" % stones stats = hotshot.stats.load(logfile) stats.strip_dirs() stats.sort_stats('time', 'calls') try: stats.print_stats(20) except IOError, e: if e.errno != errno.EPIPE: raise
Example #7
Source File: profilehooks.py From verge3d-blender-addon with GNU General Public License v3.0 | 6 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" self.ncalls += 1 if self.skip > 0: self.skip -= 1 self.skipped += 1 return self.fn(*args, **kw) if FuncProfile.in_profiler: # handle recursive calls return self.fn(*args, **kw) # You cannot reuse the same profiler for many calls and accumulate # stats that way. :-/ profiler = self.Profile() try: FuncProfile.in_profiler = True return profiler.runcall(self.fn, *args, **kw) finally: FuncProfile.in_profiler = False self.stats.add(profiler) if self.immediate: self.print_stats() self.reset_stats()
Example #8
Source File: profilehooks.py From pyFileFixity with MIT License | 6 votes |
def __init__(self, fn, skip=0, filename=None): """Creates a profiler for a function. Every profiler has its own log file (the name of which is derived from the function name). HotShotFuncProfile registers an atexit handler that prints profiling information to sys.stderr when the program terminates. The log file is not removed and remains there to clutter the current working directory. """ self.fn = fn self.filename = filename if self.filename: self.logfilename = filename + ".raw" else: self.logfilename = fn.__name__ + ".prof" self.profiler = hotshot.Profile(self.logfilename) self.ncalls = 0 self.skip = skip self.skipped = 0 atexit.register(self.atexit)
Example #9
Source File: profiler-hotshot.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def handler(req): ''' Handler that uses hotshot to store profile data. Stores profile data in PROFILE_DATA_DIR. Since hotshot has no way (that I know of) to append profile data to a single file, each request gets its own profile. The file names are in the format <url>.<n>.prof where <url> is the request path with "/" replaced by ".", and <n> is a timestamp with microseconds to prevent overwriting files. Use the gather_profile_stats.py script to gather these individual request profiles into aggregated profiles by request path. ''' profname = "%s.%.3f.prof" % (req.uri.strip("/").replace('/', '.'), time.time()) profname = os.path.join(PROFILE_DATA_DIR, profname) prof = hotshot.Profile(profname) return prof.runcall(ModPythonHandler(), req)
Example #10
Source File: profilehooks.py From pyFileFixity with MIT License | 6 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" self.ncalls += 1 if self.skip > 0: self.skip -= 1 self.skipped += 1 return self.fn(*args, **kw) if FuncProfile.in_profiler: # handle recursive calls return self.fn(*args, **kw) # You cannot reuse the same profiler for many calls and accumulate # stats that way. :-/ profiler = self.Profile() try: FuncProfile.in_profiler = True return profiler.runcall(self.fn, *args, **kw) finally: FuncProfile.in_profiler = False self.stats.add(profiler) if self.immediate: self.print_stats() self.reset_stats()
Example #11
Source File: profiler.py From darkc0de-old-stuff with GNU General Public License v3.0 | 6 votes |
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)
Example #12
Source File: stones.py From oss-ftp with MIT License | 6 votes |
def main(logfile): p = hotshot.Profile(logfile) benchtime, stones = p.runcall(test.pystone.pystones) p.close() print "Pystone(%s) time for %d passes = %g" % \ (test.pystone.__version__, test.pystone.LOOPS, benchtime) print "This machine benchmarks at %g pystones/second" % stones stats = hotshot.stats.load(logfile) stats.strip_dirs() stats.sort_stats('time', 'calls') try: stats.print_stats(20) except IOError, e: if e.errno != errno.EPIPE: raise
Example #13
Source File: hotshotmain.py From oss-ftp with MIT License | 6 votes |
def run_hotshot(filename, profile, args): prof = hotshot.Profile(profile) sys.path.insert(0, os.path.dirname(filename)) sys.argv = [filename] + args prof.run("execfile(%r)" % filename) prof.close() stats = hotshot.stats.load(profile) stats.sort_stats("time", "calls") # print_stats uses unadorned print statements, so the only way # to force output to stderr is to reassign sys.stdout temporarily save_stdout = sys.stdout sys.stdout = sys.stderr stats.print_stats() sys.stdout = save_stdout return 0
Example #14
Source File: stones.py From Computable with MIT License | 6 votes |
def main(logfile): p = hotshot.Profile(logfile) benchtime, stones = p.runcall(test.pystone.pystones) p.close() print "Pystone(%s) time for %d passes = %g" % \ (test.pystone.__version__, test.pystone.LOOPS, benchtime) print "This machine benchmarks at %g pystones/second" % stones stats = hotshot.stats.load(logfile) stats.strip_dirs() stats.sort_stats('time', 'calls') try: stats.print_stats(20) except IOError, e: if e.errno != errno.EPIPE: raise
Example #15
Source File: stones.py From BinderFilter with MIT License | 6 votes |
def main(logfile): p = hotshot.Profile(logfile) benchtime, stones = p.runcall(test.pystone.pystones) p.close() print "Pystone(%s) time for %d passes = %g" % \ (test.pystone.__version__, test.pystone.LOOPS, benchtime) print "This machine benchmarks at %g pystones/second" % stones stats = hotshot.stats.load(logfile) stats.strip_dirs() stats.sort_stats('time', 'calls') try: stats.print_stats(20) except IOError, e: if e.errno != errno.EPIPE: raise
Example #16
Source File: profilehooks.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" self.ncalls += 1 if self.skip > 0: self.skip -= 1 self.skipped += 1 return self.fn(*args, **kw) if FuncProfile.in_profiler: # handle recursive calls return self.fn(*args, **kw) # You cannot reuse the same profiler for many calls and accumulate # stats that way. :-/ profiler = self.Profile() try: FuncProfile.in_profiler = True return profiler.runcall(self.fn, *args, **kw) finally: FuncProfile.in_profiler = False self.stats.add(profiler) if self.immediate: self.print_stats() self.reset_stats()
Example #17
Source File: stones.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def main(logfile): p = hotshot.Profile(logfile) benchtime, stones = p.runcall(test.pystone.pystones) p.close() print "Pystone(%s) time for %d passes = %g" % \ (test.pystone.__version__, test.pystone.LOOPS, benchtime) print "This machine benchmarks at %g pystones/second" % stones stats = hotshot.stats.load(logfile) stats.strip_dirs() stats.sort_stats('time', 'calls') try: stats.print_stats(20) except IOError, e: if e.errno != errno.EPIPE: raise
Example #18
Source File: profilehooks.py From verge3d-blender-addon with GNU General Public License v3.0 | 6 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" self.ncalls += 1 if self.skip > 0: self.skip -= 1 self.skipped += 1 return self.fn(*args, **kw) if HotShotFuncProfile.in_profiler: # handle recursive calls return self.fn(*args, **kw) if self.profiler is None: self.profiler = hotshot.Profile(self.logfilename) try: HotShotFuncProfile.in_profiler = True return self.profiler.runcall(self.fn, *args, **kw) finally: HotShotFuncProfile.in_profiler = False if self.immediate: self.print_stats() self.reset_stats()
Example #19
Source File: hotshotmain.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def run_hotshot(filename, profile, args): prof = hotshot.Profile(profile) sys.path.insert(0, os.path.dirname(filename)) sys.argv = [filename] + args prof.run("execfile(%r)" % filename) prof.close() stats = hotshot.stats.load(profile) stats.sort_stats("time", "calls") # print_stats uses unadorned print statements, so the only way # to force output to stderr is to reassign sys.stdout temporarily save_stdout = sys.stdout sys.stdout = sys.stderr stats.print_stats() sys.stdout = save_stdout return 0
Example #20
Source File: profilehooks.py From verge3d-blender-addon with GNU General Public License v3.0 | 6 votes |
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()
Example #21
Source File: Performance.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def runTest(self): self.prof = hotshot.Profile('%s.prof' % self.__class__.__name__) self.prof.start() for i in range(self.iterations): if hasattr(self, 'performanceSample'): self.display = True self.performanceSample() self.prof.stop() self.prof.close() if self.display: print('>>> %s (%d iterations) ' % (self.__class__.__name__, self.iterations)) stats = hotshot.stats.load('%s.prof' % self.__class__.__name__) #stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(50) if not self.save: os.unlink('%s.prof' % self.__class__.__name__)
Example #22
Source File: profilehooks.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" fn = self.fn timer = self.timer self.ncalls += 1 try: start = timer() return fn(*args, **kw) finally: duration = timer() - start self.totaltime += duration if self.immediate: funcname = fn.__name__ filename = fn.func_code.co_filename lineno = fn.func_code.co_firstlineno print >> sys.stderr, "\n %s (%s:%s):\n %.3f seconds\n" % ( funcname, filename, lineno, duration)
Example #23
Source File: profilehooks.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def __init__(self, fn, skip=0, filename=None): """Creates a profiler for a function. Every profiler has its own log file (the name of which is derived from the function name). HotShotFuncProfile registers an atexit handler that prints profiling information to sys.stderr when the program terminates. The log file is not removed and remains there to clutter the current working directory. """ self.fn = fn self.filename = filename if self.filename: self.logfilename = filename + ".raw" else: self.logfilename = fn.__name__ + ".prof" self.profiler = hotshot.Profile(self.logfilename) self.ncalls = 0 self.skip = skip self.skipped = 0 atexit.register(self.atexit)
Example #24
Source File: stones.py From ironpython2 with Apache License 2.0 | 6 votes |
def main(logfile): p = hotshot.Profile(logfile) benchtime, stones = p.runcall(test.pystone.pystones) p.close() print "Pystone(%s) time for %d passes = %g" % \ (test.pystone.__version__, test.pystone.LOOPS, benchtime) print "This machine benchmarks at %g pystones/second" % stones stats = hotshot.stats.load(logfile) stats.strip_dirs() stats.sort_stats('time', 'calls') try: stats.print_stats(20) except IOError, e: if e.errno != errno.EPIPE: raise
Example #25
Source File: test_hotshot.py From medicare-demo with Apache License 2.0 | 5 votes |
def new_profiler(self, lineevents=0, linetimings=1): self.logfn = test_support.TESTFN return hotshot.Profile(self.logfn, lineevents, linetimings)
Example #26
Source File: profilehooks.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" self.ncalls += 1 if self.skip > 0: self.skip -= 1 self.skipped += 1 return self.fn(*args, **kw) if HotShotFuncProfile.in_profiler: # handle recursive calls return self.fn(*args, **kw) try: HotShotFuncProfile.in_profiler = True return self.profiler.runcall(self.fn, *args, **kw) finally: HotShotFuncProfile.in_profiler = False
Example #27
Source File: profilehooks.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def __call__(self, *args, **kw): """Profile a singe call to the function.""" self.ncalls += 1 return self.profiler.runcall(self.fn, args, kw)
Example #28
Source File: bench.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def OtherTest(): print "Doing hotshot test" import hotshot import hotshot.stats prof = hotshot.Profile("stones.prof") benchtime = prof.runcall(Tester) stats = hotshot.stats.load("stones.prof") stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(20)
Example #29
Source File: BTAppController.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def listen_forever(self): pool = NSAutoreleasePool.alloc().init() # XXX #self.profile = Profile("BT.prof");self.profile.start() self.rawserver = RawServer(self.config) self.mt = MultiTorrent(self.config, self.doneflag, self.rawserver, self.multi_errorfunc, self.config['data_dir']) self.rawserver.ident = thread.get_ident() self.mt.set_option("max_upload_rate", self.config['max_upload_rate'] * 1024) self.rawserver.listen_forever(self.doneflag) #self.profile.stop();self.profile.close()
Example #30
Source File: profilehooks.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def reset_stats(self): """Reset accumulated profiler statistics.""" # Note: not using self.Profile, since pstats.Stats() fails then self.stats = pstats.Stats(Profile()) self.ncalls = 0 self.skipped = 0