BlockIndexer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- BlockIndexer.h - FDR Block Indexing Visitor ------------------------===//
  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 generates a mapping between a
  15. // thread and a range of records representing a block.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_XRAY_BLOCKINDEXER_H
  19. #define LLVM_XRAY_BLOCKINDEXER_H
  20. #include "llvm/ADT/DenseMap.h"
  21. #include "llvm/XRay/FDRRecords.h"
  22. #include <cstdint>
  23. #include <vector>
  24. namespace llvm {
  25. namespace xray {
  26. // The BlockIndexer will gather all related records associated with a
  27. // process+thread and group them by 'Block'.
  28. class BlockIndexer : public RecordVisitor {
  29. public:
  30. struct Block {
  31. uint64_t ProcessID;
  32. int32_t ThreadID;
  33. WallclockRecord *WallclockTime;
  34. std::vector<Record *> Records;
  35. };
  36. // This maps the process + thread combination to a sequence of blocks.
  37. using Index = DenseMap<std::pair<uint64_t, int32_t>, std::vector<Block>>;
  38. private:
  39. Index &Indices;
  40. Block CurrentBlock{0, 0, nullptr, {}};
  41. public:
  42. explicit BlockIndexer(Index &I) : Indices(I) {}
  43. Error visit(BufferExtents &) override;
  44. Error visit(WallclockRecord &) override;
  45. Error visit(NewCPUIDRecord &) override;
  46. Error visit(TSCWrapRecord &) override;
  47. Error visit(CustomEventRecord &) override;
  48. Error visit(CallArgRecord &) override;
  49. Error visit(PIDRecord &) override;
  50. Error visit(NewBufferRecord &) override;
  51. Error visit(EndBufferRecord &) override;
  52. Error visit(FunctionRecord &) override;
  53. Error visit(CustomEventRecordV5 &) override;
  54. Error visit(TypedEventRecord &) override;
  55. /// The flush() function will clear out the current state of the visitor, to
  56. /// allow for explicitly flushing a block's records to the currently
  57. /// recognized thread and process combination.
  58. Error flush();
  59. };
  60. } // namespace xray
  61. } // namespace llvm
  62. #endif // LLVM_XRAY_BLOCKINDEXER_H
  63. #ifdef __GNUC__
  64. #pragma GCC diagnostic pop
  65. #endif