[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace

Alisamar Husain via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Mar 20 02:17:19 PDT 2022


zrthxn updated this revision to Diff 416765.
zrthxn added a comment.

Fixed trace info test for this


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122093/new/

https://reviews.llvm.org/D122093

Files:
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDumpInfo.py


Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===================================================================
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -39,4 +39,5 @@
 
 thread #1: tid = 3842849
   Raw trace size: 4096 bytes
-  Total number of instructions: 21'''])
+  Total number of instructions: 21
+  Total memory usage: 1037 bytes'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===================================================================
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -114,6 +114,8 @@
   s.Printf("  Raw trace size: %zu bytes\n", *raw_size);
   s.Printf("  Total number of instructions: %zu\n", 
     Decode(thread)->GetInstructions().size());
+  s.Printf("  Total memory usage: %zu bytes\n", 
+    Decode(thread)->GetMemoryUsage());
   return;
 }
 
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
===================================================================
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -81,6 +81,19 @@
   ///     The instruction pointer address, or \a LLDB_INVALID_ADDRESS if it is
   ///     an error.
   lldb::addr_t GetLoadAddress() const;
+  
+  /// Get the size in bytes of decoded instruction.
+  /// This method is static because the size of \a IntelPTInstruction is not dynamic
+  ///
+  /// \return
+  ///   The size of the decoded instruction
+  static size_t GetMemoryUsage() {
+    return (
+      sizeof(m_pt_insn) + 
+      sizeof(uint64_t) + 
+      sizeof(bool)
+    );
+  }
 
   /// \return
   ///     An \a llvm::Error object if this class corresponds to an Error, or an
@@ -150,6 +163,12 @@
   ///   The size of the trace.
   size_t GetRawTraceSize() const;
 
+  /// Get the size in bytes of decoded Intel PT trace
+  ///
+  /// \return
+  ///   The size of the decoded traces.
+  size_t GetMemoryUsage() const;
+
 private:
   lldb::ThreadSP m_thread_sp;
   std::vector<IntelPTInstruction> m_instructions;
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
===================================================================
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -116,3 +116,12 @@
 lldb::TraceCursorUP DecodedThread::GetCursor() {
   return std::make_unique<TraceCursorIntelPT>(m_thread_sp, shared_from_this());
 }
+
+size_t DecodedThread::GetMemoryUsage() const {
+  size_t total = sizeof(m_raw_trace_size);
+
+  for (const IntelPTInstruction &ins : m_instructions)
+    total += ins.GetMemoryUsage();
+
+  return total;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122093.416765.patch
Type: text/x-patch
Size: 2734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220320/723bde10/attachment.bin>


More information about the lldb-commits mailing list