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)
def process_response(self, request, response): if (settings.DEBUG or request.user.is_superuser) \ and request.method == 'GET' and request.GET.get('prof', False): self.prof.close() out = StringIO.StringIO() old_stdout = sys.stdout sys.stdout = out obj_stats = stats.load(self.tmpfile) obj_stats.sort_stats('time', 'calls') obj_stats.print_stats() sys.stdout = old_stdout stats_str = out.getvalue() if response and response.content and stats_str: response.content = "<pre>" + stats_str + "</pre>" response.content = "\n".join(response.content.split("\n")[:40]) response.content += self.summary_for_files(stats_str) unlink(self.tmpfile) return response
def runTests(options): global GROUND_QUERY, SINGLE_TEST, DEBUG SINGLE_TEST = options.singleTest DEBUG = options.debug GROUND_QUERY = options.groundQuery suite = unittest.makeSuite(OwlTestSuite) if options.profile: #from profile import Profile from hotshot import Profile, stats p = Profile('fuxi.profile') #p = Profile() for i in range(options.runs): p.runcall(unittest.TextTestRunner(verbosity=5).run, suite) p.close() s = stats.load('fuxi.profile') # s=p.create_stats() s.strip_dirs() s.sort_stats('time', 'cumulative', 'pcalls') s.print_stats(.1) s.print_callers(.05) s.print_callees(.05) else: for i in range(options.runs): unittest.TextTestRunner(verbosity=5).run(suite)
def main(args): # process all files so the user can use wildcards like *.wav for input_file in args.files: output_file_w = input_file + "_w.png" output_file_s = input_file + "_s.jpg" this_args = (input_file, output_file_w, output_file_s, args.width, args.height, args.fft_size, progress_callback, args.color_scheme) print("processing file %s:\n\t" % input_file, end="") if not args.profile: try: create_wave_images(*this_args) except AudioProcessingException as e: print("Error running wav2png: %s" % e) else: from hotshot import stats import hotshot prof = hotshot.Profile("stats") prof.runcall(create_wave_images, *this_args) prof.close() print("\n---------- profiling information ----------\n") s = stats.load("stats") s.strip_dirs() s.sort_stats("time") s.print_stats(30) print("")
def report(self, stream): 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(stats, 'stream') if compat_25: tmp = prof_stats.stream 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: stats.stream = tmp else: sys.stdout = tmp
def runTests(options): if options is None: options = defaultOptions() global REASONING_STRATEGY, GROUND_QUERY, SINGLE_TEST, DEBUG SINGLE_TEST = options.singleTest DEBUG = options.debug GROUND_QUERY = options.groundQuery REASONING_STRATEGY = options.strategy suite = unittest.makeSuite(OwlTestSuite) if options.profile: # from profile import Profile from hotshot import Profile, stats p = Profile('fuxi.profile') # p = Profile() for i in range(options.runs): p.runcall(unittest.TextTestRunner(verbosity=5).run,suite) p.close() s = stats.load('fuxi.profile') # s = p.create_stats() s.strip_dirs() s.sort_stats('time','cumulative','pcalls') s.print_stats(.1) s.print_callers(.05) s.print_callees(.05) else: for i in range(options.runs): unittest.TextTestRunner(verbosity=5).run(suite)
def PlotRKProbabilityTime(param): """ Plots the CPU time in second to calculate the probability. @type param : physicsconstants @param param : set of physical parameters used to make the plot. @rtype : plot @return : generates the spectra plot """ import hotshot as hs import hotshot.stats as hstat import re prof = hs.Profile("RKprob.prof") E = np.arange(1.0,1000.0,50.0) Sun = bd.Sun() Ri = 0.01*Sun.Radius*param.km Rf = Sun.Radius*param.km track = Sun.track(Ri,Ri,Rf) fM2 = no.flavorM2(param) EE = 1.0*param.GeV benchtime = prof.runcall(no.AvgNeuProb_RK,1,EE,track,Sun,fM2,param) prof.close() print benchtime stat = hstat.load("RKprob.prof") stat.strip_dirs() stat.dump_stats('RKprob.stat') #re.match('calls',stat.print_stats(0)) stat.print_stats()
def runTests(options): if options is None: options = defaultOptions() global REASONING_STRATEGY, GROUND_QUERY, SINGLE_TEST, DEBUG SINGLE_TEST = options.singleTest DEBUG = True # options.debug GROUND_QUERY = options.groundQuery REASONING_STRATEGY = options.strategy suite = unittest.makeSuite(OwlTestSuite) print("NTests: {}".format(suite.countTestCases())) if options.profile: # from profile import Profile from hotshot import Profile, stats p = Profile('fuxi.profile') # p = Profile() for i in range(options.runs): p.runcall(unittest.TextTestRunner(verbosity=5).run, suite) p.close() s = stats.load('fuxi.profile') # s = p.create_stats() s.strip_dirs() s.sort_stats('time', 'cumulative', 'pcalls') s.print_stats(.1) s.print_callers(.05) s.print_callees(.05) else: for i in range(options.runs): unittest.TextTestRunner(verbosity=5).run(suite)
def profiling_decorator_func(*args, **kwargs): import hotshot prof = hotshot.Profile("hotshot_edi_stats") ret = prof.runcall(profiling_func,*args) prof.close() from hotshot import stats print "now printing stats..." s = stats.load("hotshot_edi_stats") s.sort_stats("time").print_stats(15) s.sort_stats("cum").print_stats(15) return ret
def profiling_decorator_func(*args, **kwargs): import hotshot prof = hotshot.Profile("hotshot_edi_stats") ret = prof.runcall(profiling_func, *args) prof.close() from hotshot import stats print "now printing stats..." s = stats.load("hotshot_edi_stats") s.sort_stats("time").print_stats(15) s.sort_stats("cum").print_stats(15) return ret
def profileTests(): from hotshot import Profile, stats p = Profile('rdflib-mysql.profile') p.runcall(testRun) p.close() s = stats.load('rdflib-mysql.profile') s.strip_dirs() s.sort_stats('time','cumulative','pcalls') #s.sort_stats('time','pcalls') s.print_stats(.1) s.print_callers(.1) s.print_callees(.1)
def profileTests(): from hotshot import Profile, stats p = Profile('rdflib-mysql.profile') p.runcall(testRun) p.close() s = stats.load('rdflib-mysql.profile') s.strip_dirs() s.sort_stats('time', 'cumulative', 'pcalls') #s.sort_stats('time','pcalls') s.print_stats(.1) s.print_callers(.1) s.print_callees(.1)
def run_with_profiling(func, name='hotshot_edi_stats'): """Used to run profiling call""" import hotshot from hotshot import stats prof = hotshot.Profile(name) # Runs the function prof.runcall(func) prof.close() # Shows the time sheet s = stats.load(name) s.sort_stats('time').print_stats()
def profile_dispatch(self, pfname, pdname, prname, sig): #{{{ res = [] prof = hotshot.Profile(pfname) prof.runcall(self.stub, sig) prof.close() stats = hsstats.load(pfname) with file(pdname, 'wb') as f: stats.dump_stats(prname) stats = pstats.Stats(prname, stream=f) stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats()
def run(): import sys from hotshot import stats if len(sys.argv) != 2: print __doc__ sys.exit() # Load and print stats s = stats.load(sys.argv[1]) s.strip_dirs() s.sort_stats('cumulative', 'time', 'calls') s.print_stats(40) s.print_callers(40)
def process_response(request, response): """Finish profiling and render the results.""" profiler = getattr(request, 'profiler', None) if profiler: profiler.close() params = request.REQUEST stats = hotshot_stats.load(request.statsfile.name) queries = connection.queries if params.get('show_queries', False) and \ params.get('show_stats', '1') == '1': response = display_queries(request, stats, queries) else: response = display_stats(request, stats, queries) return response
def testDefault(self): # {{{ """Simple profile""" res = [] prof = hotshot.Profile("data/general.prof") prof.runcall(self.stub, self.sig, res, res.append) prof.close() stats = hsstats.load("data/general.prof") with file("data/results.txt", "wb") as f: stats.dump_stats("data/general2.prof") stats = pstats.Stats("data/general2.prof", stream=f) stats.strip_dirs() stats.sort_stats("time", "calls") stats.print_stats()
def stats(self, filename, sortby='cumulative'): """stats(index) -> output of print_stats() for the given profile.""" from hotshot.stats import load s = load(os.path.join(self.path, filename)) s.strip_dirs() s.sort_stats(sortby) oldout = sys.stdout try: sys.stdout = sio = StringIO.StringIO() s.print_stats() finally: sys.stdout = oldout response = sio.getvalue() sio.close() return response
def open_project(app, filename, profile): if not profile: return app.open_project(filename) print 'profiling' import hotshot from hotshot import stats prof = hotshot.Profile("gazpacho.prof") prof.runcall(app.open_project, filename) prof.close() s = stats.load("gazpacho.prof") s.strip_dirs() s.sort_stats('time', 'calls') s.print_stats(25)
def runTests(profile=False): suite = unittest.makeSuite(OwlTestSuite) if profile: #from profile import Profile from hotshot import Profile, stats p = Profile('fuxi.profile') #p = Profile() p.runcall(unittest.TextTestRunner(verbosity=5).run,suite) p.close() s = stats.load('fuxi.profile') # s=p.create_stats() s.strip_dirs() s.sort_stats('time','cumulative','pcalls') s.print_stats(.1) s.print_callers(.05) s.print_callees(.05) else: unittest.TextTestRunner(verbosity=5).run(suite)
def get_profile_summary(self, id): """Returns the summary of top 10 time consuming functions and their callers. """ result = "" try: filename = self.get_profile_name(long(id)) prof = stats.load(filename) prof.sort_stats('time', 'calls') str = StrFile() sys.stdout = str prof.print_stats(10).print_callers(10) sys.stdout = sys.__stdout__ result = str.dumpAsString() except Exception, e: sys.stdout = sys.__stdout__ logging.error(e) result = 'Error getting profile summary %s' % id self.error = result
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))
def beforeSummaryReport(self, event): """Output profiling results""" # write prof output to stream class Stream: def write(self, *msg): for m in msg: event.stream.write(m) event.stream.write(' ') event.stream.flush() stream = Stream() self.prof.close() prof_stats = stats.load(self.pfile) prof_stats.sort_stats(self.sort) event.stream.writeln(util.ln("Profiling results")) tmp = prof_stats.stream prof_stats.stream = stream try: if self.restrict: prof_stats.print_stats(*self.restrict) else: prof_stats.print_stats() finally: prof_stats.stream = tmp self.prof.close() event.stream.writeln('') if self.clean: if self.fileno: try: os.close(self.fileno) except OSError: pass try: os.unlink(self.pfile) except OSError: pass
def beforeSummaryReport(self, event): """Output profiling results""" # write prof output to stream class Stream: def write(self, *msg): for m in msg: event.stream.write(m) event.stream.write(" ") event.stream.flush() stream = Stream() self.prof.close() prof_stats = stats.load(self.pfile) prof_stats.sort_stats(self.sort) event.stream.writeln(util.ln("Profiling results")) tmp = prof_stats.stream prof_stats.stream = stream try: if self.restrict: prof_stats.print_stats(*self.restrict) else: prof_stats.print_stats() finally: prof_stats.stream = tmp self.prof.close() event.stream.writeln("") if self.clean: if self.fileno: try: os.close(self.fileno) except OSError: pass try: os.unlink(self.pfile) except OSError: pass
def __init__(self, filename): self.outfile = None self.output_dir = 'html' self.output_htmlfile = 'index.html' self.callers_htmlfile = 'callers.html' self.callers_data = [] with open(filename, 'rb') as fp: dump = fp.read() self.tmpl = ENVIRON.get_template('main.html') self.callers_tmpl = ENVIRON.get_template('callers.html') if check_hotshot(dump[:20]): if not PY2: # TODO: xxx raise Exception('Not support for hotshot on Python3') self.prof = stats.load(filename) self.profile_datatype = "hotshot" if check_hotlinetimings(dump[102:108]): self.profline = log.LogReader(filename) self.tmplline = ENVIRON.get_template('hotshot-line.html') self.profile_datatype = "hotshot(line)" else: try: self.prof = Stats(filename) except ValueError as e: # TODO: xxx raise ValueError(filename) if check_cprofile(dump): self.profile_datatype = "cProfile" else: self.profile_datatype = "profile" self.filename = filename self.proftime = time.ctime(os.stat(filename).st_mtime) self.reporttime = time.ctime() self.outputtype = 'html' self.functions_number = 20 self.profiledata_count = 0
def __init__(self, args, reporter=None): self._rcfile = None self._plugins = [] preprocess_options( args, { # option: (callback, takearg) 'rcfile': (self.cb_set_rcfile, True), 'load-plugins': (self.cb_add_plugins, True), }) self.linter = linter = self.LinterClass( ( ('rcfile', { 'action': 'callback', 'callback': lambda *args: 1, 'type': 'string', 'metavar': '<file>', 'help': 'Specify a configuration file.' }), ('init-hook', { 'action': 'callback', 'type': 'string', 'metavar': '<code>', 'callback': cb_init_hook, 'help': 'Python code to execute, usually for sys.path \ manipulation such as pygtk.require().' }), ('help-msg', { 'action': 'callback', 'type': 'string', 'metavar': '<msg-id>', 'callback': self.cb_help_message, 'group': 'Commands', 'help': '''Display a help message for the given message id and \ exit. The value may be a comma separated list of message ids.''' }), ('list-msgs', { 'action': 'callback', 'metavar': '<msg-id>', 'callback': self.cb_list_messages, 'group': 'Commands', 'help': "Generate pylint's messages." }), ('full-documentation', { 'action': 'callback', 'metavar': '<msg-id>', 'callback': self.cb_full_documentation, 'group': 'Commands', 'help': "Generate pylint's full documentation." }), ('generate-rcfile', { 'action': 'callback', 'callback': self.cb_generate_config, 'group': 'Commands', 'help': '''Generate a sample configuration file according to \ the current configuration. You can put other options before this one to get \ them in the generated configuration.''' }), ('generate-man', { 'action': 'callback', 'callback': self.cb_generate_manpage, 'group': 'Commands', 'help': "Generate pylint's man page.", 'hide': 'True' }), ('errors-only', { 'action': 'callback', 'callback': self.cb_error_mode, 'short': 'e', 'help': '''In error mode, checkers without error messages are \ disabled and for others, only the ERROR messages are displayed, and no reports \ are done by default''' }), ('profile', { 'type': 'yn', 'metavar': '<y_or_n>', 'default': False, 'help': 'Profiled execution.' }), ), option_groups=self.option_groups, reporter=reporter, pylintrc=self._rcfile) # register standard checkers from pylint import checkers checkers.initialize(linter) # load command line plugins linter.load_plugin_modules(self._plugins) # add some help section linter.add_help_section('Environment variables', config.ENV_HELP) linter.add_help_section( 'Output', ''' Using the default text output, the message format is : MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE There are 5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) fatal, if an error occurred which prevented pylint from doing further processing. ''') linter.add_help_section( 'Output status code', ''' Pylint should leave with following status code: * 0 if everything went fine * 1 if a fatal message was issued * 2 if an error message was issued * 4 if a warning message was issued * 8 if a refactor message was issued * 16 if a convention message was issued * 32 on usage error status 1 to 16 will be bit-ORed so you can know which different categories has been issued by analysing pylint output status code ''') # read configuration linter.disable_message('W0704') linter.read_config_file() # is there some additional plugins in the file configuration, in config_parser = linter._config_parser if config_parser.has_option('MASTER', 'load-plugins'): plugins = splitstrip(config_parser.get('MASTER', 'load-plugins')) linter.load_plugin_modules(plugins) # now we can load file config and command line, plugins (which can # provide options) have been registered linter.load_config_file() if reporter: # if a custom reporter is provided as argument, it may be overridden # by file parameters, so re-set it here, but before command line # parsing so it's still overrideable by command line option linter.set_reporter(reporter) args = linter.load_command_line_configuration(args) if not args: print linter.help() sys.exit(32) # insert current working directory to the python path to have a correct # behaviour sys.path.insert(0, os.getcwd()) if self.linter.config.profile: print >> sys.stderr, '** profiled run' from hotshot import Profile, stats prof = Profile('stones.prof') prof.runcall(linter.check, args) prof.close() data = stats.load('stones.prof') data.strip_dirs() data.sort_stats('time', 'calls') data.print_stats(30) else: linter.check(args) sys.path.pop(0) sys.exit(self.linter.msg_status)
#!/usr/bin/python # # THIS FILE IS PART OF THE JOKOSHER PROJECT AND LICENSED UNDER THE GPL. SEE # THE 'COPYING' FILE FOR DETAILS # # This module is meant for testing and profiling the code only. # This file should not be included in any release. # #------------------------------------------------------------------------------- import hotshot from hotshot import stats import JokosherApp profile = hotshot.Profile("JokosherApp", lineevents=1) profile.runcall(JokosherApp.main) s = stats.load("JokosherApp") s.strip_dirs() s.sort_stats("cumulative", "calls").print_stats() s.sort_stats("time", "calls").print_stats()
(orig_dt*1e6)) # third row if info.instrument.find("pigot") >= 0: instrument = "Spigot" else: instrument = info.instrument ppgplot.pgmtxt('T', -3.7, 0.02, 0.0, 'Instrument: %s'%instrument) if (info.bary): ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dbary\u: %.12f'%info.epoch) else: ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dtopo\u: %.12f'%info.epoch) ppgplot.pgmtxt('T', -3.7, 0.73, 0.0, 'Freq\dctr\u: %.1f MHz'%\ ((info.numchan/2-0.5)*info.chan_width+info.lofreq)) ppgplot.pgiden() ppgplot.pgend() if __name__ == '__main__': if (0): # The following is for profiling import hotshot prof = hotshot.Profile("hotshot_edi_stats") prof.runcall(main) prof.close() # To see the results: if (0): from hotshot import stats s = stats.load("hotshot_edi_stats") s.sort_stats("time").print_stats() else: main()
def __init__(self, args, reporter=None): self._rcfile = None self._plugins = [] preprocess_options( args, { # option: (callback, takearg) "rcfile": (self.cb_set_rcfile, True), "load-plugins": (self.cb_add_plugins, True), }, ) self.linter = linter = self.LinterClass( ( ( "rcfile", { "action": "callback", "callback": lambda *args: 1, "type": "string", "metavar": "<file>", "help": "Specify a configuration file.", }, ), ( "init-hook", { "action": "callback", "type": "string", "metavar": "<code>", "callback": cb_init_hook, "help": "Python code to execute, usually for sys.path \ manipulation such as pygtk.require().", }, ), ( "help-msg", { "action": "callback", "type": "string", "metavar": "<msg-id>", "callback": self.cb_help_message, "group": "Commands", "help": """Display a help message for the given message id and \ exit. The value may be a comma separated list of message ids.""", }, ), ( "list-msgs", { "action": "callback", "metavar": "<msg-id>", "callback": self.cb_list_messages, "group": "Commands", "help": "Generate pylint's full documentation.", }, ), ( "generate-rcfile", { "action": "callback", "callback": self.cb_generate_config, "group": "Commands", "help": """Generate a sample configuration file according to \ the current configuration. You can put other options before this one to get \ them in the generated configuration.""", }, ), ( "generate-man", { "action": "callback", "callback": self.cb_generate_manpage, "group": "Commands", "help": "Generate pylint's man page.", "hide": "True", }, ), ( "errors-only", { "action": "callback", "callback": self.cb_error_mode, "short": "e", "help": """In error mode, checkers without error messages are \ disabled and for others, only the ERROR messages are displayed, and no reports \ are done by default""", }, ), ("profile", {"type": "yn", "metavar": "<y_or_n>", "default": False, "help": "Profiled execution."}), ), option_groups=self.option_groups, reporter=reporter, pylintrc=self._rcfile, ) # register standard checkers checkers.initialize(linter) # load command line plugins linter.load_plugin_modules(self._plugins) # read configuration linter.disable_message("W0704") linter.read_config_file() # is there some additional plugins in the file configuration, in config_parser = linter._config_parser if config_parser.has_option("MASTER", "load-plugins"): plugins = splitstrip(config_parser.get("MASTER", "load-plugins")) linter.load_plugin_modules(plugins) # now we can load file config and command line, plugins (which can # provide options) have been registered linter.load_config_file() if reporter: # if a custom reporter is provided as argument, it may be overriden # by file parameters, so re-set it here, but before command line # parsing so it's still overrideable by command line option linter.set_reporter(reporter) args = linter.load_command_line_configuration(args) # insert current working directory to the python path to have a correct # behaviour sys.path.insert(0, os.getcwd()) if self.linter.config.profile: print >> sys.stderr, "** profiled run" from hotshot import Profile, stats prof = Profile("stones.prof") prof.runcall(linter.check, args) prof.close() data = stats.load("stones.prof") data.strip_dirs() data.sort_stats("time", "calls") data.print_stats(30) sys.path.pop(0)
def handle(self, *args, **options): self.stdout.write("Show profiler log file output..", ending='\n') _stats = stats.load(args[0]) _stats.sort_stats('time', 'calls') _stats.print_stats(20)
for input_file in args: output_file_w = options.output_filename_w or input_file + "_w.png" output_file_s = options.output_filename_s or input_file + "_s.jpg" args = (input_file, output_file_w, output_file_s, options.image_width, options.image_height, options.fft_size, progress_callback) print "processing file %s:\n\t" % input_file, if not options.profile: try: create_wave_images(*args) except AudioProcessingException as e: print "Error running wav2png: ", e else: from hotshot import stats import hotshot prof = hotshot.Profile("stats") prof.runcall(create_wave_images, *args) prof.close() print "\n---------- profiling information ----------\n" s = stats.load("stats") s.strip_dirs() s.sort_stats("time") s.print_stats(30) print
def execute(self, line, previous_args): """ String/list handling as well as EOF and comment handling. Otherwise, parses the arguments as shlexed and runs the function returned by argparse. """ if isinstance(line, (str, unicode)): if COMMENT.match(line): return # EARLY EXIT! args = shlex.split(line) elif isinstance(line, (tuple, list)): args = list(line) else: self.die(1, "Bad argument type: %s ('%s')" % (type(line), line)) if not args: return elif args == ["EOF"]: self.exit("") return args = self.parser.parse_args(args, previous_args) args.prog = self.parser.prog self.waitForPlugins() debug_str = getattr(args, "debug", "") debug_opts = set([x.lower() for x in debug_str.split(",")]) if "" in debug_opts: debug_opts.remove("") old_debug = self.isdebug if "debug" in debug_opts: self.isdebug = 1 debug_opts.remove("debug") elif "0" in debug_opts: self.isdebug = 0 debug_opts.remove("0") for x in range(1, 9): if str(x) in debug_opts: self.isdebug = x debug_opts.remove(str(x)) try: if len(debug_opts) == 0: args.func(args) elif len(debug_opts) > 1: self.die(9, "Conflicting debug options: %s" % ", ".join(debug_opts)) elif "t" in debug_opts or "trace" in debug_opts: import trace tracer = trace.Trace() tracer.runfunc(args.func, args) elif "p" in debug_opts or "profile" in debug_opts: import hotshot from hotshot import stats prof = hotshot.Profile("hotshot_edi_stats") rv = prof.runcall( lambda: args.func(args) ) prof.close() s = stats.load("hotshot_edi_stats") s.sort_stats("time").print_stats() else: self.die(10, "Unknown debug action: %s" % debug_opts) finally: self.isdebug = old_debug
# ts_ax.xaxis.set_major_formatter(time_series_x_fmt) # ts_ax.legend() # time_filename = 'out/LMA-timeseries_%s_%5.2fkm_%5.1fs.pdf' % (start_time.strftime('%Y%m%d_%H%M%S'), dx/1000.0, time_delta.seconds) # time_series.savefig(time_filename) # print ' ... done' print 'making multiples', p.multiples.flat[0].axis(view_x+view_y) filename = 'out/LMA-density_%s_%5.2fkm_%5.1fs.pdf' % (start_time.strftime('%Y%m%d_%H%M%S'), dx/1000.0, time_delta.seconds) f.savefig(filename, dpi=150) print ' ... done' f.clf() return events if __name__ == '__main__': do_profile=True if do_profile: import hotshot from hotshot import stats prof = hotshot.Profile("multiples_test_profile") prof.runcall(runtest, HDFmanagers=HDFmanagers) prof.close() s=stats.load("multiples_test_profile") s.sort_stats("time").print_stats() else: if source_density: res = runtest(lmaManager=lmaManager, lma_view=lma_view) else: res = runtest(HDFmanagers=HDFmanagers)
from hotshot import stats s = stats.load("hotshot_stats") s.sort_stats("time").print_stats()
>>> s.print_stats(20) and a report will be displayed. For more information on generating profiler reports, see http://python.org/doc/current/lib/profile-stats.html or the 'pstats' module chapter of your Python manual. """ import sys from run_tests import ScanningLoader from unittest import main from hotshot import Profile from hotshot.stats import load if __name__ == '__main__': if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'): # XXX print __doc__ sys.exit(2) stats_file = "profile.dat" try: Profile(stats_file).run( "main(module=None, testLoader=ScanningLoader())") except SystemExit: # prevent unittest.main() from forcing an early exit pass s = load(stats_file) s.sort_stats("time") s.print_stats(10)
network.inferredFacts = network.filteredFacts if options.closure \ and options.output in RDF_SERIALIZATION_FORMATS: cGraph = network.closureGraph(factGraph) cGraph.namespace_manager = namespace_manager print(cGraph.serialize(destination=None, format=options.output, base=None)) elif options.output and options.output in RDF_SERIALIZATION_FORMATS: print(network.inferredFacts.serialize(destination=None, format=options.output, base=None)) if __name__ == '__main__': from hotshot import Profile, stats # import pycallgraph # pycallgraph.start_trace() # main() # pycallgraph.make_dot_graph('FuXi-timing.png') # sys.exit(1) p = Profile('fuxi.profile') p.runcall(main) p.close() s = stats.load('fuxi.profile') s.strip_dirs() s.sort_stats('time', 'cumulative', 'pcalls') s.print_stats(.05) s.print_callers(.01) s.print_callees(.01)
if options.closure and options.output in RDF_SERIALIZATION_FORMATS: cGraph = network.closureGraph(factGraph) cGraph.namespace_manager = namespace_manager print( cGraph.serialize(destination=None, format=options.output, base=None)) elif options.output and options.output in RDF_SERIALIZATION_FORMATS: print( network.inferredFacts.serialize(destination=None, format=options.output, base=None)) if __name__ == '__main__': from hotshot import Profile, stats # import pycallgraph # pycallgraph.start_trace() # main() # pycallgraph.make_dot_graph('FuXi-timing.png') # sys.exit(1) p = Profile('fuxi.profile') p.runcall(main) p.close() s = stats.load('fuxi.profile') s.strip_dirs() s.sort_stats('time', 'cumulative', 'pcalls') s.print_stats(.05) s.print_callers(.01) s.print_callees(.01)
def __init__(self, args, reporter=None): self._rcfile = None self._plugins = [] preprocess_options( args, { # option: (callback, takearg) 'rcfile': (self.cb_set_rcfile, True), 'load-plugins': (self.cb_add_plugins, True), }) self.linter = linter = self.LinterClass(( ('rcfile', { 'action': 'callback', 'callback': lambda *args: 1, 'type': 'string', 'metavar': '<file>', 'help': 'Specify a configuration file.' }), ('init-hook', { 'action': 'callback', 'type': 'string', 'metavar': '<code>', 'callback': cb_init_hook, 'help': 'Python code to execute, usually for sys.path \ manipulation such as pygtk.require().' }), ('help-msg', { 'action': 'callback', 'type': 'string', 'metavar': '<msg-id>', 'callback': self.cb_help_message, 'group': 'Commands', 'help': '''Display a help message for the given message id and \ exit. The value may be a comma separated list of message ids.''' }), ('list-msgs', { 'action': 'callback', 'metavar': '<msg-id>', 'callback': self.cb_list_messages, 'group': 'Commands', 'help': "Generate pylint's full documentation." }), ('generate-rcfile', { 'action': 'callback', 'callback': self.cb_generate_config, 'group': 'Commands', 'help': '''Generate a sample configuration file according to \ the current configuration. You can put other options before this one to get \ them in the generated configuration.''' }), ('generate-man', { 'action': 'callback', 'callback': self.cb_generate_manpage, 'group': 'Commands', 'help': "Generate pylint's man page.", 'hide': 'True' }), ('errors-only', { 'action': 'callback', 'callback': self.cb_error_mode, 'short': 'e', 'help': '''In error mode, checkers without error messages are \ disabled and for others, only the ERROR messages are displayed, and no reports \ are done by default''' }), ('profile', { 'type': 'yn', 'metavar': '<y_or_n>', 'default': False, 'help': 'Profiled execution.' }), ), option_groups=self. option_groups, reporter=reporter, pylintrc=self._rcfile) # register standard checkers checkers.initialize(linter) # load command line plugins linter.load_plugin_modules(self._plugins) # read configuration linter.disable_message('W0704') linter.read_config_file() # is there some additional plugins in the file configuration, in config_parser = linter._config_parser if config_parser.has_option('MASTER', 'load-plugins'): plugins = splitstrip( config_parser.get('MASTER', 'load-plugins')) linter.load_plugin_modules(plugins) # now we can load file config and command line, plugins (which can # provide options) have been registered linter.load_config_file() if reporter: # if a custom reporter is provided as argument, it may be overriden # by file parameters, so re-set it here, but before command line # parsing so it's still overrideable by command line option linter.set_reporter(reporter) args = linter.load_command_line_configuration(args) # insert current working directory to the python path to have a correct # behaviour sys.path.insert(0, os.getcwd()) if self.linter.config.profile: print('** profiled run', file=sys.stderr) from hotshot import Profile, stats prof = Profile('stones.prof') prof.runcall(linter.check, args) prof.close() data = stats.load('stones.prof') data.strip_dirs() data.sort_stats('time', 'calls') data.print_stats(30) sys.path.pop(0)
for u in unichars: f.write(u) f.close() def profile_decode_file(): f = codecs.open("/tmp/tmp.txt", "r", encoding='utf-16') s = f.read() f.close() f = open("/tmp/tmp.bin", 'wb') for chunk in gen_decode_bytes_from_string(s): for b in chunk: buf = struct.pack("B", b) f.write(buf) f.close() if __name__ == '__main__': for f in [profile_encode_file, profile_decode_file]: prof = hotshot.Profile("hotshot_stats.prof") prof.runcall(f) prof.close() s = stats.load("hotshot_stats.prof") s.strip_dirs() s.sort_stats('time', 'calls') s.print_stats(20)
instrument = "Spigot" else: instrument = info.instrument ppgplot.pgmtxt('T', -3.7, 0.02, 0.0, 'Instrument: %s' % instrument) if (info.bary): ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dbary\u: %.12f' % info.epoch) else: ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dtopo\u: %.12f' % info.epoch) ppgplot.pgmtxt('T', -3.7, 0.73, 0.0, 'Freq\dctr\u: %.1f MHz'%\ ((info.numchan/2-0.5)*info.chan_width+info.lofreq)) ppgplot.pgiden() ppgplot.pgend() if __name__ == '__main__': if (0): # The following is for profiling import hotshot prof = hotshot.Profile("hotshot_edi_stats") prof.runcall(main) prof.close() # To see the results: if (0): from hotshot import stats s = stats.load("hotshot_edi_stats") s.sort_stats("time").print_stats() else: main()
def __init__(self, args, reporter=None): self._rcfile = None self._plugins = [] preprocess_options(args, { # option: (callback, takearg) 'rcfile': (self.cb_set_rcfile, True), 'load-plugins': (self.cb_add_plugins, True), }) self.linter = linter = self.LinterClass(( ('rcfile', {'action' : 'callback', 'callback' : lambda *args: 1, 'type': 'string', 'metavar': '<file>', 'help' : 'Specify a configuration file.'}), ('init-hook', {'action' : 'callback', 'type' : 'string', 'metavar': '<code>', 'callback' : cb_init_hook, 'help' : 'Python code to execute, usually for sys.path \ manipulation such as pygtk.require().'}), ('help-msg', {'action' : 'callback', 'type' : 'string', 'metavar': '<msg-id>', 'callback' : self.cb_help_message, 'group': 'Commands', 'help' : '''Display a help message for the given message id and \ exit. The value may be a comma separated list of message ids.'''}), ('list-msgs', {'action' : 'callback', 'metavar': '<msg-id>', 'callback' : self.cb_list_messages, 'group': 'Commands', 'help' : "Generate pylint's full documentation."}), ('generate-rcfile', {'action' : 'callback', 'callback' : self.cb_generate_config, 'group': 'Commands', 'help' : '''Generate a sample configuration file according to \ the current configuration. You can put other options before this one to get \ them in the generated configuration.'''}), ('generate-man', {'action' : 'callback', 'callback' : self.cb_generate_manpage, 'group': 'Commands', 'help' : "Generate pylint's man page.",'hide': 'True'}), ('errors-only', {'action' : 'callback', 'callback' : self.cb_error_mode, 'short': 'e', 'help' : '''In error mode, checkers without error messages are \ disabled and for others, only the ERROR messages are displayed, and no reports \ are done by default'''}), ('profile', {'type' : 'yn', 'metavar' : '<y_or_n>', 'default': False, 'help' : 'Profiled execution.'}), ), option_groups=self.option_groups, reporter=reporter, pylintrc=self._rcfile) # register standard checkers from pylint import checkers checkers.initialize(linter) # load command line plugins linter.load_plugin_modules(self._plugins) # add some help section linter.add_help_section('Environment variables', config.ENV_HELP) linter.add_help_section('Output', ''' Using the default text output, the message format is : MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE There are 5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) fatal, if an error occured which prevented pylint from doing further \ processing. ''') linter.add_help_section('Output status code', ''' Pylint should leave with following status code: * 0 if everything went fine * 1 if some fatal message issued * 2 if some error message issued * 4 if some warning message issued * 8 if some refactor message issued * 16 if some convention message issued * 32 on usage error status 1 to 16 will be bit-ORed so you can know which different categories has been issued by analysing pylint output status code ''') # read configuration linter.disable_message('W0704') linter.read_config_file() # is there some additional plugins in the file configuration, in config_parser = linter._config_parser if config_parser.has_option('MASTER', 'load-plugins'): plugins = get_csv(config_parser.get('MASTER', 'load-plugins')) linter.load_plugin_modules(plugins) # now we can load file config and command line, plugins (which can # provide options) have been registered linter.load_config_file() if reporter: # if a custom reporter is provided as argument, it may be overriden # by file parameters, so re-set it here, but before command line # parsing so it's still overrideable by command line option linter.set_reporter(reporter) args = linter.load_command_line_configuration(args) if not args: print linter.help() sys.exit(32) # insert current working directory to the python path to have a correct # behaviour sys.path.insert(0, os.getcwd()) if self.linter.config.profile: print >> sys.stderr, '** profiled run' from hotshot import Profile, stats prof = Profile('stones.prof') prof.runcall(linter.check, args) prof.close() data = stats.load('stones.prof') data.strip_dirs() data.sort_stats('time', 'calls') data.print_stats(30) else: linter.check(args) sys.path.pop(0) sys.exit(self.linter.msg_status)
# shadow maps require bounded scene.... # TODO: maybe generating the bounds ? # TODO: SM: why y=50.0 ? (from nvidia sdk CSM example) td = 10.0 # bounding value from xml file... # TODO: SM: why 1.0? (from nvidia sdk CSM example) radius = 1.0 sceneBoundPoints = array( [ [-td, 50.0, -td, 1.0], [-td, 50.0, td, 1.0], [ td, 50.0, td, 1.0], [ td, 50.0, -td, 1.0] ], float32 ) app.setSceneBounds(sceneBoundPoints, radius) for m in models: app.addModel(m) m.create(app=app) if PROFILING: import hotshot from hotshot import stats prof = hotshot.Profile("appProfile") prof.runcall(app.mainloop) prof.close() print "loading statistics, this may take a while...." s = stats.load("appProfile") s.sort_stats("time").print_stats() else: app.mainloop()
"""script for digesting profiling output to profile functions, wrap them into decorator @profile('file_name.prof') source: http://code.djangoproject.com/wiki/ProfilingDjango """ import sys try: from pstats import Stats stats = Stats() except ImportError: from hotshot import stats _stats = stats.load(sys.argv[1]) # _stats.strip_dirs() _stats.sort_stats('time', 'calls') _stats.print_stats(20)
#!/usr/bin/env python import hotshot from hotshot.stats import load import os from TestCaseTask import DUMMY_TASK try: os.system("touch index.html") prof = hotshot.Profile("task.prof") prof.runcall(DUMMY_TASK.service) prof.close() finally: os.system("rm index.html") stats = load("task.prof") stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(20) os.system("rm task.prof")
''' Displays a report of a previous profile run ''' mode= 'cProfile' if mode == 'hotshot': from hotshot import stats s = stats.load("profiling_data_hotshot") s.sort_stats("time").print_stats() elif mode == 'cProfile': import pstats p = pstats.Stats('profiling_data_cProfile') p.sort_stats('time').print_stats(50) print '-' * 80 p.sort_stats('cumulative').print_stats(50) ## ## p.sort_stats('cumulative').print_callees('UpdateScene')
# process all files so the user can use wildcards like *.wav for input_file in args: output_file_w = options.output_filename_w or input_file + "_w.png" output_file_s = options.output_filename_s or input_file + "_s.jpg" args = (input_file, output_file_w, output_file_s, options.image_width, options.image_height, options.fft_size, progress_callback) print "processing file %s:\n\t" % input_file, if not options.profile: try: create_wave_images(*args) except AudioProcessingException, e: print "Error running wav2png: ", e else: from hotshot import stats import hotshot prof = hotshot.Profile("stats") prof.runcall(create_wave_images, *args) prof.close() print "\n---------- profiling information ----------\n" s = stats.load("stats") s.strip_dirs() s.sort_stats("time") s.print_stats(30) print
# Wait until end of frame or skip frame turn_actions = get_turn_actions() if turn_actions >= 2: frame_loc += 1 vframe += 1 game_context.draw() frame += 1 total_time = pygame.time.get_ticks() - first_ticks l.info("Total game time : %d min, %d sec, %d ms"\ %(total_time / 60000,(total_time / 1000) % 60,total_time % 1000)) l.info("Total wait time : %d min, %d sec, %d ms, ie %f percent of the time"\ %(total_wait_time / 60000,(total_wait_time / 1000) % 60,total_wait_time % 1000,100*float(total_wait_time)/total_time)) l.info("Gameplay fps : " + str(float(frame)/(pygame.time.get_ticks()-first_ticks)*1000)) l.info("Graphical fps : " + str(float(vframe)/(pygame.time.get_ticks()-first_ticks)*1000)) l.info( str(skip_c) + " skips") l.info( "max objects # : " + str(max_ob)) if __name__ == '__main__': try: hotshot.Profile("prof").runcall(main) from hotshot import stats s = stats.load("prof") s.sort_stats("time").print_stats() except NameError: main()
PlotNewIcecubeXsectionLimit(pct, pc, None, True) #quit() ch = 'bb' dm = 1.0 * pct.TeV sig = 1.8e-41 * pct.cm**2 benchtime = prof.runcall(DM.DMFNeuFluxMCDetv2, ch, dm, sig, pct, False, datapath) #benchtime = prof.runcall(PlotNewIcecubeXsectionLimit,pct,pc,None,True) prof.close() stat = hstat.load("MC_profile_0.prof") stat.strip_dirs() stat.print_stats() #quit() #pct = PC.PhysicsConstants() #pct.name = "3+3v2" #pct.numneu = 6 # #thsterile = 0.087 #dmsterile = 0.10 # #pct.th14 = thsterile #pct.th25 = thsterile #pct.th36 = thsterile
def stats(self): from hotshot import stats try: return stats.load(self.filename) except hotshot.ProfilerError: raise IOError("Error reading stats from '%s', file may be corrupt" % filename)
view_x = (xedge.min(), xedge.max()) view_y = (yedge.min(), yedge.max()) print 'making multiples', p.multiples.flat[0].axis(view_x + view_y) filename = '%s-%s_%s_%05.2fkm_%05.1fs.%s' % ( filename_prefix, grid_name, start_time.strftime('%Y%m%d_%H%M%S'), dx, time_delta.seconds, image_type) filename = os.path.join(outpath, filename) if do_save: fig.savefig(filename, dpi=150) return fig, p, frame_start_times, filename print ' ... done' if __name__ == '__main__': do_profile = False if do_profile: import hotshot from hotshot import stats prof = hotshot.Profile("multiples_test_profile") prof.runcall(runtest) prof.close() s = stats.load("multiples_test_profile") s.sort_stats("time").print_stats() else: import sys res = runtest(sys.argv[1], sys.argv[2])
#!/usr/bin/env python """ Print statistics gathered by hotshot profiler Usage: print_stats.py statsfile Typical usage: 1. Edit moin.py and activate the hotshot profiler, set profile file name 2. Run moin.py 3. Do some request, with a browser, script or ab 4. Stop moin.py 5. Run this tool: print_stats.py moin.prof Currently CGI and twisted also have a hotshot profiler integration. """ import sys from hotshot import stats if len(sys.argv) != 2: print __doc__ sys.exit() # Load and print stats s = stats.load(sys.argv[1]) s.strip_dirs() s.sort_stats('cumulative', 'time', 'calls') s.print_stats(40) s.print_callers(40)
profiler reports, see http://python.org/doc/current/lib/profile-stats.html or the 'pstats' module chapter of your Python manual. """ import sys from run_tests import ScanningLoader from unittest import main from hotshot import Profile from hotshot.stats import load if __name__ == '__main__': if len(sys.argv)<2 or sys.argv[1] in ('-h','--help'): # XXX print __doc__ sys.exit(2) stats_file = "profile.dat" try: Profile(stats_file).run( "main(module=None, testLoader=ScanningLoader())" ) except SystemExit: # prevent unittest.main() from forcing an early exit pass s = load(stats_file) s.sort_stats("time") s.print_stats(10)