blob: 98e91f7de5487d0ce44627af24238a926ae93452 [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
Dean Michael Berris90a46bd2018-09-13 09:25:42 +000019Error BlockIndexer::visit(BufferExtents &) { return Error::success(); }
Dean Michael Berris02f097e2018-09-06 05:55:57 +000020
21Error BlockIndexer::visit(WallclockRecord &R) {
22 CurrentBlock.Records.push_back(&R);
Dean Michael Berris985c2b92018-09-11 06:45:59 +000023 CurrentBlock.WallclockTime = &R;
Dean Michael Berris02f097e2018-09-06 05:55:57 +000024 return Error::success();
25}
26
27Error BlockIndexer::visit(NewCPUIDRecord &R) {
28 CurrentBlock.Records.push_back(&R);
29 return Error::success();
30}
31
32Error BlockIndexer::visit(TSCWrapRecord &R) {
33 CurrentBlock.Records.push_back(&R);
34 return Error::success();
35}
36
37Error BlockIndexer::visit(CustomEventRecord &R) {
38 CurrentBlock.Records.push_back(&R);
39 return Error::success();
40}
41
42Error BlockIndexer::visit(CallArgRecord &R) {
43 CurrentBlock.Records.push_back(&R);
44 return Error::success();
Simon Pilgrim6088e852018-09-06 15:15:28 +000045}
Dean Michael Berris02f097e2018-09-06 05:55:57 +000046
47Error BlockIndexer::visit(PIDRecord &R) {
48 CurrentBlock.ProcessID = R.pid();
49 CurrentBlock.Records.push_back(&R);
50 return Error::success();
51}
52
53Error BlockIndexer::visit(NewBufferRecord &R) {
Dean Michael Berris90a46bd2018-09-13 09:25:42 +000054 if (!CurrentBlock.Records.empty())
55 if (auto E = flush())
56 return E;
57
Dean Michael Berris02f097e2018-09-06 05:55:57 +000058 CurrentBlock.ThreadID = R.tid();
59 CurrentBlock.Records.push_back(&R);
60 return Error::success();
61}
62
63Error BlockIndexer::visit(EndBufferRecord &R) {
Dean Michael Berris02f097e2018-09-06 05:55:57 +000064 CurrentBlock.Records.push_back(&R);
65 return Error::success();
66}
67
68Error BlockIndexer::visit(FunctionRecord &R) {
69 CurrentBlock.Records.push_back(&R);
70 return Error::success();
71}
72
73Error BlockIndexer::flush() {
Dean Michael Berris02f097e2018-09-06 05:55:57 +000074 Index::iterator It;
75 std::tie(It, std::ignore) =
76 Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}});
77 It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID,
Dean Michael Berris985c2b92018-09-11 06:45:59 +000078 CurrentBlock.WallclockTime,
Dean Michael Berris02f097e2018-09-06 05:55:57 +000079 std::move(CurrentBlock.Records)});
80 CurrentBlock.ProcessID = 0;
81 CurrentBlock.ThreadID = 0;
82 CurrentBlock.Records = {};
Dean Michael Berris90a46bd2018-09-13 09:25:42 +000083 CurrentBlock.WallclockTime = nullptr;
Dean Michael Berris02f097e2018-09-06 05:55:57 +000084 return Error::success();
85}
86
87} // namespace xray
88} // namespace llvm