aboutsummaryrefslogtreecommitdiffstats
path: root/test/tools/benchtool.py
diff options
context:
space:
mode:
authorJim Shaver <dcypherd@gmail.com>2015-05-31 01:21:44 -0400
committerJim Shaver <dcypherd@gmail.com>2015-05-31 01:21:44 -0400
commitb51363b3ca43f6572acb673186e6ae78a1f48434 (patch)
treea7488b32871c142141a813dc6ff2ede172672c31 /test/tools/benchtool.py
parent4fe2c069cca07aadf983f54e18dac4de492d5d69 (diff)
parent06fba18106a8f759ec6f08453e86772a170c653b (diff)
downloadmitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.tar.gz
mitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.tar.bz2
mitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.zip
Merge remote-tracking branch 'upstream/master' into print-bracket-fix
Conflicts: examples/har_extractor.py examples/nonblocking.py examples/read_dumpfile libmproxy/web/app.py
Diffstat (limited to 'test/tools/benchtool.py')
-rw-r--r--test/tools/benchtool.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/tools/benchtool.py b/test/tools/benchtool.py
new file mode 100644
index 00000000..ae4636a7
--- /dev/null
+++ b/test/tools/benchtool.py
@@ -0,0 +1,54 @@
+# Profile mitmdump with apachebench and
+# yappi (https://code.google.com/p/yappi/)
+#
+# Requirements:
+# - Apache Bench "ab" binary
+# - pip install click yappi
+
+from libmproxy.main import mitmdump
+from os import system
+from threading import Thread
+import time
+
+import yappi
+import click
+
+
+class ApacheBenchThread(Thread):
+ def __init__(self, concurrency):
+ self.concurrency = concurrency
+ super(ApacheBenchThread, self).__init__()
+
+ def run(self):
+ time.sleep(2)
+ system(
+ "ab -n 1024 -c {} -X 127.0.0.1:8080 http://example.com/".format(self.concurrency))
+
+
+@click.command()
+@click.option('--profiler', default="none", type=click.Choice(['none', 'yappi']))
+@click.option('--clock-type', default="cpu", type=click.Choice(['wall', 'cpu']))
+@click.option('--concurrency', default=1, type=click.INT)
+def main(profiler, clock_type, concurrency):
+
+ outfile = "callgrind.mitmdump-{}-c{}".format(clock_type, concurrency)
+ a = ApacheBenchThread(concurrency)
+ a.start()
+
+ if profiler == "yappi":
+ yappi.set_clock_type(clock_type)
+ yappi.start(builtins=True)
+
+ print("Start mitmdump...")
+ mitmdump(["-k", "-q", "-S", "1024example"])
+ print("mitmdump stopped.")
+
+ print("Save profile information...")
+ if profiler == "yappi":
+ yappi.stop()
+ stats = yappi.get_func_stats()
+ stats.save(outfile, type='callgrind')
+ print("Done.")
+
+if __name__ == '__main__':
+ main()