summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/benchmarks/disassembly/TestDoAttachThenDisassembly.py
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-10-28 17:43:26 +0000
committerZachary Turner <zturner@google.com>2015-10-28 17:43:26 +0000
commitc432c8f856e0bd84de980a9d9bb2d31b06fa95b1 (patch)
tree4efa528e074a6e2df782345e4cd97f5d85d038c4 /lldb/packages/Python/lldbsuite/test/benchmarks/disassembly/TestDoAttachThenDisassembly.py
parenta8a3bd210086b50242903ed95048fe5e53897878 (diff)
downloadbcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.tar.gz
bcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.zip
Move lldb/test to lldb/packages/Python/lldbsuite/test.
This is the conclusion of an effort to get LLDB's Python code structured into a bona-fide Python package. This has a number of benefits, but most notably the ability to more easily share Python code between different but related pieces of LLDB's Python infrastructure (for example, `scripts` can now share code with `test`). llvm-svn: 251532
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/benchmarks/disassembly/TestDoAttachThenDisassembly.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/benchmarks/disassembly/TestDoAttachThenDisassembly.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/benchmarks/disassembly/TestDoAttachThenDisassembly.py b/lldb/packages/Python/lldbsuite/test/benchmarks/disassembly/TestDoAttachThenDisassembly.py
new file mode 100644
index 00000000000..1e1c1d48fd9
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/benchmarks/disassembly/TestDoAttachThenDisassembly.py
@@ -0,0 +1,71 @@
+"""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."""
+
+from __future__ import print_function
+
+import use_lldb_suite
+
+import os, sys
+import lldb
+from lldbbench import *
+
+class AttachThenDisassemblyBench(BenchBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ BenchBase.setUp(self)
+ if lldb.bmExecutable:
+ self.exe = lldb.bmExecutable
+ else:
+ self.exe = lldbtest_config.lldbExec
+ self.count = lldb.bmIterationCount
+ if self.count <= 0:
+ self.count = 10
+
+ @benchmarks_test
+ @no_debug_info_test
+ def test_attach_then_disassembly(self):
+ """Attach to a spawned lldb process then run disassembly benchmarks."""
+ print()
+ self.run_lldb_attach_then_disassembly(self.exe, self.count)
+ print("lldb disassembly benchmark:", self.stopwatch)
+
+ def run_lldb_attach_then_disassembly(self, exe, count):
+ target = self.dbg.CreateTarget(exe)
+
+ # Spawn a new process and don't display the stdout if not in TraceOn() mode.
+ import subprocess
+ popen = subprocess.Popen([exe, self.lldbOption],
+ 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")
OpenPOWER on IntegriCloud