forked from OSchip/llvm-project
[trace][intelpt] Remove code smell when printing the raw trace size
Something ugly I did was to report the trace buffer size to the DecodedThread, which is later used as part of the `dump info` command. Instead of doing that, we can just directly ask the trace for the raw buffer and print its size. I thought about not asking for the entire trace but instead just for its size, but in this case, as our traces as not extremely big, I prefer to ask for the entire trace, ensuring it could be fetched, and then print its size. Differential Revision: https://reviews.llvm.org/D123358
This commit is contained in:
parent
bdf3e7e5b8
commit
44103c96fa
|
@ -35,10 +35,6 @@ void IntelPTError::log(llvm::raw_ostream &OS) const {
|
|||
OS << "error: " << libipt_error_message;
|
||||
}
|
||||
|
||||
Optional<size_t> DecodedThread::GetRawTraceSize() const {
|
||||
return m_raw_trace_size;
|
||||
}
|
||||
|
||||
size_t DecodedThread::GetInstructionsCount() const {
|
||||
return m_instruction_ips.size();
|
||||
}
|
||||
|
@ -178,8 +174,6 @@ DecodedThread::DecodedThread(ThreadSP thread_sp, Error &&error)
|
|||
AppendError(std::move(error));
|
||||
}
|
||||
|
||||
void DecodedThread::SetRawTraceSize(size_t size) { m_raw_trace_size = size; }
|
||||
|
||||
lldb::TraceCursorUP DecodedThread::GetCursor() {
|
||||
// We insert a fake error signaling an empty trace if needed becasue the
|
||||
// TraceCursor requires non-empty traces.
|
||||
|
|
|
@ -175,15 +175,6 @@ public:
|
|||
/// Get a new cursor for the decoded thread.
|
||||
lldb::TraceCursorUP GetCursor();
|
||||
|
||||
/// Set the size in bytes of the corresponding Intel PT raw trace.
|
||||
void SetRawTraceSize(size_t size);
|
||||
|
||||
/// Get the size in bytes of the corresponding Intel PT raw trace.
|
||||
///
|
||||
/// \return
|
||||
/// The size of the trace, or \b llvm::None if not available.
|
||||
llvm::Optional<size_t> GetRawTraceSize() const;
|
||||
|
||||
/// Return the number of TSC decoding errors that happened. A TSC error
|
||||
/// is not a fatal error and doesn't create gaps in the trace. Instead
|
||||
/// we only keep track of them as a statistic.
|
||||
|
|
|
@ -290,8 +290,6 @@ CreateInstructionDecoder(DecodedThread &decoded_thread,
|
|||
void lldb_private::trace_intel_pt::DecodeTrace(DecodedThread &decoded_thread,
|
||||
TraceIntelPT &trace_intel_pt,
|
||||
ArrayRef<uint8_t> buffer) {
|
||||
decoded_thread.SetRawTraceSize(buffer.size());
|
||||
|
||||
Expected<PtInsnDecoderUP> decoder_up =
|
||||
CreateInstructionDecoder(decoded_thread, trace_intel_pt, buffer);
|
||||
if (!decoder_up)
|
||||
|
|
|
@ -106,20 +106,27 @@ lldb::TraceCursorUP TraceIntelPT::GetCursor(Thread &thread) {
|
|||
}
|
||||
|
||||
void TraceIntelPT::DumpTraceInfo(Thread &thread, Stream &s, bool verbose) {
|
||||
Optional<size_t> raw_size = GetRawTraceSize(thread);
|
||||
lldb::tid_t tid = thread.GetID();
|
||||
s.Format("\nthread #{0}: tid = {1}", thread.GetIndexID(), thread.GetID());
|
||||
if (!raw_size) {
|
||||
if (!IsTraced(tid)) {
|
||||
s << ", not traced\n";
|
||||
return;
|
||||
}
|
||||
s << "\n";
|
||||
|
||||
Expected<size_t> raw_size = GetRawTraceSize(thread);
|
||||
if (!raw_size) {
|
||||
s.Format(" {0}\n", toString(raw_size.takeError()));
|
||||
return;
|
||||
}
|
||||
|
||||
DecodedThreadSP decoded_trace_sp = Decode(thread);
|
||||
size_t insn_len = decoded_trace_sp->GetInstructionsCount();
|
||||
size_t mem_used = decoded_trace_sp->CalculateApproximateMemoryUsage();
|
||||
|
||||
s.Format(" Total number of instructions: {0}\n", insn_len);
|
||||
|
||||
s.PutCString("\n Memory usage:\n");
|
||||
s << "\n Memory usage:\n";
|
||||
s.Format(" Raw trace size: {0} KiB\n", *raw_size / 1024);
|
||||
s.Format(
|
||||
" Total approximate memory usage (excluding raw trace): {0:2} KiB\n",
|
||||
|
@ -129,15 +136,13 @@ void TraceIntelPT::DumpTraceInfo(Thread &thread, Stream &s, bool verbose) {
|
|||
"{0:2} bytes\n",
|
||||
(double)mem_used / insn_len);
|
||||
|
||||
s.PutCString("\n Timing:\n");
|
||||
GetTimer()
|
||||
.ForThread(thread.GetID())
|
||||
.ForEachTimedTask(
|
||||
[&](const std::string &name, std::chrono::milliseconds duration) {
|
||||
s.Format(" {0}: {1:2}s\n", name, duration.count() / 1000.0);
|
||||
});
|
||||
s << "\n Timing:\n";
|
||||
GetTimer().ForThread(tid).ForEachTimedTask(
|
||||
[&](const std::string &name, std::chrono::milliseconds duration) {
|
||||
s.Format(" {0}: {1:2}s\n", name, duration.count() / 1000.0);
|
||||
});
|
||||
|
||||
s.PutCString("\n Errors:\n");
|
||||
s << "\n Errors:\n";
|
||||
const DecodedThread::LibiptErrors &tsc_errors =
|
||||
decoded_trace_sp->GetTscErrors();
|
||||
s.Format(" Number of TSC decoding errors: {0}\n", tsc_errors.total_count);
|
||||
|
@ -147,11 +152,16 @@ void TraceIntelPT::DumpTraceInfo(Thread &thread, Stream &s, bool verbose) {
|
|||
}
|
||||
}
|
||||
|
||||
Optional<size_t> TraceIntelPT::GetRawTraceSize(Thread &thread) {
|
||||
if (IsTraced(thread.GetID()))
|
||||
return Decode(thread)->GetRawTraceSize();
|
||||
else
|
||||
return None;
|
||||
llvm::Expected<size_t> TraceIntelPT::GetRawTraceSize(Thread &thread) {
|
||||
size_t size;
|
||||
auto callback = [&](llvm::ArrayRef<uint8_t> data) {
|
||||
size = data.size();
|
||||
return Error::success();
|
||||
};
|
||||
if (Error err = OnThreadBufferRead(thread.GetID(), callback))
|
||||
return std::move(err);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
Expected<pt_cpu> TraceIntelPT::GetCPUInfoForLiveProcess() {
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
|
||||
void DumpTraceInfo(Thread &thread, Stream &s, bool verbose) override;
|
||||
|
||||
llvm::Optional<size_t> GetRawTraceSize(Thread &thread);
|
||||
llvm::Expected<size_t> GetRawTraceSize(Thread &thread);
|
||||
|
||||
void DoRefreshLiveProcessState(
|
||||
llvm::Expected<TraceGetStateResponse> state) override;
|
||||
|
|
Loading…
Reference in New Issue