llvm-project/lldb/source/Plugins/Process/Linux/IntelPTPerThreadProcessTrace.cpp
Walter Erquinigo 1f2d49a8e7 [trace][intelpt] Support system-wide tracing [10] - Return warnings and tsc information from lldb-server.
- Add a warnings field in the jLLDBGetState response, for warnings to be delivered to the client for troubleshooting. This removes the need to silently log lldb-server's llvm::Errors and not expose them easily to the user
- Simplify the tscPerfZeroConversion struct and schema. It used to extend a base abstract class, but I'm doubting that we'll ever add other conversion mechanisms because all modern kernels support perf zero. It is also the one who is supposed to work with the timestamps produced by the context switch trace, so expecting it is imperative.
- Force tsc collection for cpu tracing.
- Add a test checking that tscPerfZeroConversion is returned by the GetState request
- Add a pre-check for cpu tracing that makes sure that perf zero values are available.

Differential Revision: https://reviews.llvm.org/D125932
2022-06-15 12:08:00 -07:00

70 lines
2.5 KiB
C++

//===-- IntelPTPerThreadProcessTrace.cpp ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "IntelPTPerThreadProcessTrace.h"
using namespace lldb;
using namespace lldb_private;
using namespace process_linux;
using namespace llvm;
bool IntelPTPerThreadProcessTrace::TracesThread(lldb::tid_t tid) const {
return m_thread_traces.TracesThread(tid);
}
Error IntelPTPerThreadProcessTrace::TraceStop(lldb::tid_t tid) {
return m_thread_traces.TraceStop(tid);
}
Error IntelPTPerThreadProcessTrace::TraceStart(lldb::tid_t tid) {
if (m_thread_traces.GetTotalBufferSize() +
m_tracing_params.trace_buffer_size >
static_cast<size_t>(*m_tracing_params.process_buffer_size_limit))
return createStringError(
inconvertibleErrorCode(),
"Thread %" PRIu64 " can't be traced as the process trace size limit "
"has been reached. Consider retracing with a higher "
"limit.",
tid);
return m_thread_traces.TraceStart(tid, m_tracing_params);
}
TraceIntelPTGetStateResponse IntelPTPerThreadProcessTrace::GetState() {
TraceIntelPTGetStateResponse state;
m_thread_traces.ForEachThread(
[&](lldb::tid_t tid, const IntelPTSingleBufferTrace &thread_trace) {
state.traced_threads.push_back({tid,
{{IntelPTDataKinds::kTraceBuffer,
thread_trace.GetTraceBufferSize()}}});
});
return state;
}
Expected<std::vector<uint8_t>> IntelPTPerThreadProcessTrace::GetBinaryData(
const TraceGetBinaryDataRequest &request) {
if (Expected<IntelPTSingleBufferTrace &> trace =
m_thread_traces.GetTracedThread(*request.tid))
return trace->GetTraceBuffer(request.offset, request.size);
else
return trace.takeError();
}
Expected<IntelPTProcessTraceUP>
IntelPTPerThreadProcessTrace::Start(const TraceIntelPTStartRequest &request,
ArrayRef<lldb::tid_t> current_tids) {
IntelPTProcessTraceUP trace(new IntelPTPerThreadProcessTrace(request));
Error error = Error::success();
for (lldb::tid_t tid : current_tids)
error = joinErrors(std::move(error), trace->TraceStart(tid));
if (error)
return std::move(error);
return trace;
}