BlockIndexer.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===- BlockIndexer.cpp - 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. #include "llvm/XRay/BlockIndexer.h"
  14. namespace llvm {
  15. namespace xray {
  16. Error BlockIndexer::visit(BufferExtents &) { return Error::success(); }
  17. Error BlockIndexer::visit(WallclockRecord &R) {
  18. CurrentBlock.Records.push_back(&R);
  19. CurrentBlock.WallclockTime = &R;
  20. return Error::success();
  21. }
  22. Error BlockIndexer::visit(NewCPUIDRecord &R) {
  23. CurrentBlock.Records.push_back(&R);
  24. return Error::success();
  25. }
  26. Error BlockIndexer::visit(TSCWrapRecord &R) {
  27. CurrentBlock.Records.push_back(&R);
  28. return Error::success();
  29. }
  30. Error BlockIndexer::visit(CustomEventRecord &R) {
  31. CurrentBlock.Records.push_back(&R);
  32. return Error::success();
  33. }
  34. Error BlockIndexer::visit(CustomEventRecordV5 &R) {
  35. CurrentBlock.Records.push_back(&R);
  36. return Error::success();
  37. }
  38. Error BlockIndexer::visit(TypedEventRecord &R) {
  39. CurrentBlock.Records.push_back(&R);
  40. return Error::success();
  41. }
  42. Error BlockIndexer::visit(CallArgRecord &R) {
  43. CurrentBlock.Records.push_back(&R);
  44. return Error::success();
  45. }
  46. Error BlockIndexer::visit(PIDRecord &R) {
  47. CurrentBlock.ProcessID = R.pid();
  48. CurrentBlock.Records.push_back(&R);
  49. return Error::success();
  50. }
  51. Error BlockIndexer::visit(NewBufferRecord &R) {
  52. if (!CurrentBlock.Records.empty())
  53. if (auto E = flush())
  54. return E;
  55. CurrentBlock.ThreadID = R.tid();
  56. CurrentBlock.Records.push_back(&R);
  57. return Error::success();
  58. }
  59. Error BlockIndexer::visit(EndBufferRecord &R) {
  60. CurrentBlock.Records.push_back(&R);
  61. return Error::success();
  62. }
  63. Error BlockIndexer::visit(FunctionRecord &R) {
  64. CurrentBlock.Records.push_back(&R);
  65. return Error::success();
  66. }
  67. Error BlockIndexer::flush() {
  68. Index::iterator It;
  69. std::tie(It, std::ignore) =
  70. Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}});
  71. It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID,
  72. CurrentBlock.WallclockTime,
  73. std::move(CurrentBlock.Records)});
  74. CurrentBlock.ProcessID = 0;
  75. CurrentBlock.ThreadID = 0;
  76. CurrentBlock.Records = {};
  77. CurrentBlock.WallclockTime = nullptr;
  78. return Error::success();
  79. }
  80. } // namespace xray
  81. } // namespace llvm