2018-09-11 08:45:59 +02:00
|
|
|
//===- FDRTraceExpander.cpp -----------------------------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2018-09-11 08:45:59 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/XRay/FDRTraceExpander.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace xray {
|
|
|
|
|
|
|
|
void TraceExpander::resetCurrentRecord() {
|
2018-11-06 09:51:37 +01:00
|
|
|
if (BuildingRecord)
|
2018-09-11 08:45:59 +02:00
|
|
|
C(CurrentRecord);
|
2018-11-06 09:51:37 +01:00
|
|
|
BuildingRecord = false;
|
2018-09-11 08:45:59 +02:00
|
|
|
CurrentRecord.CallArgs.clear();
|
2018-11-06 09:51:37 +01:00
|
|
|
CurrentRecord.Data.clear();
|
2018-09-11 08:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(BufferExtents &) {
|
|
|
|
resetCurrentRecord();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(WallclockRecord &) { return Error::success(); }
|
|
|
|
|
|
|
|
Error TraceExpander::visit(NewCPUIDRecord &R) {
|
|
|
|
CPUId = R.cpuid();
|
|
|
|
BaseTSC = R.tsc();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(TSCWrapRecord &R) {
|
|
|
|
BaseTSC = R.tsc();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2018-11-06 09:51:37 +01:00
|
|
|
Error TraceExpander::visit(CustomEventRecord &R) {
|
2018-09-11 08:45:59 +02:00
|
|
|
resetCurrentRecord();
|
2018-11-06 09:51:37 +01:00
|
|
|
if (!IgnoringRecords) {
|
|
|
|
CurrentRecord.TSC = R.tsc();
|
|
|
|
CurrentRecord.CPU = R.cpu();
|
|
|
|
CurrentRecord.PId = PID;
|
|
|
|
CurrentRecord.TId = TID;
|
|
|
|
CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
|
2020-01-28 20:23:46 +01:00
|
|
|
CurrentRecord.Data = std::string(R.data());
|
2018-11-06 09:51:37 +01:00
|
|
|
BuildingRecord = true;
|
|
|
|
}
|
2018-09-11 08:45:59 +02:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2018-11-07 05:37:42 +01:00
|
|
|
Error TraceExpander::visit(CustomEventRecordV5 &R) {
|
|
|
|
resetCurrentRecord();
|
|
|
|
if (!IgnoringRecords) {
|
|
|
|
BaseTSC += R.delta();
|
|
|
|
CurrentRecord.TSC = BaseTSC;
|
|
|
|
CurrentRecord.CPU = CPUId;
|
|
|
|
CurrentRecord.PId = PID;
|
|
|
|
CurrentRecord.TId = TID;
|
|
|
|
CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
|
2020-01-28 20:23:46 +01:00
|
|
|
CurrentRecord.Data = std::string(R.data());
|
2018-11-07 05:37:42 +01:00
|
|
|
BuildingRecord = true;
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(TypedEventRecord &R) {
|
|
|
|
resetCurrentRecord();
|
|
|
|
if (!IgnoringRecords) {
|
|
|
|
BaseTSC += R.delta();
|
|
|
|
CurrentRecord.TSC = BaseTSC;
|
|
|
|
CurrentRecord.CPU = CPUId;
|
|
|
|
CurrentRecord.PId = PID;
|
|
|
|
CurrentRecord.TId = TID;
|
|
|
|
CurrentRecord.RecordType = R.eventType();
|
|
|
|
CurrentRecord.Type = RecordTypes::TYPED_EVENT;
|
2020-01-28 20:23:46 +01:00
|
|
|
CurrentRecord.Data = std::string(R.data());
|
2018-11-07 05:37:42 +01:00
|
|
|
BuildingRecord = true;
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2018-09-11 08:45:59 +02:00
|
|
|
Error TraceExpander::visit(CallArgRecord &R) {
|
|
|
|
CurrentRecord.CallArgs.push_back(R.arg());
|
|
|
|
CurrentRecord.Type = RecordTypes::ENTER_ARG;
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(PIDRecord &R) {
|
|
|
|
PID = R.pid();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(NewBufferRecord &R) {
|
|
|
|
if (IgnoringRecords)
|
|
|
|
IgnoringRecords = false;
|
|
|
|
TID = R.tid();
|
|
|
|
if (LogVersion == 2)
|
|
|
|
PID = R.tid();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(EndBufferRecord &) {
|
|
|
|
IgnoringRecords = true;
|
|
|
|
resetCurrentRecord();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::visit(FunctionRecord &R) {
|
|
|
|
resetCurrentRecord();
|
|
|
|
if (!IgnoringRecords) {
|
|
|
|
BaseTSC += R.delta();
|
|
|
|
CurrentRecord.Type = R.recordType();
|
|
|
|
CurrentRecord.FuncId = R.functionId();
|
|
|
|
CurrentRecord.TSC = BaseTSC;
|
|
|
|
CurrentRecord.PId = PID;
|
|
|
|
CurrentRecord.TId = TID;
|
|
|
|
CurrentRecord.CPU = CPUId;
|
2018-11-06 09:51:37 +01:00
|
|
|
BuildingRecord = true;
|
2018-09-11 08:45:59 +02:00
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error TraceExpander::flush() {
|
|
|
|
resetCurrentRecord();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xray
|
|
|
|
} // namespace llvm
|