mitmproxy/test/tools/benchtool.py

56 lines
1.4 KiB
Python
Raw Normal View History

2015-04-08 18:43:59 +00:00
# Profile mitmdump with apachebench and
# yappi (https://code.google.com/p/yappi/)
#
# Requirements:
2015-05-30 00:03:28 +00:00
# - Apache Bench "ab" binary
2015-04-08 18:43:59 +00:00
# - pip install click yappi
from libmproxy.main import mitmdump
from os import system
from threading import Thread
import time
import yappi
import click
2015-05-30 00:03:28 +00:00
2015-04-08 18:43:59 +00:00
class ApacheBenchThread(Thread):
2016-01-27 09:12:18 +00:00
2015-05-30 00:03:28 +00:00
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))
2015-04-08 18:43:59 +00:00
@click.command()
2015-05-30 23:51:13 +00:00
@click.option('--profiler', default="none", type=click.Choice(['none', 'yappi']))
2015-04-08 18:43:59 +00:00
@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):
2015-05-30 00:03:28 +00:00
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.")
2015-04-08 18:43:59 +00:00
if __name__ == '__main__':
2015-05-30 00:03:28 +00:00
main()