Files
clang-p2996/lldb/source/Plugins/Process/Linux/IntelPTPerThreadProcessTrace.cpp
Walter Erquinigo 1f56f7fc16 [trace][intelpt] Support system-wide tracing [7] - Create a base IntelPTProcessTrace class
We have two different "process trace" implementations: per thread and per core. As a way to simplify the collector who uses both, I'm creating a base abstract class that is used by these implementations. This effectively simplify a good chunk of code.

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

70 lines
2.4 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);
}
TraceGetStateResponse IntelPTPerThreadProcessTrace::GetState() {
TraceGetStateResponse 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;
}