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 @@ -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 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 @@ -116,3 +116,12 @@ lldb::TraceCursorUP DecodedThread::GetCursor() { return std::make_unique(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; +} 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,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; }