Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 1 | //===- BlockIndexer.cpp - FDR Block Indexing VIsitor ----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // An implementation of the RecordVisitor which generates a mapping between a |
| 11 | // thread and a range of records representing a block. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #include "llvm/XRay/BlockIndexer.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | namespace xray { |
| 18 | |
Dean Michael Berris | 90a46bd | 2018-09-13 09:25:42 +0000 | [diff] [blame] | 19 | Error BlockIndexer::visit(BufferExtents &) { return Error::success(); } |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 20 | |
| 21 | Error BlockIndexer::visit(WallclockRecord &R) { |
| 22 | CurrentBlock.Records.push_back(&R); |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 23 | CurrentBlock.WallclockTime = &R; |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 24 | return Error::success(); |
| 25 | } |
| 26 | |
| 27 | Error BlockIndexer::visit(NewCPUIDRecord &R) { |
| 28 | CurrentBlock.Records.push_back(&R); |
| 29 | return Error::success(); |
| 30 | } |
| 31 | |
| 32 | Error BlockIndexer::visit(TSCWrapRecord &R) { |
| 33 | CurrentBlock.Records.push_back(&R); |
| 34 | return Error::success(); |
| 35 | } |
| 36 | |
| 37 | Error BlockIndexer::visit(CustomEventRecord &R) { |
| 38 | CurrentBlock.Records.push_back(&R); |
| 39 | return Error::success(); |
| 40 | } |
| 41 | |
Dean Michael Berris | 59439dd | 2018-11-07 04:37:42 +0000 | [diff] [blame^] | 42 | Error BlockIndexer::visit(CustomEventRecordV5 &R) { |
| 43 | CurrentBlock.Records.push_back(&R); |
| 44 | return Error::success(); |
| 45 | } |
| 46 | |
| 47 | Error BlockIndexer::visit(TypedEventRecord &R) { |
| 48 | CurrentBlock.Records.push_back(&R); |
| 49 | return Error::success(); |
| 50 | } |
| 51 | |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 52 | Error BlockIndexer::visit(CallArgRecord &R) { |
| 53 | CurrentBlock.Records.push_back(&R); |
| 54 | return Error::success(); |
Simon Pilgrim | 6088e85 | 2018-09-06 15:15:28 +0000 | [diff] [blame] | 55 | } |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 56 | |
| 57 | Error BlockIndexer::visit(PIDRecord &R) { |
| 58 | CurrentBlock.ProcessID = R.pid(); |
| 59 | CurrentBlock.Records.push_back(&R); |
| 60 | return Error::success(); |
| 61 | } |
| 62 | |
| 63 | Error BlockIndexer::visit(NewBufferRecord &R) { |
Dean Michael Berris | 90a46bd | 2018-09-13 09:25:42 +0000 | [diff] [blame] | 64 | if (!CurrentBlock.Records.empty()) |
| 65 | if (auto E = flush()) |
| 66 | return E; |
| 67 | |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 68 | CurrentBlock.ThreadID = R.tid(); |
| 69 | CurrentBlock.Records.push_back(&R); |
| 70 | return Error::success(); |
| 71 | } |
| 72 | |
| 73 | Error BlockIndexer::visit(EndBufferRecord &R) { |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 74 | CurrentBlock.Records.push_back(&R); |
| 75 | return Error::success(); |
| 76 | } |
| 77 | |
| 78 | Error BlockIndexer::visit(FunctionRecord &R) { |
| 79 | CurrentBlock.Records.push_back(&R); |
| 80 | return Error::success(); |
| 81 | } |
| 82 | |
| 83 | Error BlockIndexer::flush() { |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 84 | Index::iterator It; |
| 85 | std::tie(It, std::ignore) = |
| 86 | Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}}); |
| 87 | It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID, |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 88 | CurrentBlock.WallclockTime, |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 89 | std::move(CurrentBlock.Records)}); |
| 90 | CurrentBlock.ProcessID = 0; |
| 91 | CurrentBlock.ThreadID = 0; |
| 92 | CurrentBlock.Records = {}; |
Dean Michael Berris | 90a46bd | 2018-09-13 09:25:42 +0000 | [diff] [blame] | 93 | CurrentBlock.WallclockTime = nullptr; |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 94 | return Error::success(); |
| 95 | } |
| 96 | |
| 97 | } // namespace xray |
| 98 | } // namespace llvm |