This improves several things and addresses comments up to the diff [11] in this stack. - Simplify many functions to receive less parameters that they can identify easily - Create Storage classes for Trace and TraceIntelPT that can make it easier to reason about what can change with live process refreshes and what cannot. - Don't cache the perf zero conversion numbers in lldb-server to make sure we get the most up-to-date numbers. - Move the thread identifaction from context switches to the bundle parser, to leave TraceIntelPT simpler. This also makes sure that the constructor of TraceIntelPT is invoked when the entire data has been checked to be correct. - Normalize all bundle paths before the Processes, Threads and Modules are created, so that they can assume that all paths are correct and absolute - Fix some issues in the tests. Now they all pass. - return the specific instance when constructing PerThread and MultiCore processor tracers. - Properly implement IntelPTMultiCoreTrace::TraceStart. - Improve some comments. - Use the typedef ContextSwitchTrace more often for clarity. - Move CreateContextSwitchTracePerfEvent to Perf.h as a utility function. - Synchronize better the state of the context switch and the intel pt perf events. - Use a booblean instead of an enum for the PerfEvent state. Differential Revision: https://reviews.llvm.org/D127456
68 lines
2.4 KiB
C++
68 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);
|
|
}
|
|
|
|
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<llvm::Optional<std::vector<uint8_t>>>
|
|
IntelPTPerThreadProcessTrace::TryGetBinaryData(
|
|
const TraceGetBinaryDataRequest &request) {
|
|
return m_thread_traces.TryGetBinaryData(request);
|
|
}
|
|
|
|
Expected<std::unique_ptr<IntelPTPerThreadProcessTrace>>
|
|
IntelPTPerThreadProcessTrace::Start(const TraceIntelPTStartRequest &request,
|
|
ArrayRef<lldb::tid_t> current_tids) {
|
|
std::unique_ptr<IntelPTPerThreadProcessTrace> 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;
|
|
}
|