[trace][intelpt] Added total memory usage by decoded trace

This fails currently but the basics are there

Differential Revision: https://reviews.llvm.org/D122093
This commit is contained in:
Alisamar Husain 2022-03-20 13:01:31 +05:30
parent 1eada2adda
commit 37a466dd72
4 changed files with 29 additions and 5 deletions

View File

@ -48,6 +48,8 @@ bool IntelPTInstruction::IsError() const { return (bool)m_error; }
lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; } lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; }
size_t IntelPTInstruction::GetNonErrorMemoryUsage() { return sizeof(IntelPTInstruction); }
Optional<uint64_t> IntelPTInstruction::GetTimestampCounter() const { Optional<uint64_t> IntelPTInstruction::GetTimestampCounter() const {
return m_timestamp; return m_timestamp;
} }
@ -116,3 +118,9 @@ DecodedThread::DecodedThread(ThreadSP thread_sp,
lldb::TraceCursorUP DecodedThread::GetCursor() { lldb::TraceCursorUP DecodedThread::GetCursor() {
return std::make_unique<TraceCursorIntelPT>(m_thread_sp, shared_from_this()); return std::make_unique<TraceCursorIntelPT>(m_thread_sp, shared_from_this());
} }
size_t DecodedThread::CalculateApproximateMemoryUsage() const {
return m_raw_trace_size
+ IntelPTInstruction::GetNonErrorMemoryUsage() * m_instructions.size()
+ sizeof(DecodedThread);
}

View File

@ -82,6 +82,9 @@ public:
/// an error. /// an error.
lldb::addr_t GetLoadAddress() const; lldb::addr_t GetLoadAddress() const;
/// Get the size in bytes of a non-error instance of this class
static size_t GetNonErrorMemoryUsage();
/// \return /// \return
/// An \a llvm::Error object if this class corresponds to an Error, or an /// An \a llvm::Error object if this class corresponds to an Error, or an
/// \a llvm::Error::success otherwise. /// \a llvm::Error::success otherwise.
@ -112,6 +115,8 @@ private:
IntelPTInstruction(const IntelPTInstruction &other) = delete; IntelPTInstruction(const IntelPTInstruction &other) = delete;
const IntelPTInstruction &operator=(const IntelPTInstruction &other) = delete; const IntelPTInstruction &operator=(const IntelPTInstruction &other) = delete;
// When adding new members to this class, make sure to update
// IntelPTInstruction::GetNonErrorMemoryUsage() if needed.
pt_insn m_pt_insn; pt_insn m_pt_insn;
llvm::Optional<uint64_t> m_timestamp; llvm::Optional<uint64_t> m_timestamp;
std::unique_ptr<llvm::ErrorInfoBase> m_error; std::unique_ptr<llvm::ErrorInfoBase> m_error;
@ -150,7 +155,13 @@ public:
/// The size of the trace. /// The size of the trace.
size_t GetRawTraceSize() const; size_t GetRawTraceSize() const;
/// The approximate size in bytes used by this instance,
/// including all the already decoded instructions.
size_t CalculateApproximateMemoryUsage() const;
private: private:
/// When adding new members to this class, make sure
/// to update \a CalculateApproximateMemoryUsage() accordingly.
lldb::ThreadSP m_thread_sp; lldb::ThreadSP m_thread_sp;
std::vector<IntelPTInstruction> m_instructions; std::vector<IntelPTInstruction> m_instructions;
size_t m_raw_trace_size; size_t m_raw_trace_size;

View File

@ -111,9 +111,13 @@ void TraceIntelPT::DumpTraceInfo(Thread &thread, Stream &s, bool verbose) {
return; return;
} }
s.Printf("\n"); s.Printf("\n");
s.Printf(" Raw trace size: %zu bytes\n", *raw_size);
size_t mem_used = Decode(thread)->CalculateApproximateMemoryUsage();
s.Printf(" Raw trace size: %zu KiB\n", *raw_size / 1024);
s.Printf(" Total number of instructions: %zu\n", s.Printf(" Total number of instructions: %zu\n",
Decode(thread)->GetInstructions().size()); Decode(thread)->GetInstructions().size());
s.Printf(" Total approximate memory usage: %0.2lf KiB\n",
(double)mem_used / 1024);
return; return;
} }

View File

@ -38,5 +38,6 @@ class TestTraceDumpInfo(TraceIntelPTTestCaseBase):
substrs=['''Trace technology: intel-pt substrs=['''Trace technology: intel-pt
thread #1: tid = 3842849 thread #1: tid = 3842849
Raw trace size: 4096 bytes Raw trace size: 4 KiB
Total number of instructions: 21''']) Total number of instructions: 21
Total approximate memory usage: 5.38 KiB'''])