Updated microbenchmarking script.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Mon, 27 Sep 2010 05:55:19 +0000 (22:55 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Mon, 27 Sep 2010 05:55:19 +0000 (22:55 -0700)
microbench/microbench.py

index 3e0cd4d..313828a 100755 (executable)
@@ -7,40 +7,81 @@ SERVER = 'c09-45.sysnet.ucsd.edu'
 
 class TestClient:
     def setup_client(self, export):
+        print "Mounting file system..."
         subprocess.check_call(['mount', '-t', 'nfs',
                                '-o', 'vers=3,tcp,rw,soft,intr',
                                export, MNTDIR])
 
     def cleanup_client(self):
+        print "Unmounting file system..."
         subprocess.check_call(['umount', '-f', MNTDIR])
 
-    def run(self, export):
+    def run(self, proc, args=(), export=(SERVER + ":/export")):
         self.setup_client(export)
+        startdir = os.getcwd()
         try:
-            results = self.run_test()
+            os.chdir(MNTDIR)
+            results = proc(*args)
         finally:
+            os.chdir(startdir)
             self.cleanup_client()
         return results
 
-class BlueSkyServer:
-    def setup_server(self):
-        subprocess.call(['ssh', SERVER, ''])
+class TestCommands:
+    def serial_stat(self):
+        files = ["file-%d" % (i,) for i in range(8)]
 
-class SerialStat(TestClient):
-    """Call stat() on a set of files sequentially and measure the response time
-    for each call."""
+        times = []
+        for f in files:
+            start = time.time()
+            os.stat(f)
+            times.append(time.time() - start)
 
-    def run_test(self):
-        files = [MNTDIR + "/file-%d" % (i,) for i in range(8)]
+        return times
+
+    def serial_read(self):
+        files = ["file-%d" % (i,) for i in range(8)]
 
         times = []
         for f in files:
             start = time.time()
-            os.stat(f)
+            open(f).read()
+            times.append(time.time() - start)
+
+        return times
+
+    def serial_write(self):
+        files = ["write-%d" % (i,) for i in range(8)]
+
+        times = []
+        buf = "A" * 32768
+        for f in files:
+            start = time.time()
+            fp = open(f, 'w')
+            fp.write(buf)
+            fp.close()
             times.append(time.time() - start)
 
         return times
 
+    def large_write(self):
+        buf = "A" * 1048576
+
+        start = time.time()
+        fp = open("largefile", 'w')
+        for i in range(128): fp.write(buf)
+        fp.close()
+
+        return [time.time() - start]
+
+    def shell(self):
+        subprocess.call(['/bin/sh'])
+
 if __name__ == '__main__':
-    test = SerialStat()
-    print test.run('niniel.sysnet.ucsd.edu:/export')
+    cmd = sys.argv[1]
+    args = sys.argv[2:]
+    if not cmd.startswith("_"):
+        fun = getattr(TestCommands(), cmd)
+        client = TestClient()
+        result = client.run(fun, args)
+        print "Results:", result