def start_profiler(host='localhost', port=8090, tracker=None, stats=None, debug=False, **kwargs): """ Start the web server to show profiling data. The function suspends the Python application (the current thread) until the web server is stopped. The only way to stop the server is to signal the running thread, e.g. press Ctrl+C in the console. If this isn't feasible for your application use `start_in_background` instead. During the execution of the web server, profiling data is (lazily) cached to improve performance. For example, garbage graphs are rendered when the garbage profiling data is requested and are simply retransmitted upon later requests. The web server can display profiling data from previously taken snapshots when `tracker` or `stats` is specified. The former is useful for profiling a running application, the latter for off-line analysis. Requires existing snapshots taken with :py:meth:`~pympler.classtracker.ClassTracker.create_snapshot` or :py:meth:`~pympler.classtracker.ClassTracker.start_periodic_snapshots`. :param host: the host where the server shall run, default is localhost :param port: server listens on the specified port, default is 8090 to allow coexistance with common web applications :param tracker: `ClassTracker` instance, browse profiling data (on-line analysis) :param stats: `Stats` instance, analyze `ClassTracker` profiling dumps (useful for off-line analysis) """ if tracker and not stats: server.stats = tracker.stats else: server.stats = stats try: server.tmpdir = mkdtemp(prefix='pympler') server.server = PymplerServer(host=host, port=port, **kwargs) bottle.debug(debug) bottle.run(server=server.server) finally: rmtree(server.tmpdir)