[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 00:32:59 PDT 2022


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

This fails currently but the basics are there


Repository:
  rG LLVM Github Monorepo

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,9 @@
   s.Printf("  Raw trace size: %zu bytes\n", *raw_size);
   s.Printf("  Total number of instructions: %zu\n", 
     Decode(thread)->GetInstructions().size());
+
+  size_t memsize = Decode(thread)->GetMemoryUsage();
+  s.Printf("  Total memory usage: %zu\n", memsize);
   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
@@ -82,6 +82,12 @@
   ///     an error.
   lldb::addr_t GetLoadAddress() const;
 
+  /// Get the size in bytes of decoded instruction
+  ///
+  /// \return
+  ///   The size of the decoded instruction
+  static size_t GetMemoryUsage();
+
   /// \return
   ///     An \a llvm::Error object if this class corresponds to an Error, or an
   ///     \a llvm::Error::success otherwise.
@@ -150,6 +156,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
@@ -48,6 +48,14 @@
 
 lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; }
 
+size_t IntelPTInstruction::GetMemoryUsage() {
+  return (
+    sizeof(m_pt_insn) + 
+    sizeof(uint64_t) + sizeof(bool) 
+    // sizeof(m_error)
+  );
+}
+
 Optional<uint64_t> IntelPTInstruction::GetTimestampCounter() const {
   return m_timestamp;
 }
@@ -116,3 +124,13 @@
 lldb::TraceCursorUP DecodedThread::GetCursor() {
   return std::make_unique<TraceCursorIntelPT>(m_thread_sp, shared_from_this());
 }
+
+size_t DecodedThread::GetMemoryUsage() const {
+  size_t total = 0;
+  total += sizeof(m_raw_trace_size);
+
+  for (size_t i = 0; i < m_instructions.size(); i++)
+    total += m_instructions[i].GetMemoryUsage();
+  
+  return total;
+}


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


More information about the lldb-commits mailing list