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