10b57cec5SDimitry Andric //===- FDRTraceExpander.h - XRay FDR Mode Log Expander --------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // We define an FDR record visitor which can re-constitute XRayRecord instances 100b57cec5SDimitry Andric // from a sequence of FDR mode records in arrival order into a collection. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 13fe6060f1SDimitry Andric #ifndef LLVM_XRAY_FDRTRACEEXPANDER_H 14fe6060f1SDimitry Andric #define LLVM_XRAY_FDRTRACEEXPANDER_H 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h" 170b57cec5SDimitry Andric #include "llvm/XRay/FDRRecords.h" 180b57cec5SDimitry Andric #include "llvm/XRay/XRayRecord.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric namespace llvm { 210b57cec5SDimitry Andric namespace xray { 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric class TraceExpander : public RecordVisitor { 240b57cec5SDimitry Andric // Type-erased callback for handling individual XRayRecord instances. 250b57cec5SDimitry Andric function_ref<void(const XRayRecord &)> C; 260b57cec5SDimitry Andric int32_t PID = 0; 270b57cec5SDimitry Andric int32_t TID = 0; 280b57cec5SDimitry Andric uint64_t BaseTSC = 0; 290b57cec5SDimitry Andric XRayRecord CurrentRecord{0, 0, RecordTypes::ENTER, 0, 0, 0, 0, {}, {}}; 300b57cec5SDimitry Andric uint16_t CPUId = 0; 310b57cec5SDimitry Andric uint16_t LogVersion = 0; 320b57cec5SDimitry Andric bool BuildingRecord = false; 330b57cec5SDimitry Andric bool IgnoringRecords = false; 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric void resetCurrentRecord(); 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric public: TraceExpander(function_ref<void (const XRayRecord &)> F,uint16_t L)380b57cec5SDimitry Andric explicit TraceExpander(function_ref<void(const XRayRecord &)> F, uint16_t L) 39*04eeddc0SDimitry Andric : C(std::move(F)), LogVersion(L) {} 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric Error visit(BufferExtents &) override; 420b57cec5SDimitry Andric Error visit(WallclockRecord &) override; 430b57cec5SDimitry Andric Error visit(NewCPUIDRecord &) override; 440b57cec5SDimitry Andric Error visit(TSCWrapRecord &) override; 450b57cec5SDimitry Andric Error visit(CustomEventRecord &) override; 460b57cec5SDimitry Andric Error visit(CallArgRecord &) override; 470b57cec5SDimitry Andric Error visit(PIDRecord &) override; 480b57cec5SDimitry Andric Error visit(NewBufferRecord &) override; 490b57cec5SDimitry Andric Error visit(EndBufferRecord &) override; 500b57cec5SDimitry Andric Error visit(FunctionRecord &) override; 510b57cec5SDimitry Andric Error visit(CustomEventRecordV5 &) override; 520b57cec5SDimitry Andric Error visit(TypedEventRecord &) override; 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric // Must be called after all the records have been processed, to handle the 550b57cec5SDimitry Andric // most recent record generated. 560b57cec5SDimitry Andric Error flush(); 570b57cec5SDimitry Andric }; 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric } // namespace xray 600b57cec5SDimitry Andric } // namespace llvm 610b57cec5SDimitry Andric 62fe6060f1SDimitry Andric #endif // LLVM_XRAY_FDRTRACEEXPANDER_H 63