guneysus
3/2/2016 - 9:33 PM

wrk benchmarking result parser

wrk benchmarking result parser

#!/usr/bin/env python
# coding=utf-8
import pprint
import subprocess
import re

__author__ = u'Ahmed Şeref GÜNEYSU'


# noinspection PyShadowingNames,PyUnusedLocal
def wrk_parse(output):
    stats = dict(
        url=None,
        duration=None,
        thread=None,
        total_requests=None,
        errors=dict(
            non2xx3xx=None,
            socket=dict(connect=0, read=0, write=0, timeout=0)
        ),
        stats=dict(
            latency=dict(avg=None, stdev=None, max=None, stdev_diff=None),
            rps=dict(avg=None, stdev=None, max=None, stdev_diff=None)
        )
    )

    return stats


if __name__ == '__main__':
    args = ['wrk', 'http://example.com', '-t 1', '-d 5s', '']
    process = subprocess.Popen(args=args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    output, error = process.communicate()
    results = wrk_parse(output)
    pprint.pprint(wrk_parse(output), indent=1, width=80)
    print output