[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:12:51 PDT 2022


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

Clean up, works fine now


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


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.416764.patch
Type: text/x-patch
Size: 2309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220320/72622567/attachment-0001.bin>


More information about the lldb-commits mailing list