: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
97 lines
3.4 KiB
C++
97 lines
3.4 KiB
C++
//===-- TraceIntelPTGDBRemotePackets.cpp ------------------------*- C++ -*-===//
|
|
//
|
|
// 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 "lldb/Utility/TraceIntelPTGDBRemotePackets.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::json;
|
|
|
|
namespace lldb_private {
|
|
|
|
const char *IntelPTDataKinds::kProcFsCpuInfo = "procfsCpuInfo";
|
|
const char *IntelPTDataKinds::kTraceBuffer = "traceBuffer";
|
|
const char *IntelPTDataKinds::kPerfContextSwitchTrace =
|
|
"perfContextSwitchTrace";
|
|
|
|
bool TraceIntelPTStartRequest::IsPerCoreTracing() const {
|
|
return per_core_tracing.getValueOr(false);
|
|
}
|
|
|
|
bool fromJSON(const json::Value &value, TraceIntelPTStartRequest &packet,
|
|
Path path) {
|
|
ObjectMapper o(value, path);
|
|
if (!o || !fromJSON(value, (TraceStartRequest &)packet, path) ||
|
|
!o.map("enableTsc", packet.enable_tsc) ||
|
|
!o.map("psbPeriod", packet.psb_period) ||
|
|
!o.map("traceBufferSize", packet.trace_buffer_size))
|
|
return false;
|
|
|
|
if (packet.IsProcessTracing()) {
|
|
if (!o.map("processBufferSizeLimit", packet.process_buffer_size_limit) ||
|
|
!o.map("perCoreTracing", packet.per_core_tracing))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
json::Value toJSON(const TraceIntelPTStartRequest &packet) {
|
|
json::Value base = toJSON((const TraceStartRequest &)packet);
|
|
json::Object &obj = *base.getAsObject();
|
|
obj.try_emplace("traceBufferSize", packet.trace_buffer_size);
|
|
obj.try_emplace("processBufferSizeLimit", packet.process_buffer_size_limit);
|
|
obj.try_emplace("psbPeriod", packet.psb_period);
|
|
obj.try_emplace("enableTsc", packet.enable_tsc);
|
|
obj.try_emplace("perCoreTracing", packet.per_core_tracing);
|
|
return base;
|
|
}
|
|
|
|
std::chrono::nanoseconds LinuxPerfZeroTscConversion::ToNanos(uint64_t tsc) {
|
|
uint64_t quot = tsc >> time_shift;
|
|
uint64_t rem_flag = (((uint64_t)1 << time_shift) - 1);
|
|
uint64_t rem = tsc & rem_flag;
|
|
return std::chrono::nanoseconds{time_zero + quot * time_mult +
|
|
((rem * time_mult) >> time_shift)};
|
|
}
|
|
|
|
json::Value toJSON(const LinuxPerfZeroTscConversion &packet) {
|
|
return json::Value(json::Object{
|
|
{"timeMult", packet.time_mult},
|
|
{"timeShift", packet.time_shift},
|
|
{"timeZero", packet.time_zero},
|
|
});
|
|
}
|
|
|
|
bool fromJSON(const json::Value &value, LinuxPerfZeroTscConversion &packet,
|
|
json::Path path) {
|
|
ObjectMapper o(value, path);
|
|
uint64_t time_mult, time_shift, time_zero;
|
|
if (!o || !o.map("timeMult", time_mult) || !o.map("timeShift", time_shift) ||
|
|
!o.map("timeZero", time_zero))
|
|
return false;
|
|
packet.time_mult = time_mult;
|
|
packet.time_zero = time_zero;
|
|
packet.time_shift = time_shift;
|
|
return true;
|
|
}
|
|
|
|
bool fromJSON(const json::Value &value, TraceIntelPTGetStateResponse &packet,
|
|
json::Path path) {
|
|
ObjectMapper o(value, path);
|
|
return o && fromJSON(value, (TraceGetStateResponse &)packet, path) &&
|
|
o.map("tscPerfZeroConversion", packet.tsc_perf_zero_conversion);
|
|
}
|
|
|
|
json::Value toJSON(const TraceIntelPTGetStateResponse &packet) {
|
|
json::Value base = toJSON((const TraceGetStateResponse &)packet);
|
|
base.getAsObject()->insert(
|
|
{"tscPerfZeroConversion", packet.tsc_perf_zero_conversion});
|
|
return base;
|
|
}
|
|
|
|
} // namespace lldb_private
|