1 //===- BlockIndexer.cpp - FDR Block Indexing VIsitor ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // An implementation of the RecordVisitor which generates a mapping between a
11 // thread and a range of records representing a block.
13 //===----------------------------------------------------------------------===//
14 #include "llvm/XRay/BlockIndexer.h"
19 Error BlockIndexer::visit(BufferExtents &) { return Error::success(); }
21 Error BlockIndexer::visit(WallclockRecord &R) {
22 CurrentBlock.Records.push_back(&R);
23 CurrentBlock.WallclockTime = &R;
24 return Error::success();
27 Error BlockIndexer::visit(NewCPUIDRecord &R) {
28 CurrentBlock.Records.push_back(&R);
29 return Error::success();
32 Error BlockIndexer::visit(TSCWrapRecord &R) {
33 CurrentBlock.Records.push_back(&R);
34 return Error::success();
37 Error BlockIndexer::visit(CustomEventRecord &R) {
38 CurrentBlock.Records.push_back(&R);
39 return Error::success();
42 Error BlockIndexer::visit(CustomEventRecordV5 &R) {
43 CurrentBlock.Records.push_back(&R);
44 return Error::success();
47 Error BlockIndexer::visit(TypedEventRecord &R) {
48 CurrentBlock.Records.push_back(&R);
49 return Error::success();
52 Error BlockIndexer::visit(CallArgRecord &R) {
53 CurrentBlock.Records.push_back(&R);
54 return Error::success();
57 Error BlockIndexer::visit(PIDRecord &R) {
58 CurrentBlock.ProcessID = R.pid();
59 CurrentBlock.Records.push_back(&R);
60 return Error::success();
63 Error BlockIndexer::visit(NewBufferRecord &R) {
64 if (!CurrentBlock.Records.empty())
68 CurrentBlock.ThreadID = R.tid();
69 CurrentBlock.Records.push_back(&R);
70 return Error::success();
73 Error BlockIndexer::visit(EndBufferRecord &R) {
74 CurrentBlock.Records.push_back(&R);
75 return Error::success();
78 Error BlockIndexer::visit(FunctionRecord &R) {
79 CurrentBlock.Records.push_back(&R);
80 return Error::success();
83 Error BlockIndexer::flush() {
85 std::tie(It, std::ignore) =
86 Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}});
87 It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID,
88 CurrentBlock.WallclockTime,
89 std::move(CurrentBlock.Records)});
90 CurrentBlock.ProcessID = 0;
91 CurrentBlock.ThreadID = 0;
92 CurrentBlock.Records = {};
93 CurrentBlock.WallclockTime = nullptr;
94 return Error::success();