diff options
author | Aldo Cortesi <aldo@corte.si> | 2018-04-17 07:35:12 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-17 07:35:12 +1200 |
commit | 754cb6cac9b1db56e2221fa379db014856a4725d (patch) | |
tree | 3eae65bfb213e549531fa21dfb4edb4e8ce58410 /test/bench/benchmark.py | |
parent | 5f74adc2df6d2a9452a9e3a6923fe05ba579e9e6 (diff) | |
parent | 565146311a5f7939f107af12a91d94f5f96d56fc (diff) | |
download | mitmproxy-754cb6cac9b1db56e2221fa379db014856a4725d.tar.gz mitmproxy-754cb6cac9b1db56e2221fa379db014856a4725d.tar.bz2 mitmproxy-754cb6cac9b1db56e2221fa379db014856a4725d.zip |
Merge pull request #3048 from cortesi/qbench
Improve benchmarking
Diffstat (limited to 'test/bench/benchmark.py')
-rw-r--r-- | test/bench/benchmark.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/bench/benchmark.py b/test/bench/benchmark.py new file mode 100644 index 00000000..8d208088 --- /dev/null +++ b/test/bench/benchmark.py @@ -0,0 +1,51 @@ +import asyncio +import cProfile +from mitmproxy import ctx + + +class Benchmark: + """ + A simple profiler addon. + """ + def __init__(self): + self.pr = cProfile.Profile() + self.started = False + + async def procs(self): + ctx.log.error("starting benchmark") + backend = await asyncio.create_subprocess_exec("devd", "-q", "-p", "10001", ".") + traf = await asyncio.create_subprocess_exec( + "wrk", + "-c50", + "-d5s", + "http://localhost:%s/benchmark.py" % ctx.master.server.address[1], + stdout=asyncio.subprocess.PIPE + ) + stdout, _ = await traf.communicate() + open(ctx.options.benchmark_save_path + ".bench", mode="wb").write(stdout) + ctx.log.error(stdout.decode("ascii")) + backend.kill() + ctx.master.shutdown() + + def load(self, loader): + loader.add_option( + "benchmark_save_path", + str, + "/tmp/profile", + "Destination for the .prof and and .bench result files" + ) + ctx.options.update( + mode="reverse:http://devd.io:10001", + ) + self.pr.enable() + + def running(self): + if not self.started: + self.started = True + asyncio.get_event_loop().create_task(self.procs()) + + def done(self): + self.pr.dump_stats(ctx.options.benchmark_save_path + ".prof") + + +addons = [Benchmark()]
\ No newline at end of file |