Ticket #54: memcheck-win32.diff
File memcheck-win32.diff, 4.7 KB (added by Grumpf, at 2009-12-20T16:10:06Z) |
---|
-
src/allmydata/control.py
diff -rN -u old-tahoe/src/allmydata/control.py new-tahoe/src/allmydata/control.py
old new 10 10 from allmydata.immutable import upload 11 11 from twisted.python import log 12 12 13 try: 14 import win32process 15 except: 16 win32process = None 17 13 18 def get_memory_usage(): 14 # this is obviously linux-specific15 stat_names = ("VmPeak",16 "VmSize",17 #"VmHWM",18 "VmData")19 19 stats = {} 20 try: 21 for line in open("/proc/self/status", "r").readlines(): 22 name, right = line.split(":",2) 23 if name in stat_names: 24 assert right.endswith(" kB\n") 25 right = right[:-4] 26 stats[name] = int(right) * 1024 27 except: 28 # Probably not on (a compatible version of) Linux 29 stats['VmSize'] = 0 30 stats['VmPeak'] = 0 20 stats['VmSize'] = 0 21 stats['VmPeak'] = 0 22 stats['VmData'] = 0 23 if win32process: 24 # Windows-specific 25 process_memory_counters = win32process.GetProcessMemoryInfo(win32process.GetCurrentProcess()) 26 stats['VmSize'] = process_memory_counters['WorkingSetSize'] 27 stats['VmPeak'] = process_memory_counters['PeakWorkingSetSize'] 28 stats['VmData'] = stats['VmSize'] 29 else: 30 # this is obviously linux-specific 31 stat_names = ("VmPeak", 32 "VmSize", 33 #"VmHWM", 34 "VmData") 35 try: 36 for line in open("/proc/self/status", "r").readlines(): 37 name, right = line.split(":",2) 38 if name in stat_names: 39 assert right.endswith(" kB\n") 40 right = right[:-4] 41 stats[name] = int(right) * 1024 42 except: 43 # Probably not on (a compatible version of) Linux 44 pass 45 31 46 return stats 32 47 33 48 def log_memory_usage(where=""): -
src/allmydata/test/check_memory.py
diff -rN -u old-tahoe/src/allmydata/test/check_memory.py new-tahoe/src/allmydata/test/check_memory.py
old new 8 8 from allmydata import client, introducer 9 9 from allmydata.immutable import upload 10 10 from allmydata.scripts import create_node 11 from allmydata.util import fileutil, pollmixin 11 from allmydata.util import fileutil, pollmixin, find_exe 12 12 from foolscap.api import Tub, fireEventually, flushEventualQueue 13 13 from twisted.python import log 14 14 … … 263 263 pp = ClientWatcher() 264 264 self.proc_done = pp.d = defer.Deferred() 265 265 logfile = os.path.join(self.basedir, "client.log") 266 cmd = ["twistd", "-n", "-y", "tahoe-client.tac", "-l", logfile] 266 # code imported from do_start() of src/allmydata/scripts/startstop_node.py 267 cmd = find_exe.find_exe('twistd') 268 if not cmd: 269 # If 'twistd' wasn't on $PATH, maybe we're running from source and 270 # Twisted was built as one of our dependencies. If so, we're at 271 # BASEDIR/src/allmydata/test/check_memory.py, and it's at 272 # BASEDIR/support/$BINDIR/twistd 273 up = os.path.dirname 274 TAHOEDIR = up(up(up(up(os.path.abspath(__file__))))) 275 if sys.platform == "win32": 276 bin_dir = "Scripts" 277 else: 278 bin_dir = "bin" 279 bindir = os.path.join(TAHOEDIR, "support", bin_dir) 280 281 maybe = os.path.join(bindir, "twistd") 282 if os.path.exists(maybe): 283 cmd = [maybe] 284 oldpath = os.environ.get("PATH", "").split(os.pathsep) 285 os.environ["PATH"] = os.pathsep.join(oldpath + [bindir]) 286 # sys.path and $PYTHONPATH are taken care of by the extra code in 287 # 'setup.py trial' 288 else: 289 maybe = maybe+'.py' 290 if os.path.exists(maybe): 291 cmd = [sys.executable, maybe] 292 oldpath = os.environ.get("PATH", "").split(os.pathsep) 293 os.environ["PATH"] = os.pathsep.join(oldpath + [bindir]) 294 # sys.path and $PYTHONPATH are taken care of by the extra code in 295 # 'setup.py trial' 296 if not cmd: 297 raise TwistdNotFoundError("Can't find twistd (it comes with Twisted)") 298 # End of code import from do_start() of src/allmydata/scripts/startstop_node.py 299 300 cmd.extend(["-n", "-y", "tahoe-client.tac", "-l", logfile]) 267 301 env = os.environ.copy() 268 302 self.proc = reactor.spawnProcess(pp, cmd[0], cmd, env, path=clientdir) 269 303 log.msg("CLIENT STARTED")