diff -rN -u old-tahoe/src/allmydata/control.py new-tahoe/src/allmydata/control.py --- old-tahoe/src/allmydata/control.py 2009-12-20 15:58:04 +0000 +++ new-tahoe/src/allmydata/control.py 2009-12-20 15:58:05 +0000 @@ -10,24 +10,39 @@ from allmydata.immutable import upload from twisted.python import log +try: + import win32process +except: + win32process = None + def get_memory_usage(): - # this is obviously linux-specific - stat_names = ("VmPeak", - "VmSize", - #"VmHWM", - "VmData") stats = {} - try: - for line in open("/proc/self/status", "r").readlines(): - name, right = line.split(":",2) - if name in stat_names: - assert right.endswith(" kB\n") - right = right[:-4] - stats[name] = int(right) * 1024 - except: - # Probably not on (a compatible version of) Linux - stats['VmSize'] = 0 - stats['VmPeak'] = 0 + stats['VmSize'] = 0 + stats['VmPeak'] = 0 + stats['VmData'] = 0 + if win32process: + # Windows-specific + process_memory_counters = win32process.GetProcessMemoryInfo(win32process.GetCurrentProcess()) + stats['VmSize'] = process_memory_counters['WorkingSetSize'] + stats['VmPeak'] = process_memory_counters['PeakWorkingSetSize'] + stats['VmData'] = stats['VmSize'] + else: + # this is obviously linux-specific + stat_names = ("VmPeak", + "VmSize", + #"VmHWM", + "VmData") + try: + for line in open("/proc/self/status", "r").readlines(): + name, right = line.split(":",2) + if name in stat_names: + assert right.endswith(" kB\n") + right = right[:-4] + stats[name] = int(right) * 1024 + except: + # Probably not on (a compatible version of) Linux + pass + return stats def log_memory_usage(where=""): diff -rN -u old-tahoe/src/allmydata/test/check_memory.py new-tahoe/src/allmydata/test/check_memory.py --- old-tahoe/src/allmydata/test/check_memory.py 2009-12-20 15:58:05 +0000 +++ new-tahoe/src/allmydata/test/check_memory.py 2009-12-20 15:58:05 +0000 @@ -8,7 +8,7 @@ from allmydata import client, introducer from allmydata.immutable import upload from allmydata.scripts import create_node -from allmydata.util import fileutil, pollmixin +from allmydata.util import fileutil, pollmixin, find_exe from foolscap.api import Tub, fireEventually, flushEventualQueue from twisted.python import log @@ -263,7 +263,41 @@ pp = ClientWatcher() self.proc_done = pp.d = defer.Deferred() logfile = os.path.join(self.basedir, "client.log") - cmd = ["twistd", "-n", "-y", "tahoe-client.tac", "-l", logfile] + # code imported from do_start() of src/allmydata/scripts/startstop_node.py + cmd = find_exe.find_exe('twistd') + if not cmd: + # If 'twistd' wasn't on $PATH, maybe we're running from source and + # Twisted was built as one of our dependencies. If so, we're at + # BASEDIR/src/allmydata/test/check_memory.py, and it's at + # BASEDIR/support/$BINDIR/twistd + up = os.path.dirname + TAHOEDIR = up(up(up(up(os.path.abspath(__file__))))) + if sys.platform == "win32": + bin_dir = "Scripts" + else: + bin_dir = "bin" + bindir = os.path.join(TAHOEDIR, "support", bin_dir) + + maybe = os.path.join(bindir, "twistd") + if os.path.exists(maybe): + cmd = [maybe] + oldpath = os.environ.get("PATH", "").split(os.pathsep) + os.environ["PATH"] = os.pathsep.join(oldpath + [bindir]) + # sys.path and $PYTHONPATH are taken care of by the extra code in + # 'setup.py trial' + else: + maybe = maybe+'.py' + if os.path.exists(maybe): + cmd = [sys.executable, maybe] + oldpath = os.environ.get("PATH", "").split(os.pathsep) + os.environ["PATH"] = os.pathsep.join(oldpath + [bindir]) + # sys.path and $PYTHONPATH are taken care of by the extra code in + # 'setup.py trial' + if not cmd: + raise TwistdNotFoundError("Can't find twistd (it comes with Twisted)") + # End of code import from do_start() of src/allmydata/scripts/startstop_node.py + + cmd.extend(["-n", "-y", "tahoe-client.tac", "-l", logfile]) env = os.environ.copy() self.proc = reactor.spawnProcess(pp, cmd[0], cmd, env, path=clientdir) log.msg("CLIENT STARTED")