[Lldb-commits] [PATCH] D123984: [trace][intel pt] Add a memory usage test

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 18 23:11:50 PDT 2022


wallace created this revision.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The existing tests that check for the memory usage of the decoded trace are using small binaries, and in this case the memory usage is dominated by the static size of the structures. In order to check the dynamic cost of the trace, I'm creating a new test that runs a program that is compiled at test time and then the total number of instructions and memory usage is asserted.

This serves as an example of a test that doesn't require to check in a prebuilt binary, which is costly for git.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123984

Files:
  lldb/test/API/commands/trace/memory-usage/Makefile
  lldb/test/API/commands/trace/memory-usage/TestTraceMemoryUsage.py
  lldb/test/API/commands/trace/memory-usage/main.cpp


Index: lldb/test/API/commands/trace/memory-usage/main.cpp
===================================================================
--- /dev/null
+++ 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;
+}
Index: lldb/test/API/commands/trace/memory-usage/TestTraceMemoryUsage.py
===================================================================
--- /dev/null
+++ 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)
Index: lldb/test/API/commands/trace/memory-usage/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/commands/trace/memory-usage/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123984.423539.patch
Type: text/x-patch
Size: 2605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220419/7535abc9/attachment.bin>


More information about the lldb-commits mailing list