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

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Mar 20 10:50:09 PDT 2022


wallace added inline comments.


================
Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp:121-126
+  size_t total = sizeof(m_raw_trace_size);
+
+  for (const IntelPTInstruction &ins : m_instructions)
+    total += ins.GetMemoryUsage();
+
+  return total;
----------------
wallace wrote:
> you might be able to do something like
> 
>   // As calculating the size used by error instructions is very difficult, because errors
>   // are dynamic objects, we just discard them from our calculations because errors
>   // are supposed to be rare and not really contribute much to the total memory usage.
>   size_t non_error_instructions = count(m_instructions.begin(), m_instructions.end(), [](const IntelPTInstruction& insn) {!insn.IsError();});
> 
>   return IntelPTInstruction::GetNonErrorMemoryUsage() * non_error_instructions + GetRawTraceSize();
> 
> notice that we need the actual `GetRawTraceSize()` and not `sizeof(m_raw_trace_size)`, because the latter will always give you 8 bytes on an x86_64 machine, regardless of how much data it is actually consuming.
sorry, it should be 
  return IntelPTInstruction::GetNonErrorMemoryUsage() * non_error_instructions + GetRawTraceSize() + sizeof(DecodedThread);

notice the `sizeof(DecodedThread)` portion that accounts for the the m_thread_sp. The actual storage of the Thread * is somewhere else, and DecodedThread is just keeping a reference to it, so sizeof() is enough for this.


================
Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:172-173
+
 private:
   lldb::ThreadSP m_thread_sp;
   std::vector<IntelPTInstruction> m_instructions;
----------------



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122093



More information about the lldb-commits mailing list