2011-10-27 06:58:02 +08:00
|
|
|
"""Test lldb's disassemblt speed. This bench deliberately attaches to an lldb
|
|
|
|
inferior and traverses the stack for thread0 to arrive at frame with function
|
|
|
|
'MainLoop'. It is important to specify an lldb executable as the inferior."""
|
2011-10-22 08:57:05 +08:00
|
|
|
|
|
|
|
import os, sys
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbbench import *
|
|
|
|
|
|
|
|
class AttachThenDisassemblyBench(BenchBase):
|
|
|
|
|
2013-12-11 07:19:29 +08:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2011-10-22 08:57:05 +08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
BenchBase.setUp(self)
|
2011-10-27 06:58:02 +08:00
|
|
|
if lldb.bmExecutable:
|
|
|
|
self.exe = lldb.bmExecutable
|
|
|
|
else:
|
2015-05-19 03:39:03 +08:00
|
|
|
self.exe = lldbtest_config.lldbExec
|
2011-10-27 06:58:02 +08:00
|
|
|
self.count = lldb.bmIterationCount
|
|
|
|
if self.count <= 0:
|
|
|
|
self.count = 10
|
2011-10-22 08:57:05 +08:00
|
|
|
|
|
|
|
@benchmarks_test
|
|
|
|
def test_attach_then_disassembly(self):
|
|
|
|
"""Attach to a spawned lldb process then run disassembly benchmarks."""
|
|
|
|
print
|
2011-10-27 06:58:02 +08:00
|
|
|
self.run_lldb_attach_then_disassembly(self.exe, self.count)
|
2011-10-22 08:57:05 +08:00
|
|
|
print "lldb disassembly benchmark:", self.stopwatch
|
|
|
|
|
2011-10-27 06:58:02 +08:00
|
|
|
def run_lldb_attach_then_disassembly(self, exe, count):
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
2011-10-22 08:57:05 +08:00
|
|
|
|
|
|
|
# Spawn a new process and don't display the stdout if not in TraceOn() mode.
|
|
|
|
import subprocess
|
2011-10-27 06:58:02 +08:00
|
|
|
popen = subprocess.Popen([exe, self.lldbOption],
|
2011-10-22 08:57:05 +08:00
|
|
|
stdout = open(os.devnull, 'w') if not self.TraceOn() else None)
|
|
|
|
if self.TraceOn():
|
|
|
|
print "pid of spawned process: %d" % popen.pid
|
|
|
|
|
|
|
|
# Attach to the launched lldb process.
|
|
|
|
listener = lldb.SBListener("my.attach.listener")
|
|
|
|
error = lldb.SBError()
|
|
|
|
process = target.AttachToProcessWithID(listener, popen.pid, error)
|
|
|
|
|
|
|
|
# Set thread0 as the selected thread, followed by the 'MainLoop' frame
|
|
|
|
# as the selected frame. Then do disassembly on the function.
|
|
|
|
thread0 = process.GetThreadAtIndex(0)
|
|
|
|
process.SetSelectedThread(thread0)
|
|
|
|
i = 0
|
|
|
|
found = False
|
|
|
|
for f in thread0:
|
|
|
|
#print "frame#%d %s" % (i, f.GetFunctionName())
|
|
|
|
if "MainLoop" in f.GetFunctionName():
|
|
|
|
found = True
|
|
|
|
thread0.SetSelectedFrame(i)
|
|
|
|
if self.TraceOn():
|
|
|
|
print "Found frame#%d for function 'MainLoop'" % i
|
|
|
|
break
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
# Reset the stopwatch now.
|
|
|
|
self.stopwatch.reset()
|
|
|
|
for i in range(count):
|
|
|
|
with self.stopwatch:
|
|
|
|
# Disassemble the function.
|
|
|
|
self.runCmd("disassemble -f")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|