From 228e17560a95f37169c91a5df8faf55b28880a13 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Wed, 7 Mar 2007 20:31:49 -0700
Subject: [PATCH] control.py: fix get_memory_usage, add a sample client tool

---
 misc/getmem.py           | 18 ++++++++++++++++++
 src/allmydata/control.py |  4 +++-
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 misc/getmem.py

diff --git a/misc/getmem.py b/misc/getmem.py
new file mode 100644
index 00000000..171340d2
--- /dev/null
+++ b/misc/getmem.py
@@ -0,0 +1,18 @@
+#! /usr/bin/python
+
+from foolscap import Tub
+from foolscap.eventual import eventually
+import sys
+from twisted.internet import reactor
+
+def go():
+    t = Tub()
+    d = t.getReference(sys.argv[1])
+    d.addCallback(lambda rref: rref.callRemote("get_memory_usage"))
+    def _got(res):
+        print res
+        reactor.stop()
+    d.addCallback(_got)
+
+eventually(go)
+reactor.run()
diff --git a/src/allmydata/control.py b/src/allmydata/control.py
index 4c4ea1eb..d2d756da 100644
--- a/src/allmydata/control.py
+++ b/src/allmydata/control.py
@@ -29,5 +29,7 @@ class ControlServer(Referenceable, service.Service):
         for line in open("/proc/self/status", "r").readlines():
             name, right = line.split(":",2)
             if name in stat_names:
-                stats[name] = int(right.strip()) * 1024
+                assert right.endswith(" kB\n")
+                right = right[:-4]
+                stats[name] = int(right) * 1024
         return stats
-- 
2.45.2