1"""Test lldb's startup delays creating a target, setting a breakpoint, and run to breakpoint stop.""" 2 3import os, sys 4import unittest2 5import lldb 6import pexpect 7from lldbbench import * 8 9class StartupDelaysBench(BenchBase): 10 11 mydir = os.path.join("benchmarks", "startup") 12 13 def setUp(self): 14 BenchBase.setUp(self) 15 # Create self.stopwatch2 for measuring "set first breakpoint". 16 # The default self.stopwatch is for "create fresh target". 17 self.stopwatch2 = Stopwatch() 18 # Create self.stopwatch3 for measuring "run to breakpoint". 19 self.stopwatch3 = Stopwatch() 20 if lldb.bmExecutable: 21 self.exe = lldb.bmExecutable 22 else: 23 self.exe = self.lldbHere 24 if lldb.bmBreakpointSpec: 25 self.break_spec = lldb.bmBreakpointSpec 26 else: 27 self.break_spec = '-n main' 28 29 self.count = lldb.bmIterationCount 30 if self.count <= 0: 31 self.count = 30 32 33 @benchmarks_test 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 "lldb startup delay (create fresh target) benchmark:", self.stopwatch 39 print "lldb startup delay (set first breakpoint) benchmark:", self.stopwatch2 40 print "lldb startup delay (run to breakpoint) benchmark:", self.stopwatch3 41 42 def run_startup_delays_bench(self, exe, break_spec, count): 43 # Set self.child_prompt, which is "(lldb) ". 44 self.child_prompt = '(lldb) ' 45 prompt = self.child_prompt 46 47 # Reset the stopwatchs now. 48 self.stopwatch.reset() 49 self.stopwatch2.reset() 50 for i in range(count): 51 # So that the child gets torn down after the test. 52 self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption)) 53 child = self.child 54 55 # Turn on logging for what the child sends back. 56 if self.TraceOn(): 57 child.logfile_read = sys.stdout 58 59 with self.stopwatch: 60 # Create a fresh target. 61 child.sendline('file %s' % exe) # Aka 'target create'. 62 child.expect_exact(prompt) 63 64 with self.stopwatch2: 65 # Read debug info and set the first breakpoint. 66 child.sendline('breakpoint set %s' % break_spec) 67 child.expect_exact(prompt) 68 69 with self.stopwatch3: 70 # Run to the breakpoint just set. 71 child.sendline('run') 72 child.expect_exact(prompt) 73 74 child.sendline('quit') 75 try: 76 self.child.expect(pexpect.EOF) 77 except: 78 pass 79 80 # The test is about to end and if we come to here, the child process has 81 # been terminated. Mark it so. 82 self.child = None 83 84 85if __name__ == '__main__': 86 import atexit 87 lldb.SBDebugger.Initialize() 88 atexit.register(lambda: lldb.SBDebugger.Terminate()) 89 unittest2.main() 90