1
1
#!/usr/bin/python
2
2
3
- from __future__ import print_function
4
-
5
- import commands
6
3
import json
7
4
import os
8
5
import subprocess
9
6
import sys
10
7
import time
11
8
12
- LWAN_PATH = './build /testrunner/testrunner'
9
+ LWAN_PATH = './src/bin /testrunner/testrunner'
13
10
for arg in sys .argv [1 :]:
14
11
if not arg .startswith ('-' ) and os .path .exists (arg ):
15
12
LWAN_PATH = arg
@@ -33,25 +30,25 @@ def clearstderrline():
33
30
34
31
35
32
def weighttp (url , n_threads , n_connections , n_requests , keep_alive ):
36
- keep_alive = '-k' if keep_alive else ''
37
- command = 'weighttp %(keep_alive)s ' \
38
- '-t %(n_threads)d ' \
39
- '-c %(n_connections)d ' \
40
- '-n %(n_requests)d ' \
41
- '-j ' \
42
- '%(url)s 2> /dev/null' % locals ()
43
-
44
33
clearstderrline ()
45
- sys .stderr .write ('*** %s\r ' % command )
46
-
47
- output = commands .getoutput (command )
48
-
49
- return json .loads (output )
50
-
51
-
52
- def weighttp_has_json_output ():
53
- output = commands .getoutput ('weighttp -j' )
54
- return not 'unknown option: -j' in output
34
+ sys .stderr .write (f'*** Running weighttp on { url } : threads: { n_threads } ' \
35
+ f'conns: { n_connections } reqs: { n_requests } ' \
36
+ f'{ "keep-alive" if keep_alive else "" } \r ' )
37
+
38
+ command = [
39
+ './src/bin/tools/weighttp' ,
40
+ '-k' if keep_alive else '' ,
41
+ '-t' , n_threads ,
42
+ '-c' , n_connections ,
43
+ '-n' , n_requests ,
44
+ '-j' ,
45
+ url
46
+ ]
47
+ print (command )
48
+ output = subprocess .run (command , capture_output = True )
49
+ output .check_returncode ()
50
+
51
+ return json .loads (output .stdout )
55
52
56
53
57
54
def steprange (initial , final , steps = 10 ):
@@ -151,11 +148,6 @@ def log(self, keep_alive, n_connections, rps, kbps, _2xx, _3xx, _4xx, _5xx):
151
148
152
149
153
150
if __name__ == '__main__' :
154
- if not weighttp_has_json_output ():
155
- print ('This script requires a special version of weighttp which supports JSON' )
156
- print ('output. Get it at http://github.com/lpereira/weighttp' )
157
- sys .exit (1 )
158
-
159
151
plot = cmdlineboolarg ('--plot' )
160
152
xkcd = cmdlineboolarg ('--xkcd' )
161
153
n_threads = cmdlineintarg ('--threads' , 2 )
@@ -183,7 +175,7 @@ def log(self, keep_alive, n_connections, rps, kbps, _2xx, _3xx, _4xx, _5xx):
183
175
status = results ['status_codes' ]
184
176
185
177
output .log (keep_alive , n_connections , results ['reqs_per_sec' ],
186
- results ['kbyte_per_sec ' ], status ['2xx' ], status ['3xx' ],
178
+ results ['kBps_per_sec ' ], status ['2xx' ], status ['3xx' ],
187
179
status ['4xx' ], status ['5xx' ])
188
180
sleepwithstatus ('Waiting for keepalive connection timeout' , keep_alive_timeout * 1.1 )
189
181
0 commit comments