Path: blob/main/contrib/llvm-project/llvm/lib/XRay/FDRTraceExpander.cpp
35233 views
//===- FDRTraceExpander.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7#include "llvm/XRay/FDRTraceExpander.h"89namespace llvm {10namespace xray {1112void TraceExpander::resetCurrentRecord() {13if (BuildingRecord)14C(CurrentRecord);15BuildingRecord = false;16CurrentRecord.CallArgs.clear();17CurrentRecord.Data.clear();18}1920Error TraceExpander::visit(BufferExtents &) {21resetCurrentRecord();22return Error::success();23}2425Error TraceExpander::visit(WallclockRecord &) { return Error::success(); }2627Error TraceExpander::visit(NewCPUIDRecord &R) {28CPUId = R.cpuid();29BaseTSC = R.tsc();30return Error::success();31}3233Error TraceExpander::visit(TSCWrapRecord &R) {34BaseTSC = R.tsc();35return Error::success();36}3738Error TraceExpander::visit(CustomEventRecord &R) {39resetCurrentRecord();40if (!IgnoringRecords) {41CurrentRecord.TSC = R.tsc();42CurrentRecord.CPU = R.cpu();43CurrentRecord.PId = PID;44CurrentRecord.TId = TID;45CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;46CurrentRecord.Data = std::string(R.data());47BuildingRecord = true;48}49return Error::success();50}5152Error TraceExpander::visit(CustomEventRecordV5 &R) {53resetCurrentRecord();54if (!IgnoringRecords) {55BaseTSC += R.delta();56CurrentRecord.TSC = BaseTSC;57CurrentRecord.CPU = CPUId;58CurrentRecord.PId = PID;59CurrentRecord.TId = TID;60CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;61CurrentRecord.Data = std::string(R.data());62BuildingRecord = true;63}64return Error::success();65}6667Error TraceExpander::visit(TypedEventRecord &R) {68resetCurrentRecord();69if (!IgnoringRecords) {70BaseTSC += R.delta();71CurrentRecord.TSC = BaseTSC;72CurrentRecord.CPU = CPUId;73CurrentRecord.PId = PID;74CurrentRecord.TId = TID;75CurrentRecord.RecordType = R.eventType();76CurrentRecord.Type = RecordTypes::TYPED_EVENT;77CurrentRecord.Data = std::string(R.data());78BuildingRecord = true;79}80return Error::success();81}8283Error TraceExpander::visit(CallArgRecord &R) {84CurrentRecord.CallArgs.push_back(R.arg());85CurrentRecord.Type = RecordTypes::ENTER_ARG;86return Error::success();87}8889Error TraceExpander::visit(PIDRecord &R) {90PID = R.pid();91return Error::success();92}9394Error TraceExpander::visit(NewBufferRecord &R) {95if (IgnoringRecords)96IgnoringRecords = false;97TID = R.tid();98if (LogVersion == 2)99PID = R.tid();100return Error::success();101}102103Error TraceExpander::visit(EndBufferRecord &) {104IgnoringRecords = true;105resetCurrentRecord();106return Error::success();107}108109Error TraceExpander::visit(FunctionRecord &R) {110resetCurrentRecord();111if (!IgnoringRecords) {112BaseTSC += R.delta();113CurrentRecord.Type = R.recordType();114CurrentRecord.FuncId = R.functionId();115CurrentRecord.TSC = BaseTSC;116CurrentRecord.PId = PID;117CurrentRecord.TId = TID;118CurrentRecord.CPU = CPUId;119BuildingRecord = true;120}121return Error::success();122}123124Error TraceExpander::flush() {125resetCurrentRecord();126return Error::success();127}128129} // namespace xray130} // namespace llvm131132133