blob: 4ea2ffbc3916c37ab7314ce91c1dfbe72d1898ec [file] [log] [blame]
Dean Michael Berris02f097e2018-09-06 05:55:57 +00001//===- 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
16namespace llvm {
17namespace xray {
18
19Error BlockIndexer::visit(BufferExtents &) {
20 if (CurrentState == State::ThreadIDFound) {
21 Index::iterator It;
22 std::tie(It, std::ignore) =
23 Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}});
24 It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID,
25 std::move(CurrentBlock.Records)});
26 CurrentBlock.ProcessID = 0;
27 CurrentBlock.ThreadID = 0;
28 CurrentBlock.Records = {};
29 }
30 CurrentState = State::ExtentsFound;
31 return Error::success();
32}
33
34Error BlockIndexer::visit(WallclockRecord &R) {
35 CurrentBlock.Records.push_back(&R);
36 return Error::success();
37}
38
39Error BlockIndexer::visit(NewCPUIDRecord &R) {
40 CurrentBlock.Records.push_back(&R);
41 return Error::success();
42}
43
44Error BlockIndexer::visit(TSCWrapRecord &R) {
45 CurrentBlock.Records.push_back(&R);
46 return Error::success();
47}
48
49Error BlockIndexer::visit(CustomEventRecord &R) {
50 CurrentBlock.Records.push_back(&R);
51 return Error::success();
52}
53
54Error BlockIndexer::visit(CallArgRecord &R) {
55 CurrentBlock.Records.push_back(&R);
56 return Error::success();
Simon Pilgrim6088e852018-09-06 15:15:28 +000057}
Dean Michael Berris02f097e2018-09-06 05:55:57 +000058
59Error BlockIndexer::visit(PIDRecord &R) {
60 CurrentBlock.ProcessID = R.pid();
61 CurrentBlock.Records.push_back(&R);
62 return Error::success();
63}
64
65Error BlockIndexer::visit(NewBufferRecord &R) {
66 CurrentState = State::ThreadIDFound;
67 CurrentBlock.ThreadID = R.tid();
68 CurrentBlock.Records.push_back(&R);
69 return Error::success();
70}
71
72Error BlockIndexer::visit(EndBufferRecord &R) {
73 CurrentState = State::SeekExtents;
74 CurrentBlock.Records.push_back(&R);
75 return Error::success();
76}
77
78Error BlockIndexer::visit(FunctionRecord &R) {
79 CurrentBlock.Records.push_back(&R);
80 return Error::success();
81}
82
83Error BlockIndexer::flush() {
84 CurrentState = State::SeekExtents;
85 Index::iterator It;
86 std::tie(It, std::ignore) =
87 Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}});
88 It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID,
89 std::move(CurrentBlock.Records)});
90 CurrentBlock.ProcessID = 0;
91 CurrentBlock.ThreadID = 0;
92 CurrentBlock.Records = {};
93 return Error::success();
94}
95
96} // namespace xray
97} // namespace llvm