mitmproxy/test/helper_tools/benchtool.py

57 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 mitmproxy.main import mitmdump
2015-04-08 18:43:59 +00:00
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
2016-10-17 04:34:46 +00:00
super().__init__()
2015-05-30 00:03:28 +00:00
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(addons=True)
2015-05-30 00:03:28 +00:00
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
2016-11-16 21:39:15 +00:00
2015-04-08 18:43:59 +00:00
if __name__ == '__main__':
2015-05-30 00:03:28 +00:00
main()