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 "*** PROFILER RESULTS ***" print "%s (%s:%s)" % (funcname, filename, lineno) print "function called %d times" % self.ncalls, if self.skipped: print "(%d calls not profiled)" % self.skipped else: print print stats = hotshot.stats.load(self.logfilename) if self.filename: stats.dump_stats(self.filename) stats.strip_dirs() stats.sort_stats('cumulative', 'time', 'calls') stats.print_stats(40)
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 "*** PROFILER RESULTS ***" print "{0!s} ({1!s}:{2!s})".format(funcname, filename, lineno) print "function called {0:d} times".format(self.ncalls), if self.skipped: print "({0:d} calls not profiled)".format(self.skipped) else: print print stats = hotshot.stats.load(self.logfilename) # hotshot.stats.load takes ages, and the .prof file eats megabytes, but # a saved stats object is small and fast if self.filename: stats.dump_stats(self.filename) # it is best to save before strip_dirs stats.strip_dirs() stats.sort_stats('cumulative', 'time', 'calls') stats.print_stats(40)
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("*** PROFILER RESULTS ***") print("%s (%s:%s)" % (funcname, filename, lineno)) if self.skipped: skipped = "(%d calls not profiled)" % self.skipped else: skipped = "" print("function called %d times%s" % (self.ncalls, skipped)) print("") stats = hotshot.stats.load(self.logfilename) # hotshot.stats.load takes ages, and the .prof file eats megabytes, but # a saved stats object is small and fast if self.filename: stats.dump_stats(self.filename) # it is best to save before strip_dirs stats.strip_dirs() stats.sort_stats('cumulative', 'time', 'calls') stats.print_stats(40)
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("*** PROFILER RESULTS ***") print(("%s (%s:%s)" % (funcname, filename, lineno))) if self.skipped: skipped = "(%d calls not profiled)" % self.skipped else: skipped = "" print(("function called %d times%s" % (self.ncalls, skipped))) print("") stats = hotshot.stats.load(self.logfilename) # hotshot.stats.load takes ages, and the .prof file eats megabytes, but # a saved stats object is small and fast if self.filename: stats.dump_stats(self.filename) # it is best to save before strip_dirs stats.strip_dirs() stats.sort_stats('cumulative', 'time', 'calls') stats.print_stats(40)
def load_hotshot_profile(filename): import hotshot.stats stats = hotshot.stats.load(filename) pstats_path = os.path.splitext(filename)[0] + '.pstats' stats.dump_stats(pstats_path) bs = BrowseableStats(pstats_path) return bs
def show(file, call='cum', length=50): if file.endswith('stats'): stats = pstats.Stats(file) else: stats = hotshot.stats.load(file) stats.strip_dirs() stats.dump_stats('.'.join((os.path.splitext(file)[0], 'stats'))) if call == 'cum': cum(stats, int(length)) elif call == 'tot': calls(stats, int(length)) else: stats.sort_stats(call) stats.print_stats(int(length)) stats.print_callers(int(length)) stats.print_callees(int(length)) return stats
def load_sureshot_profile(filename, additional_io_functions=app_io_functions, additional_sys_paths=()): import sureshot io_functions = list(sureshot.default_io_functions) io_functions.extend(additional_io_functions) sys_lib_paths = list(sys.path) sys_lib_paths.extend(additional_sys_paths) function_normalizer = create_function_normalizer( additional_sys_paths, ignore_line_number=True) stats = sureshot.StatsLoader(filename).load( io_functions, function_normalizer) pstats_path = os.path.splitext(filename)[0] + '.pstats' stats.dump_stats(pstats_path) bs = BrowseableStats(pstats_path) bs.strip_dirs(additional_sys_paths) return bs
def print_stats(self): """Print profile information to sys.stdout.""" stats = self.stats if self.filename: stats.dump_stats(self.filename) if self.stdout: funcname, filename, lineno = _identify(self.fn) print("") print("*** PROFILER RESULTS ***") print("%s (%s:%s)" % (funcname, filename, lineno)) if self.skipped: skipped = " (%d calls not profiled)" % self.skipped else: skipped = "" print("function called %d times%s" % (self.ncalls, skipped)) print("") if not self.dirs: stats.strip_dirs() stats.sort_stats(*self.sort) stats.print_stats(self.entries)
def print_stats(self): """Print profile information to sys.stdout.""" funcname = self.fn.__name__ filename = self.fn.func_code.co_filename lineno = self.fn.func_code.co_firstlineno print print "*** PROFILER RESULTS ***" print "{0!s} ({1!s}:{2!s})".format(funcname, filename, lineno) print "function called {0:d} times".format(self.ncalls), if self.skipped: print "({0:d} calls not profiled)".format(self.skipped) else: print print stats = self.stats if self.filename: stats.dump_stats(self.filename) if not self.dirs: stats.strip_dirs() stats.sort_stats(*self.sort) stats.print_stats(self.entries)
def print_stats(self): """Print profile information to sys.stdout.""" funcname = self.fn.__name__ filename = self.fn.__code__.co_filename lineno = self.fn.__code__.co_firstlineno print("") print("*** PROFILER RESULTS ***") print("%s (%s:%s)" % (funcname, filename, lineno)) if self.skipped: skipped = "(%d calls not profiled)" % self.skipped else: skipped = "" print("function called %d times%s" % (self.ncalls, skipped)) print("") stats = self.stats if self.filename: stats.dump_stats(self.filename) if not self.dirs: stats.strip_dirs() stats.sort_stats(*self.sort) stats.print_stats(self.entries)
def print_stats(self): """Print profile information to sys.stdout.""" funcname = self.fn.__name__ filename = self.fn.func_code.co_filename lineno = self.fn.func_code.co_firstlineno print print "*** PROFILER RESULTS ***" print "%s (%s:%s)" % (funcname, filename, lineno) print "function called %d times" % self.ncalls, if self.skipped: print "(%d calls not profiled)" % self.skipped else: print print stats = self.stats if self.filename: stats.dump_stats(self.filename) if not self.dirs: stats.strip_dirs() stats.sort_stats(*self.sort) stats.print_stats(self.entries)
def run(statement, filename=None, sort=-1): import os, tempfile, hotshot, hotshot.stats logfd, logfn = tempfile.mkstemp() prof = hotshot.Profile(logfn) try: prof = prof.run(statement) except SystemExit: pass try: try: prof = prof.run(statement) except SystemExit: pass prof.close() finally: stats = hotshot.stats.load(logfn) stats.strip_dirs() stats.sort_stats(sort) if filename is not None: result = stats.dump_stats(filename) else: result = stats.print_stats() os.unlink(logfn) return result
res = res.replace(imagesBaseURL, imagesBaseSecureURL) res = res.replace(escapeHTMLForJS(imagesBaseURL), escapeHTMLForJS(imagesBaseSecureURL)) # destroy the context ContextManager.destroy() totalTime = (datetime.now() - self._startTime) textLog.append("%s : Request ended"%totalTime) # log request timing if profile and totalTime > timedelta(0, 1): rep = Config.getInstance().getTempDir() stats = hotshot.stats.load(proffilename) stats.strip_dirs() stats.sort_stats('cumulative', 'time', 'calls') stats.dump_stats(os.path.join(rep, "IndicoRequestProfile.log")) output = StringIO.StringIO() sys.stdout = output stats.print_stats(40) sys.stdout = sys.__stdout__ s = output.getvalue() f = file(os.path.join(rep, "IndicoRequest.log"), 'a+') f.write("--------------------------------\n") f.write("URL : " + self._req.construct_url(self._req.unparsed_uri) + "\n") f.write("%s : start request\n"%self._startTime) f.write("params:%s"%params) f.write("\n".join(textLog)) f.write("\n") f.write("retried : %d\n"%(10-retry)) f.write(s) f.write("--------------------------------\n\n")
import hotshot.stats import sys file_name = sys.argv[1] stats = hotshot.stats.load(file_name) stats.dump_stats(file_name+"_stats")