pyldb: Use the Py_TYPE macro
[samba.git] / script / show_test_time
1 #!/usr/bin/python
2
3 import optparse
4 import os.path
5 import subprocess
6 import sys
7
8 parser = optparse.OptionParser()
9 parser.add_option("--limit", dest="limit", type=int,
10                   help="Limit to this number of output entries.", default=0)
11 (opts, args) = parser.parse_args()
12
13 third_party_path = os.path.join(os.path.dirname(sys.argv[0]), "..", "lib")
14 subunit_prefix = "PYTHONPATH="+ ":".join([
15     os.path.join(third_party_path, "testtools"),
16     os.path.join(third_party_path, "mimeparse"),
17     os.path.join(third_party_path, "extras"),
18     os.path.join(third_party_path, "subunit/python")]) + (
19     " " + os.path.join(third_party_path, "subunit"))
20
21 durations = {}
22
23 cmd = (os.path.join(subunit_prefix, "filters/subunit-1to2") + " | " +
24        os.path.join(subunit_prefix, "filters/subunit-ls") + " --times --no-passthrough")
25
26 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=sys.stdin, shell=True)
27 for l in p.stdout:
28     l = l.strip()
29     (name, duration) = l.rsplit(" ", 1)
30     durations[name] = float(duration)
31
32 if opts.limit:
33     print "Top %d tests by run time:" % opts.limit
34
35 for i, (name, length) in enumerate(sorted(
36     durations.items(), cmp=lambda (k1,v1), (k2, v2): cmp(v1, v2), reverse=True)):
37     if opts.limit and i == opts.limit:
38         break
39     print "%d: %s -> %ds" % (i+1, name, length)