summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2014-11-01 14:33:37 -0700
committerJelmer Vernooij <jelmer@samba.org>2014-11-19 02:46:04 +0100
commit34c6d47194cf52ca7228076da5bd80c6029e356f (patch)
tree85ef3989d010b914bd1e3bd5ec4f103971bda638
parent393b04cd57d351ee7c250178e7c8a910dc6416a9 (diff)
downloadsamba-34c6d47194cf52ca7228076da5bd80c6029e356f.tar.gz
Rewrite show_test_time in python and support --limit argument.
Change-Id: I6c3f28ed52cc8597251aa195ec3c7e38587c2573 Signed-Off-By: Jelmer Vernooij <jelmer@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
-rwxr-xr-xscript/show_test_time58
1 files changed, 39 insertions, 19 deletions
diff --git a/script/show_test_time b/script/show_test_time
index d9a18f034ea..f3ea56ef1ec 100755
--- a/script/show_test_time
+++ b/script/show_test_time
@@ -1,19 +1,39 @@
-#!/usr/bin/env perl
-#
-use strict;
-my %h;
-open(FH, "subunit-ls --times --no-passthrough|") || die "pb with subunit-ls";
-while(<FH>)
-{
- chomp();
- my @l = split(/ /);
- my $val = @l[scalar(@l)-1];
- $h{join(' ',@l)} = $val;
-}
-
-my @sorted = sort { $h{$b}<=>$h{$a} } keys(%h);
-use Data::Dumper;
-foreach my $l (@sorted)
-{
- print "$l\n";
-}
+#!/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()
+
+third_party_path = os.path.join(os.path.dirname(sys.argv[0]), "..", "lib")
+subunit_prefix = "PYTHONPATH="+ ":".join([
+ os.path.join(third_party_path, "testtools"),
+ os.path.join(third_party_path, "mimeparse"),
+ os.path.join(third_party_path, "extras"),
+ os.path.join(third_party_path, "subunit/python")]) + (
+ " " + os.path.join(third_party_path, "subunit"))
+
+durations = {}
+
+cmd = (os.path.join(subunit_prefix, "filters/subunit-1to2") + " | " +
+ os.path.join(subunit_prefix, "filters/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(), cmp=lambda (k1,v1), (k2, v2): cmp(v1, v2), reverse=True)):
+ if opts.limit and i == opts.limit:
+ break
+ print "%d: %s -> %ds" % (i+1, name, length)