• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test lldb's startup delays creating a target, setting a breakpoint, and run to breakpoint stop."""
2
3from __future__ import print_function
4
5
6import sys
7import lldb
8from lldbsuite.test import configuration
9from lldbsuite.test import lldbtest_config
10from lldbsuite.test.decorators import *
11from lldbsuite.test.lldbbench import *
12
13
14class StartupDelaysBench(BenchBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    def setUp(self):
19        BenchBase.setUp(self)
20        # Create self.stopwatch2 for measuring "set first breakpoint".
21        # The default self.stopwatch is for "create fresh target".
22        self.stopwatch2 = Stopwatch()
23        # Create self.stopwatch3 for measuring "run to breakpoint".
24        self.stopwatch3 = Stopwatch()
25        self.exe = lldbtest_config.lldbExec
26        self.break_spec = '-n main'
27        self.count = 30
28
29    @benchmarks_test
30    @no_debug_info_test
31    @expectedFailureAll(
32        oslist=["windows"],
33        bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
34    def test_startup_delay(self):
35        """Test start up delays creating a target, setting a breakpoint, and run to breakpoint stop."""
36        print()
37        self.run_startup_delays_bench(self.exe, self.break_spec, self.count)
38        print(
39            "lldb startup delay (create fresh target) benchmark:",
40            self.stopwatch)
41        print(
42            "lldb startup delay (set first breakpoint) benchmark:",
43            self.stopwatch2)
44        print(
45            "lldb startup delay (run to breakpoint) benchmark:",
46            self.stopwatch3)
47
48    def run_startup_delays_bench(self, exe, break_spec, count):
49        import pexpect
50        # Set self.child_prompt, which is "(lldb) ".
51        self.child_prompt = '(lldb) '
52        prompt = self.child_prompt
53
54        # Reset the stopwatchs now.
55        self.stopwatch.reset()
56        self.stopwatch2.reset()
57        for i in range(count):
58            # So that the child gets torn down after the test.
59            self.child = pexpect.spawn(
60                '%s %s' %
61                (lldbtest_config.lldbExec, self.lldbOption))
62            child = self.child
63
64            # Turn on logging for what the child sends back.
65            if self.TraceOn():
66                child.logfile_read = sys.stdout
67
68            with self.stopwatch:
69                # Create a fresh target.
70                child.sendline('file %s' % exe)  # Aka 'target create'.
71                child.expect_exact(prompt)
72
73            with self.stopwatch2:
74                # Read debug info and set the first breakpoint.
75                child.sendline('breakpoint set %s' % break_spec)
76                child.expect_exact(prompt)
77
78            with self.stopwatch3:
79                # Run to the breakpoint just set.
80                child.sendline('run')
81                child.expect_exact(prompt)
82
83            child.sendline('quit')
84            try:
85                self.child.expect(pexpect.EOF)
86            except:
87                pass
88
89        # The test is about to end and if we come to here, the child process has
90        # been terminated.  Mark it so.
91        self.child = None
92