BlockIndexer.h 2.2 KB

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