oft: add --profile command line option

This produces a Python profile of the testcases. The resulting profile.out file
can be read with the pstats module, RunSnake, or pyprof2calltree.
diff --git a/oft b/oft
index 4ef82eb..7db8257 100755
--- a/oft
+++ b/oft
@@ -77,6 +77,7 @@
     "log_file"           : "oft.log",
     "log_dir"            : None,
     "debug"              : "verbose",
+    "profile"            : False,
 
     # Test behavior options
     "relax"              : False,
@@ -179,6 +180,7 @@
                      const="verbose", help="Shortcut for --debug=verbose")
     group.add_option("-q", "--quiet", action="store_const", dest="debug",
                      const="warning", help="Shortcut for --debug=warning")
+    group.add_option("--profile", action="store_true", help="Write Python profile to profile.out")
     parser.add_option_group(group)
 
     group = optparse.OptionGroup(parser, "Test behavior options")
@@ -512,6 +514,11 @@
 signal.signal(signal.SIGINT, signal.SIG_DFL)
 
 if __name__ == "__main__":
+    if config["profile"]:
+        import cProfile
+        profiler = cProfile.Profile()
+        profiler.enable()
+
     # Set up the dataplane
     oftest.dataplane_instance = oftest.dataplane.DataPlane(config)
     pcap_setup(config)
@@ -532,6 +539,10 @@
     oftest.dataplane_instance.kill()
     oftest.dataplane_instance = None
 
+    if config["profile"]:
+        profiler.disable()
+        profiler.dump_stats("profile.out")
+
     if result.failures or result.errors:
         # exit(1) hangs sometimes
         os._exit(1)