Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 1 | //===- BlockVerifier.h - FDR Block Verifier -------------------------------===// |
| 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 | // An implementation of the RecordVisitor which verifies a sequence of records |
| 10 | // associated with a block, following the FDR mode log format's specifications. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_ |
| 14 | #define LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_ |
| 15 | |
| 16 | #include "llvm/XRay/FDRRecords.h" |
| 17 | #include <array> |
| 18 | #include <bitset> |
| 19 | |
| 20 | namespace llvm { |
| 21 | namespace xray { |
| 22 | |
| 23 | class BlockVerifier : public RecordVisitor { |
| 24 | public: |
| 25 | // We force State elements to be size_t, to be used as indices for containers. |
| 26 | enum class State : std::size_t { |
| 27 | Unknown, |
| 28 | BufferExtents, |
| 29 | NewBuffer, |
| 30 | WallClockTime, |
| 31 | PIDEntry, |
| 32 | NewCPUId, |
| 33 | TSCWrap, |
| 34 | CustomEvent, |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 35 | TypedEvent, |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 36 | Function, |
| 37 | CallArg, |
| 38 | EndOfBuffer, |
| 39 | StateMax, |
| 40 | }; |
| 41 | |
| 42 | private: |
| 43 | // We keep track of the current record seen by the verifier. |
| 44 | State CurrentRecord = State::Unknown; |
| 45 | |
| 46 | // Transitions the current record to the new record, records an error on |
| 47 | // invalid transitions. |
| 48 | Error transition(State To); |
| 49 | |
| 50 | public: |
| 51 | Error visit(BufferExtents &) override; |
| 52 | Error visit(WallclockRecord &) override; |
| 53 | Error visit(NewCPUIDRecord &) override; |
| 54 | Error visit(TSCWrapRecord &) override; |
| 55 | Error visit(CustomEventRecord &) override; |
| 56 | Error visit(CallArgRecord &) override; |
| 57 | Error visit(PIDRecord &) override; |
| 58 | Error visit(NewBufferRecord &) override; |
| 59 | Error visit(EndBufferRecord &) override; |
| 60 | Error visit(FunctionRecord &) override; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 61 | Error visit(CustomEventRecordV5 &) override; |
| 62 | Error visit(TypedEventRecord &) override; |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 63 | |
| 64 | Error verify(); |
| 65 | void reset(); |
| 66 | }; |
| 67 | |
| 68 | } // namespace xray |
| 69 | } // namespace llvm |
| 70 | |
| 71 | #endif // LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_ |