def main(): interval = 5 if len(sys.argv) > 1: script_path = sys.argv[1] sys.argv = sys.argv[1:] else: print >> sys.stderr, "usage: python -m tripod.sampler ./script_path.py" print >> sys.stderr, "(Default interval: %f seconds. Override with TRIPOD_INTERVAL env var)" % interval sys.exit(1) interval = float(os.environ.get("TRIPOD_INTERVAL", interval)) timer = Timer() timer.setDaemon(True) timer.start() # dump to file: fd, fn = tempfile.mkstemp(prefix='slow_process_', suffix='.log', dir='/tmp') print >> sys.stderr, "[Tripod] Sampling every %f seconds" % interval print >> sys.stderr, "[Tripod] Writing output to:", fn timer.run_later(peek, interval, fd, thread.get_ident(), dt.datetime.utcnow()) exit_code = 0 try: with open(script_path) as f: global __file__ __file__ = script_path exec f.read() in globals(), globals() except SystemExit, e: exit_code = e.code