1 //===- BlockIndexer.cpp - FDR Block Indexing VIsitor ----------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // An implementation of the RecordVisitor which generates a mapping between a
10 // thread and a range of records representing a block.
12 //===----------------------------------------------------------------------===//
13 #include "llvm/XRay/BlockIndexer.h"
18 Error
BlockIndexer::visit(BufferExtents
&) { return Error::success(); }
20 Error
BlockIndexer::visit(WallclockRecord
&R
) {
21 CurrentBlock
.Records
.push_back(&R
);
22 CurrentBlock
.WallclockTime
= &R
;
23 return Error::success();
26 Error
BlockIndexer::visit(NewCPUIDRecord
&R
) {
27 CurrentBlock
.Records
.push_back(&R
);
28 return Error::success();
31 Error
BlockIndexer::visit(TSCWrapRecord
&R
) {
32 CurrentBlock
.Records
.push_back(&R
);
33 return Error::success();
36 Error
BlockIndexer::visit(CustomEventRecord
&R
) {
37 CurrentBlock
.Records
.push_back(&R
);
38 return Error::success();
41 Error
BlockIndexer::visit(CustomEventRecordV5
&R
) {
42 CurrentBlock
.Records
.push_back(&R
);
43 return Error::success();
46 Error
BlockIndexer::visit(TypedEventRecord
&R
) {
47 CurrentBlock
.Records
.push_back(&R
);
48 return Error::success();
51 Error
BlockIndexer::visit(CallArgRecord
&R
) {
52 CurrentBlock
.Records
.push_back(&R
);
53 return Error::success();
56 Error
BlockIndexer::visit(PIDRecord
&R
) {
57 CurrentBlock
.ProcessID
= R
.pid();
58 CurrentBlock
.Records
.push_back(&R
);
59 return Error::success();
62 Error
BlockIndexer::visit(NewBufferRecord
&R
) {
63 if (!CurrentBlock
.Records
.empty())
67 CurrentBlock
.ThreadID
= R
.tid();
68 CurrentBlock
.Records
.push_back(&R
);
69 return Error::success();
72 Error
BlockIndexer::visit(EndBufferRecord
&R
) {
73 CurrentBlock
.Records
.push_back(&R
);
74 return Error::success();
77 Error
BlockIndexer::visit(FunctionRecord
&R
) {
78 CurrentBlock
.Records
.push_back(&R
);
79 return Error::success();
82 Error
BlockIndexer::flush() {
83 Indices
[{CurrentBlock
.ProcessID
, CurrentBlock
.ThreadID
}].push_back(
84 {CurrentBlock
.ProcessID
, CurrentBlock
.ThreadID
,
85 CurrentBlock
.WallclockTime
, std::move(CurrentBlock
.Records
)});
86 CurrentBlock
.ProcessID
= 0;
87 CurrentBlock
.ThreadID
= 0;
88 CurrentBlock
.Records
= {};
89 CurrentBlock
.WallclockTime
= nullptr;
90 return Error::success();