Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / benchmarks / turnaround / TestCompileRunToBreakpointTurnaround.py
blob98a2ec9ebf231d7686a8ed082698dc4b87a8402b
1 """Benchmark the turnaround time starting a debugger and run to the breakpoint with lldb vs. gdb."""
3 import sys
4 import lldb
5 from lldbsuite.test.lldbbench import *
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import configuration
9 from lldbsuite.test import lldbutil
12 class CompileRunToBreakpointBench(BenchBase):
13 def setUp(self):
14 BenchBase.setUp(self)
15 self.exe = lldbtest_config.lldbExec
16 self.function = "Driver::MainLoop()"
17 self.count = 3
19 self.lldb_avg = None
20 self.gdb_avg = None
22 @benchmarks_test
23 @no_debug_info_test
24 @expectedFailureAll(
25 oslist=["windows"],
26 bugnumber="llvm.org/pr22274: need a pexpect replacement for windows",
28 def test_run_lldb_then_gdb(self):
29 """Benchmark turnaround time with lldb vs. gdb."""
30 print()
31 self.run_lldb_turnaround(self.exe, self.function, self.count)
32 print("lldb turnaround benchmark:", self.stopwatch)
33 self.run_gdb_turnaround(self.exe, self.function, self.count)
34 print("gdb turnaround benchmark:", self.stopwatch)
35 print("lldb_avg/gdb_avg: %f" % (self.lldb_avg / self.gdb_avg))
37 def run_lldb_turnaround(self, exe, function, count):
38 import pexpect
40 def run_one_round():
41 prompt = self.child_prompt
43 # So that the child gets torn down after the test.
44 self.child = pexpect.spawn(
45 "%s %s %s" % (lldbtest_config.lldbExec, self.lldbOption, exe)
47 child = self.child
49 # Turn on logging for what the child sends back.
50 if self.TraceOn():
51 child.logfile_read = sys.stdout
53 child.expect_exact(prompt)
54 child.sendline("breakpoint set -F %s" % function)
55 child.expect_exact(prompt)
56 child.sendline("run")
57 child.expect_exact(prompt)
59 # Set self.child_prompt, which is "(lldb) ".
60 self.child_prompt = "(lldb) "
61 # Reset the stopwatch now.
62 self.stopwatch.reset()
64 for i in range(count + 1):
65 # Ignore the first invoke lldb and run to the breakpoint turnaround
66 # time.
67 if i == 0:
68 run_one_round()
69 else:
70 with self.stopwatch:
71 run_one_round()
73 self.child.sendline("quit")
74 try:
75 self.child.expect(pexpect.EOF)
76 except:
77 pass
79 self.lldb_avg = self.stopwatch.avg()
80 self.child = None
82 def run_gdb_turnaround(self, exe, function, count):
83 import pexpect
85 def run_one_round():
86 prompt = self.child_prompt
88 # So that the child gets torn down after the test.
89 self.child = pexpect.spawn("gdb --nx %s" % exe)
90 child = self.child
92 # Turn on logging for what the child sends back.
93 if self.TraceOn():
94 child.logfile_read = sys.stdout
96 child.expect_exact(prompt)
97 child.sendline("break %s" % function)
98 child.expect_exact(prompt)
99 child.sendline("run")
100 child.expect_exact(prompt)
102 # Set self.child_prompt, which is "(gdb) ".
103 self.child_prompt = "(gdb) "
104 # Reset the stopwatch now.
105 self.stopwatch.reset()
107 for i in range(count + 1):
108 # Ignore the first invoke lldb and run to the breakpoint turnaround
109 # time.
110 if i == 0:
111 run_one_round()
112 else:
113 with self.stopwatch:
114 run_one_round()
116 self.child.sendline("quit")
117 self.child.expect_exact("The program is running. Exit anyway?")
118 self.child.sendline("y")
119 try:
120 self.child.expect(pexpect.EOF)
121 except:
122 pass
124 self.gdb_avg = self.stopwatch.avg()
125 self.child = None