:q! This diff is massive, but it's because it connects the client with lldb-server and also ensures that the postmortem case works. - Flatten the postmortem trace schema. The reason is that the schema has become quite complex due to the new multicore case, which defeats the original purpose of having a schema that could work for every trace plug-in. At this point, it's better that each trace plug-in defines it's own full schema. This means that the only common field is "type". -- Because of this new approach, I merged the "common" trace load and saving functionalities into the IntelPT one. This simplified the code quite a bit. If we eventually implement another trace plug-in, we can see then what we could reuse. -- The new schema, which is flattened, has now better comments and is parsed better. A change I did was to disallow hex addresses, because they are a bit error prone. I'm asking now to print the address in decimal. -- Renamed "intel" to "GenuineIntel" in the schema because that's what you see in /proc/cpuinfo. - Implemented reading the context switch trace data buffer. I had to do some refactors to do that cleanly. -- A major change that I did here was to simplify the perf_event circular buffer reading logic. It was too complex. Maybe the original Intel author had something different in mind. - Implemented all the necessary bits to read trace.json files with per-core data. - Implemented all the necessary bits to save to disk per-core trace session. - Added a test that ensures that parsing and saving to disk works. Differential Revision: https://reviews.llvm.org/D126015
67 lines
2.3 KiB
C++
67 lines
2.3 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<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;
|
|
}
|