1*0b57cec5SDimitry Andric //===- FDRTraceExpander.h - XRay FDR Mode Log Expander --------------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric // 9*0b57cec5SDimitry Andric // We define an FDR record visitor which can re-constitute XRayRecord instances 10*0b57cec5SDimitry Andric // from a sequence of FDR mode records in arrival order into a collection. 11*0b57cec5SDimitry Andric // 12*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 13*0b57cec5SDimitry Andric #ifndef INCLUDE_LLVM_XRAY_FDRTRACEEXPANDER_H_ 14*0b57cec5SDimitry Andric #define INCLUDE_LLVM_XRAY_FDRTRACEEXPANDER_H_ 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h" 17*0b57cec5SDimitry Andric #include "llvm/XRay/FDRRecords.h" 18*0b57cec5SDimitry Andric #include "llvm/XRay/XRayRecord.h" 19*0b57cec5SDimitry Andric 20*0b57cec5SDimitry Andric namespace llvm { 21*0b57cec5SDimitry Andric namespace xray { 22*0b57cec5SDimitry Andric 23*0b57cec5SDimitry Andric class TraceExpander : public RecordVisitor { 24*0b57cec5SDimitry Andric // Type-erased callback for handling individual XRayRecord instances. 25*0b57cec5SDimitry Andric function_ref<void(const XRayRecord &)> C; 26*0b57cec5SDimitry Andric int32_t PID = 0; 27*0b57cec5SDimitry Andric int32_t TID = 0; 28*0b57cec5SDimitry Andric uint64_t BaseTSC = 0; 29*0b57cec5SDimitry Andric XRayRecord CurrentRecord{0, 0, RecordTypes::ENTER, 0, 0, 0, 0, {}, {}}; 30*0b57cec5SDimitry Andric uint16_t CPUId = 0; 31*0b57cec5SDimitry Andric uint16_t LogVersion = 0; 32*0b57cec5SDimitry Andric bool BuildingRecord = false; 33*0b57cec5SDimitry Andric bool IgnoringRecords = false; 34*0b57cec5SDimitry Andric 35*0b57cec5SDimitry Andric void resetCurrentRecord(); 36*0b57cec5SDimitry Andric 37*0b57cec5SDimitry Andric public: 38*0b57cec5SDimitry Andric explicit TraceExpander(function_ref<void(const XRayRecord &)> F, uint16_t L) 39*0b57cec5SDimitry Andric : RecordVisitor(), C(std::move(F)), LogVersion(L) {} 40*0b57cec5SDimitry Andric 41*0b57cec5SDimitry Andric Error visit(BufferExtents &) override; 42*0b57cec5SDimitry Andric Error visit(WallclockRecord &) override; 43*0b57cec5SDimitry Andric Error visit(NewCPUIDRecord &) override; 44*0b57cec5SDimitry Andric Error visit(TSCWrapRecord &) override; 45*0b57cec5SDimitry Andric Error visit(CustomEventRecord &) override; 46*0b57cec5SDimitry Andric Error visit(CallArgRecord &) override; 47*0b57cec5SDimitry Andric Error visit(PIDRecord &) override; 48*0b57cec5SDimitry Andric Error visit(NewBufferRecord &) override; 49*0b57cec5SDimitry Andric Error visit(EndBufferRecord &) override; 50*0b57cec5SDimitry Andric Error visit(FunctionRecord &) override; 51*0b57cec5SDimitry Andric Error visit(CustomEventRecordV5 &) override; 52*0b57cec5SDimitry Andric Error visit(TypedEventRecord &) override; 53*0b57cec5SDimitry Andric 54*0b57cec5SDimitry Andric // Must be called after all the records have been processed, to handle the 55*0b57cec5SDimitry Andric // most recent record generated. 56*0b57cec5SDimitry Andric Error flush(); 57*0b57cec5SDimitry Andric }; 58*0b57cec5SDimitry Andric 59*0b57cec5SDimitry Andric } // namespace xray 60*0b57cec5SDimitry Andric } // namespace llvm 61*0b57cec5SDimitry Andric 62*0b57cec5SDimitry Andric #endif // INCLUDE_LLVM_XRAY_FDRTRACEEXPANDER_H_ 63