diff options
Diffstat (limited to 'test/tools')
-rw-r--r-- | test/tools/bench.py | 18 | ||||
-rwxr-xr-x | test/tools/getcert | 5 | ||||
-rw-r--r-- | test/tools/passive_close.py | 6 | ||||
-rw-r--r-- | test/tools/yappibench.py | 55 |
4 files changed, 46 insertions, 38 deletions
diff --git a/test/tools/bench.py b/test/tools/bench.py index 1028f61d..8127d083 100644 --- a/test/tools/bench.py +++ b/test/tools/bench.py @@ -1,5 +1,6 @@ from __future__ import print_function -import requests, time +import requests +import time n = 100 url = "http://192.168.1.1/" @@ -7,18 +8,17 @@ proxy = "http://192.168.1.115:8080/" start = time.time() for _ in range(n): - requests.get(url, allow_redirects=False, proxies=dict(http=proxy)) - print(".", end="") -t_mitmproxy = time.time()-start + requests.get(url, allow_redirects=False, proxies=dict(http=proxy)) + print(".", end="") +t_mitmproxy = time.time() - start print("\r\nTotal time with mitmproxy: {}".format(t_mitmproxy)) - start = time.time() for _ in range(n): - requests.get(url, allow_redirects=False) - print(".", end="") -t_without = time.time()-start + requests.get(url, allow_redirects=False) + print(".", end="") +t_without = time.time() - start -print("\r\nTotal time without mitmproxy: {}".format(t_without))
\ No newline at end of file +print("\r\nTotal time without mitmproxy: {}".format(t_without)) diff --git a/test/tools/getcert b/test/tools/getcert index 8fabefb7..3bd2bec8 100755 --- a/test/tools/getcert +++ b/test/tools/getcert @@ -1,7 +1,10 @@ #!/usr/bin/env python import sys sys.path.insert(0, "../..") -import socket, tempfile, ssl, subprocess +import socket +import tempfile +import ssl +import subprocess addr = socket.gethostbyname(sys.argv[1]) print ssl.get_server_certificate((addr, 443)) diff --git a/test/tools/passive_close.py b/test/tools/passive_close.py index d0b36e7f..7199ea70 100644 --- a/test/tools/passive_close.py +++ b/test/tools/passive_close.py @@ -2,12 +2,14 @@ import SocketServer from threading import Thread from time import sleep + class service(SocketServer.BaseRequestHandler): def handle(self): data = 'dummy' print "Client connected with ", self.client_address while True: - self.request.send("HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 7\r\n\r\ncontent") + self.request.send( + "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 7\r\n\r\ncontent") data = self.request.recv(1024) if not len(data): print "Connection closed by remote: ", self.client_address @@ -17,5 +19,5 @@ class service(SocketServer.BaseRequestHandler): class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass -server = ThreadedTCPServer(('',1520), service) +server = ThreadedTCPServer(('', 1520), service) server.serve_forever() diff --git a/test/tools/yappibench.py b/test/tools/yappibench.py index b9e4e41d..bae8da44 100644 --- a/test/tools/yappibench.py +++ b/test/tools/yappibench.py @@ -2,7 +2,7 @@ # yappi (https://code.google.com/p/yappi/) # # Requirements: -# - Apache Bench "ab" binary +# - Apache Bench "ab" binary # - pip install click yappi from libmproxy.main import mitmdump @@ -13,14 +13,17 @@ import time import yappi import click + class ApacheBenchThread(Thread): - def __init__(self, concurrency): - self.concurrency = concurrency - super(ApacheBenchThread, self).__init__() + 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)) - 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="yappi", type=click.Choice(['yappi'])) @@ -28,24 +31,24 @@ class ApacheBenchThread(Thread): @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.") + 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()
\ No newline at end of file + main() |