[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
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 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 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; +} 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 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 IntelPTInstruction::GetTimestampCounter() const { return
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
zrthxn updated this revision to Diff 416764. zrthxn added a comment. Clean up, works fine now Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ 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,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; } 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 @@ -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; 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 @@ -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; +} 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,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; } 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 @@ -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; 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 @@ -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; +} ___ ll
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
zrthxn updated this revision to Diff 416765. zrthxn added a comment. Fixed trace info test for this Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ 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 lldb/test/API/commands/trace/TestTraceDumpInfo.py Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -39,4 +39,5 @@ thread #1: tid = 3842849 Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Total number of instructions: 21 + Total memory usage: 1037 bytes''']) 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,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; } 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 @@ -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; 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 @@ -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; +} Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -39,4 +39,5 @@ thread #1: tid = 3842849 Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Total number of instructions: 21 + Total memory usage: 1037 bytes''']) 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,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; } 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 @@ -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
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
wallace requested changes to this revision. wallace added a comment. This revision now requires changes to proceed. Pretty nice! just some details i've noticed when reading your diff and good to go 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; 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. Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:85-95 + /// 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 ( I made a mistake. I didn't notice that there's an m_error member, whose size is dynamic, because it might hold a string message. However, the number of errors should be negligible compared to the total number of correct instructions, so, for global calculations, let's assume that all instructions are fine and they are not errors. Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:128 pt_insn m_pt_insn; llvm::Optional m_timestamp; Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:166-170 + /// Get the size in bytes of decoded Intel PT trace + /// + /// \return + /// The size of the decoded traces. + size_t GetMemoryUsage() const; We can put all the documentation in the \return section to avoid redundancy. Let's also use the word Calculate instead of Get because Get is supposed to be used for cheap operations and Calculate for maybe not so trivial ones. Comment at: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp:114 s.Printf("\n"); s.Printf(" Raw trace size: %zu bytes\n", *raw_size); s.Printf(" Total number of instructions: %zu\n", print this in KB, as it will be readability. You can assume that this number will always be an integer because the raw trace size by definition in the kernel is a multiple of 4KB. Comment at: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp:117 Decode(thread)->GetInstructions().size()); + s.Printf(" Total memory usage: %zu bytes\n", +Decode(thread)->GetMemoryUsage()); better print KB instead of bytes. you can use a double with two digits of precision Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ https://reviews.llvm.org/D122093 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
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 m_instructions; Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ https://reviews.llvm.org/D122093 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
zrthxn updated this revision to Diff 416797. zrthxn added a comment. Changed to KiB and fixed how caclulation is done Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ 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 lldb/test/API/commands/trace/TestTraceDumpInfo.py Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -38,5 +38,6 @@ substrs=['''Trace technology: intel-pt thread #1: tid = 3842849 - Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Raw trace size: 4 KiB + Total number of instructions: 21 + Total approximate memory usage: 5.38 KiB''']) 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 @@ -105,15 +105,18 @@ void TraceIntelPT::DumpTraceInfo(Thread &thread, Stream &s, bool verbose) { Optional raw_size = GetRawTraceSize(thread); + size_t mem_used = Decode(thread)->CalculateApproximateMemoryUsage(); s.Printf("\nthread #%u: tid = %" PRIu64, thread.GetIndexID(), thread.GetID()); if (!raw_size) { s.Printf(", not traced\n"); return; } s.Printf("\n"); - s.Printf(" Raw trace size: %zu bytes\n", *raw_size); - s.Printf(" Total number of instructions: %zu\n", -Decode(thread)->GetInstructions().size()); + s.Printf(" Raw trace size: %zu KiB\n", *raw_size / 1024); + s.Printf(" Total number of instructions: %zu\n", + Decode(thread)->GetInstructions().size()); + s.Printf(" Total approximate memory usage: %0.2lf KiB\n", + (float)mem_used / 1024); 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 @@ -81,6 +81,11 @@ /// 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 non-error instance of this class + static size_t GetNonErrorMemoryUsage() { +return sizeof(IntelPTInstruction); + } /// \return /// An \a llvm::Error object if this class corresponds to an Error, or an @@ -112,6 +117,8 @@ IntelPTInstruction(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; llvm::Optional m_timestamp; std::unique_ptr m_error; @@ -150,7 +157,13 @@ /// The size of the trace. size_t GetRawTraceSize() const; + /// The approximate size in bytes used by this instance, + /// including all the already decoded instructions. + size_t CalculateApproximateMemoryUsage() const; + private: + /// When adding new members to this class, make sure + /// to update \a CalculateApproximateMemoryUsage() accordingly. lldb::ThreadSP m_thread_sp; std::vector m_instructions; size_t m_raw_trace_size; 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 @@ -116,3 +116,14 @@ lldb::TraceCursorUP DecodedThread::GetCursor() { return std::make_unique(m_thread_sp, shared_from_this()); } + +size_t DecodedThread::CalculateApproximateMemoryUsage() const { + size_t non_err_instruction_count = 0; + for (const IntelPTInstruction &insn : m_instructions) +if (!insn.IsError()) + non_err_instruction_count++; + + return m_raw_trace_size ++ IntelPTInstruction::GetNonErrorMemoryUsage() * non_err_instruction_count ++ sizeof(DecodedThread); +} Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -38,5 +38,6 @@ substrs=['''Trace technology: intel-pt thread #1: tid = 3842849 - Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Raw trace size: 4 KiB + Total number of instructions: 21 + Total approximate memory usage: 5.38 KiB''']) Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp === --- lldb/source/Plugins/
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
wallace requested changes to this revision. wallace added a comment. This revision now requires changes to proceed. just some few remaining nits Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:85 + + /// Get the size in bytes of non-error instance of this class + static size_t GetNonErrorMemoryUsage() { Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:86-88 + static size_t GetNonErrorMemoryUsage() { +return sizeof(IntelPTInstruction); + } move the implementation of this this method to the corresponding cpp file. We try to keep all headers just as declarations to reduce the binary size, unless we try to achieve an optimization Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:121 + // When adding new members to this class, make sure to update + // IntelPTInstruction:: GetNonErrorMemoryUsage() if needed. pt_insn m_pt_insn; Comment at: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp:108-114 + size_t mem_used = Decode(thread)->CalculateApproximateMemoryUsage(); s.Printf("\nthread #%u: tid = %" PRIu64, thread.GetIndexID(), thread.GetID()); if (!raw_size) { s.Printf(", not traced\n"); return; } s.Printf("\n"); only calculate the memory usage if used, which happens after the early terminated if Comment at: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp:119 + s.Printf(" Total approximate memory usage: %0.2lf KiB\n", + (float)mem_used / 1024); return; use double instead of float. double has more precision Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ https://reviews.llvm.org/D122093 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
zrthxn marked 4 inline comments as done. zrthxn added inline comments. Comment at: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp:119 + s.Printf(" Total approximate memory usage: %0.2lf KiB\n", + (float)mem_used / 1024); return; wallace wrote: > use double instead of float. double has more precision But since we're showing only two decimal places, which gets rounded up, the precision eventually gets thrown away... doesn't it? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ https://reviews.llvm.org/D122093 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
zrthxn updated this revision to Diff 416825. zrthxn marked an inline comment as done. zrthxn added a comment. Cosmetic and minor changes Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ 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 lldb/test/API/commands/trace/TestTraceDumpInfo.py Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -38,5 +38,6 @@ substrs=['''Trace technology: intel-pt thread #1: tid = 3842849 - Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Raw trace size: 4 KiB + Total number of instructions: 21 + Total approximate memory usage: 5.38 KiB''']) 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 @@ -111,9 +111,13 @@ return; } s.Printf("\n"); - s.Printf(" Raw trace size: %zu bytes\n", *raw_size); - s.Printf(" Total number of instructions: %zu\n", -Decode(thread)->GetInstructions().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", + Decode(thread)->GetInstructions().size()); + s.Printf(" Total approximate memory usage: %0.2lf KiB\n", + (double)mem_used / 1024); 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 @@ -81,6 +81,9 @@ /// 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 a non-error instance of this class + size_t GetNonErrorMemoryUsage() const; /// \return /// An \a llvm::Error object if this class corresponds to an Error, or an @@ -112,6 +115,8 @@ IntelPTInstruction(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; llvm::Optional m_timestamp; std::unique_ptr m_error; @@ -150,7 +155,13 @@ /// The size of the trace. size_t GetRawTraceSize() const; + /// The approximate size in bytes used by this instance, + /// including all the already decoded instructions. + size_t CalculateApproximateMemoryUsage() const; + private: + /// When adding new members to this class, make sure + /// to update \a CalculateApproximateMemoryUsage() accordingly. lldb::ThreadSP m_thread_sp; std::vector m_instructions; size_t m_raw_trace_size; 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,8 @@ lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; } +size_t IntelPTInstruction::GetNonErrorMemoryUsage() const { return sizeof(IntelPTInstruction); } + Optional IntelPTInstruction::GetTimestampCounter() const { return m_timestamp; } @@ -116,3 +118,14 @@ lldb::TraceCursorUP DecodedThread::GetCursor() { return std::make_unique(m_thread_sp, shared_from_this()); } + +size_t DecodedThread::CalculateApproximateMemoryUsage() const { + size_t non_err_instruction_count = 0; + for (const IntelPTInstruction &insn : m_instructions) +if (!insn.IsError()) + non_err_instruction_count++; + + return m_raw_trace_size ++ IntelPTInstruction::GetNonErrorMemoryUsage() * non_err_instruction_count ++ sizeof(DecodedThread); +} Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -38,5 +38,6 @@ substrs=['''Trace technology: intel-pt thread #1: tid = 3842849 - Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Raw trace size: 4 KiB + Total number of instructions: 21 + Total approximate memory usage: 5.38 KiB''']) Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp === --- lldb/source/Plugi
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
wallace requested changes to this revision. wallace added inline comments. This revision now requires changes to proceed. Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp:123-130 + size_t non_err_instruction_count = 0; + for (const IntelPTInstruction &insn : m_instructions) +if (!insn.IsError()) + non_err_instruction_count++; + + return m_raw_trace_size ++ IntelPTInstruction::GetNonErrorMemoryUsage() * non_err_instruction_count as discussed offline, this should just be Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ https://reviews.llvm.org/D122093 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D122093: [trace][intelpt] Added total memory usage by decoded trace
zrthxn updated this revision to Diff 416826. zrthxn added a comment. Ingore errored instructions Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122093/new/ 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 lldb/test/API/commands/trace/TestTraceDumpInfo.py Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -38,5 +38,6 @@ substrs=['''Trace technology: intel-pt thread #1: tid = 3842849 - Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Raw trace size: 4 KiB + Total number of instructions: 21 + Total approximate memory usage: 5.38 KiB''']) 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 @@ -111,9 +111,13 @@ return; } s.Printf("\n"); - s.Printf(" Raw trace size: %zu bytes\n", *raw_size); - s.Printf(" Total number of instructions: %zu\n", -Decode(thread)->GetInstructions().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", + Decode(thread)->GetInstructions().size()); + s.Printf(" Total approximate memory usage: %0.2lf KiB\n", + (double)mem_used / 1024); 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 @@ -81,6 +81,9 @@ /// 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 a non-error instance of this class + static size_t GetNonErrorMemoryUsage(); /// \return /// An \a llvm::Error object if this class corresponds to an Error, or an @@ -112,6 +115,8 @@ IntelPTInstruction(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; llvm::Optional m_timestamp; std::unique_ptr m_error; @@ -150,7 +155,13 @@ /// The size of the trace. size_t GetRawTraceSize() const; + /// The approximate size in bytes used by this instance, + /// including all the already decoded instructions. + size_t CalculateApproximateMemoryUsage() const; + private: + /// When adding new members to this class, make sure + /// to update \a CalculateApproximateMemoryUsage() accordingly. lldb::ThreadSP m_thread_sp; std::vector m_instructions; size_t m_raw_trace_size; 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,8 @@ lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; } +size_t IntelPTInstruction::GetNonErrorMemoryUsage() { return sizeof(IntelPTInstruction); } + Optional IntelPTInstruction::GetTimestampCounter() const { return m_timestamp; } @@ -116,3 +118,9 @@ lldb::TraceCursorUP DecodedThread::GetCursor() { return std::make_unique(m_thread_sp, shared_from_this()); } + +size_t DecodedThread::CalculateApproximateMemoryUsage() const { + return m_raw_trace_size ++ IntelPTInstruction::GetNonErrorMemoryUsage() * m_instructions.size() ++ sizeof(DecodedThread); +} Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py === --- lldb/test/API/commands/trace/TestTraceDumpInfo.py +++ lldb/test/API/commands/trace/TestTraceDumpInfo.py @@ -38,5 +38,6 @@ substrs=['''Trace technology: intel-pt thread #1: tid = 3842849 - Raw trace size: 4096 bytes - Total number of instructions: 21''']) + Raw trace size: 4 KiB + Total number of instructions: 21 + Total approximate memory usage: 5.38 KiB''']) 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 @@ -111,9 +111,13 @@ return; } s.Printf("\n"); - s.Printf(" Raw trace size: %zu bytes\n", *raw_size); - s.P