Skip to content

Instantly share code, notes, and snippets.

@t3rmin4t0r
Created May 19, 2017 19:55
Show Gist options
  • Save t3rmin4t0r/a4d2ad8ab6ce27b2f709ee38aad4c0cc to your computer and use it in GitHub Desktop.
Save t3rmin4t0r/a4d2ad8ab6ce27b2f709ee38aad4c0cc to your computer and use it in GitHub Desktop.

Revisions

  1. t3rmin4t0r created this gist May 19, 2017.
    38 changes: 38 additions & 0 deletions report-3x-jmeter.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    import sys, re, math, os
    from xml.dom.minidom import parse
    from collections import namedtuple

    Sample = namedtuple("Sample", ['query', 'duration', 'success', 'end', 'start', 'user'])

    RUN_NUM = re.compile(r'(?P<query>.*\.sql)(_(?P<run>[0-9]*))?')
    def runid(q):
    m = RUN_NUM.match(q)
    return (m.group('query'), int(m.group('run')))

    class RawResult(object):
    def __init__(self, fname):
    self.raw = parse(fname)
    self.fname = fname
    samples = self.raw.getElementsByTagName("sample")
    self.samples = list(sorted([self.sample(s) for s in samples], key= lambda v : v.query))
    self.lookup = dict([(runid(s.query), s) for s in self.samples])
    self.users = len(set([v.user for v in self.samples]))
    def sample(self, s):
    attr = lambda a : s.getAttribute(a)
    return Sample(query=attr("lb"), duration=attr("t"), success=attr("s"), end=int(attr("ts")), start=int(attr("ts")) - int(attr("t")), user=attr("tn"))
    def get(self, q, r):
    if self.lookup.has_key((q,r)):
    return self.lookup[(q,r)]
    return -1

    def main(args):
    result = RawResult(args[0])
    queries = set([q for (q,r) in result.lookup.keys()])
    runs = max([r for (q,r) in result.lookup.keys()])
    # for each query, print runs columnar
    for q in queries:
    print ",".join([q]+[result.get(q,r).duration for r in xrange(1,runs+1)])

    if __name__ == "__main__":
    main(sys.argv[1:])