[Zope-Checkins] CVS: Zope2 - dispatcher.py:1.1.2.2

Andreas Jung andreas@yetix.digicool.com
Fri, 9 Mar 2001 13:11:55 -0500


Update of /mnt/cvs-repository/Zope2/lib/python/Testing
In directory yetix:/work/Zope2/CatalogUnit/lib/python/Testing

Modified Files:
      Tag: Catalog-BTrees-Integration
	dispatcher.py 
Log Message:
changed method to measure memory usage



--- Updated File dispatcher.py in package Zope2 --
--- dispatcher.py	2001/03/08 11:04:10	1.1.2.1
+++ dispatcher.py	2001/03/09 18:11:53	1.1.2.2
@@ -56,6 +56,7 @@
         self.th_data    = {}
         self.runtime    = {}
         self._threads   = []
+        s2s=self.s2s
         
         
         for func,numthreads,args,kw in params:
@@ -81,7 +82,7 @@
         self.logn('Complete running time:                                  %9.3f sec' % (time.time()-self.start_test) )
         if len(self.mem_usage)>1: self.mem_usage.remove(-1)
         self.logn( "Memory: start: %s, end: %s, low: %s, high: %s" %  \
-                        (self.mem_usage[0],self.mem_usage[-1],min(self.mem_usage), max(self.mem_usage)))
+                        (s2s(self.mem_usage[0]),s2s(self.mem_usage[-1]),s2s(min(self.mem_usage)), s2s(max(self.mem_usage))))
         self.logn('')
         
         
@@ -125,9 +126,12 @@
         outp = commands.getoutput(cmd)
         pid,vsize = filter(lambda x: x!="" , string.split(outp," ") )
 
-#        res = resource.getrusage(resource.RUSAGE_SELF)
+        data = open("/proc/%d/statm" % os.getpid()).read()
+        fields = re.split(" ",data)
+        mem = string.atoi(fields[0]) * 4096
+
        
-        return vsize
+        return mem
         
         
     def mem_watcher(self):
@@ -147,6 +151,13 @@
     def register_teardown(self,func):
         self.f_teardown.append(func)
         
+
+    def s2s(self,n):
+        import math
+        if n <1024.0: return "%8.3lf Bytes" % n
+        if n <1024.0*1024.0: return "%8.3lf KB" % (1.0*n/1024.0)
+        if n <1024.0*1024.0*1024.0: return "%8.3lf MB" % (1.0*n/1024.0/1024.0)
+
 if __name__=="__main__":        
 
     d=Dispatcher()