BlockVerifier.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- BlockVerifier.h - FDR Block Verifier -------------------------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // An implementation of the RecordVisitor which verifies a sequence of records
  15. // associated with a block, following the FDR mode log format's specifications.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_
  19. #define LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_
  20. #include "llvm/XRay/FDRRecords.h"
  21. #include <array>
  22. #include <bitset>
  23. namespace llvm {
  24. namespace xray {
  25. class BlockVerifier : public RecordVisitor {
  26. public:
  27. // We force State elements to be size_t, to be used as indices for containers.
  28. enum class State : std::size_t {
  29. Unknown,
  30. BufferExtents,
  31. NewBuffer,
  32. WallClockTime,
  33. PIDEntry,
  34. NewCPUId,
  35. TSCWrap,
  36. CustomEvent,
  37. TypedEvent,
  38. Function,
  39. CallArg,
  40. EndOfBuffer,
  41. StateMax,
  42. };
  43. private:
  44. // We keep track of the current record seen by the verifier.
  45. State CurrentRecord = State::Unknown;
  46. // Transitions the current record to the new record, records an error on
  47. // invalid transitions.
  48. Error transition(State To);
  49. public:
  50. Error visit(BufferExtents &) override;
  51. Error visit(WallclockRecord &) override;
  52. Error visit(NewCPUIDRecord &) override;
  53. Error visit(TSCWrapRecord &) override;
  54. Error visit(CustomEventRecord &) override;
  55. Error visit(CallArgRecord &) override;
  56. Error visit(PIDRecord &) override;
  57. Error visit(NewBufferRecord &) override;
  58. Error visit(EndBufferRecord &) override;
  59. Error visit(FunctionRecord &) override;
  60. Error visit(CustomEventRecordV5 &) override;
  61. Error visit(TypedEventRecord &) override;
  62. Error verify();
  63. void reset();
  64. };
  65. } // namespace xray
  66. } // namespace llvm
  67. #endif // LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_
  68. #ifdef __GNUC__
  69. #pragma GCC diagnostic pop
  70. #endif