102f097e1SDean Michael Berris //===- BlockIndexer.cpp - FDR Block Indexing VIsitor ----------------------===// 202f097e1SDean Michael Berris // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 602f097e1SDean Michael Berris // 702f097e1SDean Michael Berris //===----------------------------------------------------------------------===// 802f097e1SDean Michael Berris // 902f097e1SDean Michael Berris // An implementation of the RecordVisitor which generates a mapping between a 1002f097e1SDean Michael Berris // thread and a range of records representing a block. 1102f097e1SDean Michael Berris // 1202f097e1SDean Michael Berris //===----------------------------------------------------------------------===// 1302f097e1SDean Michael Berris #include "llvm/XRay/BlockIndexer.h" 1402f097e1SDean Michael Berris 1502f097e1SDean Michael Berris namespace llvm { 1602f097e1SDean Michael Berris namespace xray { 1702f097e1SDean Michael Berris 1890a46bdeSDean Michael Berris Error BlockIndexer::visit(BufferExtents &) { return Error::success(); } 1902f097e1SDean Michael Berris 2002f097e1SDean Michael Berris Error BlockIndexer::visit(WallclockRecord &R) { 2102f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 22985c2b92SDean Michael Berris CurrentBlock.WallclockTime = &R; 2302f097e1SDean Michael Berris return Error::success(); 2402f097e1SDean Michael Berris } 2502f097e1SDean Michael Berris 2602f097e1SDean Michael Berris Error BlockIndexer::visit(NewCPUIDRecord &R) { 2702f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 2802f097e1SDean Michael Berris return Error::success(); 2902f097e1SDean Michael Berris } 3002f097e1SDean Michael Berris 3102f097e1SDean Michael Berris Error BlockIndexer::visit(TSCWrapRecord &R) { 3202f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 3302f097e1SDean Michael Berris return Error::success(); 3402f097e1SDean Michael Berris } 3502f097e1SDean Michael Berris 3602f097e1SDean Michael Berris Error BlockIndexer::visit(CustomEventRecord &R) { 3702f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 3802f097e1SDean Michael Berris return Error::success(); 3902f097e1SDean Michael Berris } 4002f097e1SDean Michael Berris 4159439dd0SDean Michael Berris Error BlockIndexer::visit(CustomEventRecordV5 &R) { 4259439dd0SDean Michael Berris CurrentBlock.Records.push_back(&R); 4359439dd0SDean Michael Berris return Error::success(); 4459439dd0SDean Michael Berris } 4559439dd0SDean Michael Berris 4659439dd0SDean Michael Berris Error BlockIndexer::visit(TypedEventRecord &R) { 4759439dd0SDean Michael Berris CurrentBlock.Records.push_back(&R); 4859439dd0SDean Michael Berris return Error::success(); 4959439dd0SDean Michael Berris } 5059439dd0SDean Michael Berris 5102f097e1SDean Michael Berris Error BlockIndexer::visit(CallArgRecord &R) { 5202f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 5302f097e1SDean Michael Berris return Error::success(); 546088e851SSimon Pilgrim } 5502f097e1SDean Michael Berris 5602f097e1SDean Michael Berris Error BlockIndexer::visit(PIDRecord &R) { 5702f097e1SDean Michael Berris CurrentBlock.ProcessID = R.pid(); 5802f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 5902f097e1SDean Michael Berris return Error::success(); 6002f097e1SDean Michael Berris } 6102f097e1SDean Michael Berris 6202f097e1SDean Michael Berris Error BlockIndexer::visit(NewBufferRecord &R) { 6390a46bdeSDean Michael Berris if (!CurrentBlock.Records.empty()) 6490a46bdeSDean Michael Berris if (auto E = flush()) 6590a46bdeSDean Michael Berris return E; 6690a46bdeSDean Michael Berris 6702f097e1SDean Michael Berris CurrentBlock.ThreadID = R.tid(); 6802f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 6902f097e1SDean Michael Berris return Error::success(); 7002f097e1SDean Michael Berris } 7102f097e1SDean Michael Berris 7202f097e1SDean Michael Berris Error BlockIndexer::visit(EndBufferRecord &R) { 7302f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 7402f097e1SDean Michael Berris return Error::success(); 7502f097e1SDean Michael Berris } 7602f097e1SDean Michael Berris 7702f097e1SDean Michael Berris Error BlockIndexer::visit(FunctionRecord &R) { 7802f097e1SDean Michael Berris CurrentBlock.Records.push_back(&R); 7902f097e1SDean Michael Berris return Error::success(); 8002f097e1SDean Michael Berris } 8102f097e1SDean Michael Berris 8202f097e1SDean Michael Berris Error BlockIndexer::flush() { 83*35bbfbc7SKazu Hirata Indices[{CurrentBlock.ProcessID, CurrentBlock.ThreadID}].push_back( 84*35bbfbc7SKazu Hirata {CurrentBlock.ProcessID, CurrentBlock.ThreadID, 85*35bbfbc7SKazu Hirata CurrentBlock.WallclockTime, std::move(CurrentBlock.Records)}); 8602f097e1SDean Michael Berris CurrentBlock.ProcessID = 0; 8702f097e1SDean Michael Berris CurrentBlock.ThreadID = 0; 8802f097e1SDean Michael Berris CurrentBlock.Records = {}; 8990a46bdeSDean Michael Berris CurrentBlock.WallclockTime = nullptr; 9002f097e1SDean Michael Berris return Error::success(); 9102f097e1SDean Michael Berris } 9202f097e1SDean Michael Berris 9302f097e1SDean Michael Berris } // namespace xray 9402f097e1SDean Michael Berris } // namespace llvm 95