From: Zooko O'Whielacronx Date: Fri, 21 Sep 2007 22:03:47 +0000 (-0700) Subject: cli: add --profile flag X-Git-Tag: allmydata-tahoe-0.6.0~20 X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/FOOURL?a=commitdiff_plain;h=3e4616f4ad2e25d2850ff6dfa09a8cb053594dd8;p=tahoe-lafs%2Ftahoe-lafs.git cli: add --profile flag --- diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py index c2d7df48..3988ec3e 100644 --- a/src/allmydata/scripts/startstop_node.py +++ b/src/allmydata/scripts/startstop_node.py @@ -9,6 +9,9 @@ class StartOptions(BasedirMixin, usage.Options): optParameters = [ ["basedir", "C", None, "which directory to start the node in"], ] + optFlags = [ + ["profile", "p", "whether to run under the Python profiler, putting results in \"profiling_results.prof\""], + ] class StopOptions(BasedirMixin, usage.Options): optParameters = [ @@ -25,7 +28,7 @@ class RestartOptions(BasedirMixin, usage.Options): "of 'restart'"], ] -def do_start(basedir, out=sys.stdout, err=sys.stderr): +def do_start(basedir, profile=False, out=sys.stdout, err=sys.stderr): print >>out, "STARTING", basedir if os.path.exists(os.path.join(basedir, "client.tac")): tac = "client.tac" @@ -53,6 +56,8 @@ def do_start(basedir, out=sys.stdout, err=sys.stderr): fileutil.make_dirs(os.path.join(basedir, "logs")) cmd.extend(["-y", tac, "--logfile", os.path.join("logs", "twistd.log")]) + if profile: + cmd.extend(["--profile=profiling_results.prof", "--savestats",]) curdir = os.getcwd() try: os.chdir(basedir) @@ -100,7 +105,7 @@ def do_stop(basedir, out=sys.stdout, err=sys.stderr): def start(config, stdout, stderr): rc = 0 for basedir in config['basedirs']: - rc = do_start(basedir, stdout, stderr) or rc + rc = do_start(basedir, config['profile'], stdout, stderr) or rc return rc def stop(config, stdout, stderr):