diff --git a/lldb/test/API/commands/trace/memory-usage/Makefile b/lldb/test/API/commands/trace/memory-usage/Makefile new file mode 100644 --- /dev/null +++ b/lldb/test/API/commands/trace/memory-usage/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/commands/trace/memory-usage/TestTraceMemoryUsage.py b/lldb/test/API/commands/trace/memory-usage/TestTraceMemoryUsage.py new file mode 100644 --- /dev/null +++ b/lldb/test/API/commands/trace/memory-usage/TestTraceMemoryUsage.py @@ -0,0 +1,41 @@ +import lldb +from intelpt_testcase import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +from lldbsuite.test.decorators import * +import re + +class TestTraceMemoryUsage(TraceIntelPTTestCaseBase): + mydir = TestBase.compute_mydir(__file__) + + @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64'])) + def testDumpBigTraceSize(self): + ''' + The purpose of this test is to ensure that the memory footprint + of a decoded trace is small. + ''' + self.build() + self.expect("file " + self.getBuildArtifact("a.out")) + self.expect("b main") + self.expect("r") + self.expect("thread trace start -s 0x100000") # 1 MB of trace + self.expect("b 5") + self.expect("c") + self.runCmd("thread trace dump info") + m = re.search( + 'Average memory usage per instruction \(excluding raw trace\): (.*) bytes', + self.res.GetOutput()) + avg_byte_per_insn = float(m.group(1)) + # As the program being run is compiled every time it runs, the total number + # of instructions and events might slightly change. Besides that, the number of + # events might change (e.g. different number of context switches), so we can't + # look for an exact byte size. Therefore we expect the avg byte usage per + #instruction to be 13 +- an error. + self.assertLess(abs(avg_byte_per_insn - 13), 0.1) + + # Similarly, we expect the number of instructions to be 10000000 +- an error. + m = re.search( + 'Total number of instructions: (.*)', + self.res.GetOutput()) + insn_count = int(m.group(1)) + self.assertLess(abs(insn_count - 10000000), 100000) diff --git a/lldb/test/API/commands/trace/memory-usage/main.cpp b/lldb/test/API/commands/trace/memory-usage/main.cpp new file mode 100644 --- /dev/null +++ b/lldb/test/API/commands/trace/memory-usage/main.cpp @@ -0,0 +1,6 @@ +int main() { + int x = 0; + for (int i = 0; i < 1000000; i++) + x += i * i; + return x; +}