diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h --- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h +++ b/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 m_instructions; diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp --- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp +++ b/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 IntelPTInstruction::GetTimestampCounter() const { return m_timestamp; } @@ -116,3 +124,13 @@ lldb::TraceCursorUP DecodedThread::GetCursor() { return std::make_unique(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; +} diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp +++ b/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; }