Pavlin Radoslavov | 1a39b48 | 2013-05-21 19:20:10 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*- |
| 3 | |
| 4 | import os |
| 5 | import string |
| 6 | import subprocess |
| 7 | import time |
| 8 | |
Pavlin Radoslavov | 7be9a39 | 2013-05-24 05:17:19 +0000 | [diff] [blame] | 9 | # flow_n = 252 |
| 10 | # threads_n = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 100] |
| 11 | # iterations_n = 10 |
| 12 | |
| 13 | flow_n = 1 |
| 14 | threads_n = [1] |
Pavlin Radoslavov | 1a39b48 | 2013-05-21 19:20:10 +0000 | [diff] [blame] | 15 | iterations_n = 10 |
| 16 | # iterations_n = 100 |
| 17 | |
Pavlin Radoslavov | 7be9a39 | 2013-05-24 05:17:19 +0000 | [diff] [blame] | 18 | # flow_n = 42 |
| 19 | # flow_n = 420 |
| 20 | # flow_n = 1008 |
Pavlin Radoslavov | 1a39b48 | 2013-05-21 19:20:10 +0000 | [diff] [blame] | 21 | |
| 22 | def run_command(cmd): |
| 23 | """ |
| 24 | - Run an external command, and return a tuple: stdout as the |
| 25 | first argument, and stderr as the second argument. |
| 26 | - Returns None if error. |
| 27 | """ |
| 28 | try: |
| 29 | pr = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE) |
| 30 | ret_tuple = pr.communicate(); |
| 31 | if pr.returncode: |
| 32 | print "%s failed with error code: %s" % (cmd, str(pr.returncode)) |
| 33 | return ret_tuple |
| 34 | except OSError: |
| 35 | print "OS Error running %s" % cmd |
| 36 | |
| 37 | def run_install_paths(flowdef_filename): |
| 38 | # Prepare the flows to measure |
| 39 | cmd = "web/measurement_store_flow.py -f " + flowdef_filename |
| 40 | os.system(cmd) |
| 41 | |
| 42 | def run_measurement(thread_n): |
| 43 | # Install the Flow Paths |
| 44 | cmd = ["web/measurement_install_paths.py", str(thread_n)] |
| 45 | run_command(cmd) |
| 46 | |
| 47 | # Get the measurement data and print it |
| 48 | cmd = "web/measurement_get_install_paths_time_nsec.py" |
| 49 | r = run_command(cmd) # Tuple: [<stdout>, <stderr>] |
Pavlin Radoslavov | 7be9a39 | 2013-05-24 05:17:19 +0000 | [diff] [blame] | 50 | res = r[0].split() # Tuple: [<num>, nsec] |
Pavlin Radoslavov | 1a39b48 | 2013-05-21 19:20:10 +0000 | [diff] [blame] | 51 | nsec_str = res[0] |
| 52 | msec = float(nsec_str) / (1000 * 1000) |
| 53 | |
Pavlin Radoslavov | 7be9a39 | 2013-05-24 05:17:19 +0000 | [diff] [blame] | 54 | # Get the measurement data and print it |
| 55 | cmd = "web/measurement_get_per_flow_install_time.py" |
| 56 | r = run_command(cmd) # Tuple: [<stdout>, <stderr>] |
| 57 | res = r[0] |
| 58 | print res |
| 59 | |
Pavlin Radoslavov | 1a39b48 | 2013-05-21 19:20:10 +0000 | [diff] [blame] | 60 | # Keep checking until all Flow Paths are installed |
| 61 | while True: |
| 62 | # time.sleep(3) |
| 63 | cmd = ["web/get_flow.py", "all"] |
| 64 | r = run_command(cmd) |
| 65 | if string.count(r[0], "FlowPath") != flow_n: |
| 66 | continue |
| 67 | if string.find(r[0], "NOT") == -1: |
| 68 | break |
| 69 | |
| 70 | # Remove the installed Flow Paths |
| 71 | cmd = ["web/delete_flow.py", "all"] |
| 72 | run_command(cmd) |
| 73 | |
| 74 | # Keep checking until all Flows are removed |
| 75 | while True: |
| 76 | # time.sleep(3) |
| 77 | cmd = ["web/get_flow.py", "all"] |
| 78 | r = run_command(cmd) |
| 79 | if r[0] == "": |
| 80 | break |
| 81 | |
| 82 | return msec |
| 83 | |
| 84 | |
| 85 | if __name__ == "__main__": |
| 86 | |
| 87 | # Initial cleanup |
| 88 | cmd = "web/measurement_clear_all_paths.py" |
| 89 | run_command(cmd) |
| 90 | |
| 91 | # Install the Flow Paths to measure |
| 92 | flowdef_filename = "web/flowdef_8node_" + str(flow_n) + ".txt" |
| 93 | run_install_paths(flowdef_filename) |
| 94 | |
| 95 | # Do the work |
| 96 | for thread_n in threads_n: |
| 97 | for n in range(iterations_n): |
| 98 | msec = run_measurement(thread_n) |
| 99 | # Format: <number of threads> <time in ms> |
| 100 | print "%d %f" % (thread_n, msec / flow_n) |
| 101 | |
| 102 | # Cleanup on exit |
| 103 | cmd = "web/measurement_clear_all_paths.py" |
| 104 | run_command(cmd) |