Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 1 | //===- BlockIndexer.cpp - FDR Block Indexing VIsitor ----------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 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 | |
| 15 | namespace llvm { |
| 16 | namespace xray { |
| 17 | |
Dean Michael Berris | 90a46bd | 2018-09-13 09:25:42 +0000 | [diff] [blame] | 18 | Error BlockIndexer::visit(BufferExtents &) { return Error::success(); } |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 19 | |
| 20 | Error BlockIndexer::visit(WallclockRecord &R) { |
| 21 | CurrentBlock.Records.push_back(&R); |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 22 | CurrentBlock.WallclockTime = &R; |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 23 | return Error::success(); |
| 24 | } |
| 25 | |
| 26 | Error BlockIndexer::visit(NewCPUIDRecord &R) { |
| 27 | CurrentBlock.Records.push_back(&R); |
| 28 | return Error::success(); |
| 29 | } |
| 30 | |
| 31 | Error BlockIndexer::visit(TSCWrapRecord &R) { |
| 32 | CurrentBlock.Records.push_back(&R); |
| 33 | return Error::success(); |
| 34 | } |
| 35 | |
| 36 | Error BlockIndexer::visit(CustomEventRecord &R) { |
| 37 | CurrentBlock.Records.push_back(&R); |
| 38 | return Error::success(); |
| 39 | } |
| 40 | |
Dean Michael Berris | 59439dd | 2018-11-07 04:37:42 +0000 | [diff] [blame] | 41 | Error BlockIndexer::visit(CustomEventRecordV5 &R) { |
| 42 | CurrentBlock.Records.push_back(&R); |
| 43 | return Error::success(); |
| 44 | } |
| 45 | |
| 46 | Error BlockIndexer::visit(TypedEventRecord &R) { |
| 47 | CurrentBlock.Records.push_back(&R); |
| 48 | return Error::success(); |
| 49 | } |
| 50 | |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 51 | Error BlockIndexer::visit(CallArgRecord &R) { |
| 52 | CurrentBlock.Records.push_back(&R); |
| 53 | return Error::success(); |
Simon Pilgrim | 6088e85 | 2018-09-06 15:15:28 +0000 | [diff] [blame] | 54 | } |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 55 | |
| 56 | Error BlockIndexer::visit(PIDRecord &R) { |
| 57 | CurrentBlock.ProcessID = R.pid(); |
| 58 | CurrentBlock.Records.push_back(&R); |
| 59 | return Error::success(); |
| 60 | } |
| 61 | |
| 62 | Error BlockIndexer::visit(NewBufferRecord &R) { |
Dean Michael Berris | 90a46bd | 2018-09-13 09:25:42 +0000 | [diff] [blame] | 63 | if (!CurrentBlock.Records.empty()) |
| 64 | if (auto E = flush()) |
| 65 | return E; |
| 66 | |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 67 | CurrentBlock.ThreadID = R.tid(); |
| 68 | CurrentBlock.Records.push_back(&R); |
| 69 | return Error::success(); |
| 70 | } |
| 71 | |
| 72 | Error BlockIndexer::visit(EndBufferRecord &R) { |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 73 | CurrentBlock.Records.push_back(&R); |
| 74 | return Error::success(); |
| 75 | } |
| 76 | |
| 77 | Error BlockIndexer::visit(FunctionRecord &R) { |
| 78 | CurrentBlock.Records.push_back(&R); |
| 79 | return Error::success(); |
| 80 | } |
| 81 | |
| 82 | Error BlockIndexer::flush() { |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 83 | Index::iterator It; |
| 84 | std::tie(It, std::ignore) = |
| 85 | Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}}); |
| 86 | It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID, |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 87 | CurrentBlock.WallclockTime, |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 88 | std::move(CurrentBlock.Records)}); |
| 89 | CurrentBlock.ProcessID = 0; |
| 90 | CurrentBlock.ThreadID = 0; |
| 91 | CurrentBlock.Records = {}; |
Dean Michael Berris | 90a46bd | 2018-09-13 09:25:42 +0000 | [diff] [blame] | 92 | CurrentBlock.WallclockTime = nullptr; |
Dean Michael Berris | 02f097e | 2018-09-06 05:55:57 +0000 | [diff] [blame] | 93 | return Error::success(); |
| 94 | } |
| 95 | |
| 96 | } // namespace xray |
| 97 | } // namespace llvm |