[NFC][Py Reformat] Reformat python files in llvm
[llvm-project.git] / llvm / utils / bisect-skip-count
blobefdd2c937e1529656bee809f75053ef0228316a1
1 #!/usr/bin/env python
2 # This script is used to bisect skip and count arguments for --debug-counter.
3 # It is similar to bisect, except it understands how to increase skip and decrease count
5 # Typical usage:
7 # bisect-skip-count bisect-command.sh "%(skip)d" "%(count)d" 2>&1 | tee bisect.out
9 # bisect-command.sh is something like this:
10 # #! /bin/bash
12 # skip=$1
13 # count=$2
15 # opt -debug-counter=my-counter-skip=${skip},my-counter-count=${count}
16 # ... Test output of opt and exit zero for pass, non-zero for fail
18 # Examine bisect.out to look for "Last good skip" and "Last good
19 # count" to find the values of the counter that produce a passing
20 # result. Incrementing the last good count by one or decrementing the
21 # last good skip by one should produce a failure.
23 from __future__ import print_function
24 import os
25 import sys
26 import argparse
27 # This is for timeout support. Use the recommended way of import.
28 # We do timeouts because when doing, execution testing, we have a habit
29 # of finding variants that infinite loop
30 if os.name == 'posix' and sys.version_info[0] < 3:
31 import subprocess32 as subprocess
32 else:
33 import subprocess
34 parser = argparse.ArgumentParser()
36 parser.add_argument('--skipstart', type=int, default=0)
37 parser.add_argument('--skipend', type=int, default=(1 << 32))
38 parser.add_argument('--countstart', type=int, default=0)
39 parser.add_argument('--countend', type=int, default=(1 << 32))
40 parser.add_argument('--timeout', type=int, default=None)
41 # Use shell support if you need to use complex shell expressions in your command
42 parser.add_argument('--shell', type=bool, default=False)
43 parser.add_argument('command', nargs='+')
45 args = parser.parse_args()
47 start = args.skipstart
48 end = args.skipend
50 print("Bisect of Skip starting!")
51 print("Start: %d" % start)
52 print("End: %d" % end)
54 last = None
55 while start != end and start != end-1:
56 count = start + (end - start)//2
57 print("Visiting Skip: %d with (Start, End) = (%d,%d)" % (count, start, end))
58 cmd = [x % {'skip':count, 'count':-1} for x in args.command]
59 print(cmd)
60 try:
61 result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
62 if result == 0:
63 print(" PASSES! Setting end to count")
64 end = count
65 else:
66 print(" FAILS! Setting start to count")
67 start = count
68 except:
69 print(" TIMEOUT, setting end to count")
70 end = count
71 firstcount = start
72 print("Last good skip: %d" % start)
73 start = args.countstart
74 end = args.countend
75 print("Bisect of Count starting!")
76 print("Start: %d" % start)
77 print("End: %d" % end)
78 while start != end and start != end-1:
79 count = start + (end - start)//2
80 print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end))
81 cmd = [x % {'count':count, 'skip':firstcount } for x in args.command]
82 print(cmd)
83 try:
84 result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
85 if result == 0:
86 print(" PASSES! Setting start to count")
87 start = count
88 else:
89 print(" FAILS! Setting end to count")
90 end = count
91 except:
92 print(" TIMEOUT, setting start to count")
93 start = count
95 print("Last good count: %d" % start)