summaryrefslogtreecommitdiffstats
path: root/script/show_test_time
blob: 70d29d72b5c45eb0dd93e0a7f2f1b0250b913443 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python
import optparse
import os.path
import subprocess
import sys

parser = optparse.OptionParser()
parser.add_option("--limit", dest="limit", type=int,
                  help="Limit to this number of output entries.", default=0)
(opts, args) = parser.parse_args()

durations = {}

cmd = "subunit-1to2 | subunit-ls --times --no-passthrough"

p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=sys.stdin, shell=True)
for l in p.stdout:
    l = l.strip()
    (name, duration) = l.rsplit(" ", 1)
    durations[name] = float(duration)

if opts.limit:
    print("Top %d tests by run time:" % opts.limit)

for i, (name, length) in enumerate(sorted(
        durations.items(), key=lambda x: x[1], reverse=True)):
    if opts.limit and i == opts.limit:
        break
    print("%d: %s -> %ds" % (i+1, name, length))