Path: blob/main/contrib/llvm-project/llvm/lib/XRay/BlockIndexer.cpp
35233 views
//===- BlockIndexer.cpp - FDR Block Indexing VIsitor ----------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// An implementation of the RecordVisitor which generates a mapping between a9// thread and a range of records representing a block.10//11//===----------------------------------------------------------------------===//12#include "llvm/XRay/BlockIndexer.h"1314namespace llvm {15namespace xray {1617Error BlockIndexer::visit(BufferExtents &) { return Error::success(); }1819Error BlockIndexer::visit(WallclockRecord &R) {20CurrentBlock.Records.push_back(&R);21CurrentBlock.WallclockTime = &R;22return Error::success();23}2425Error BlockIndexer::visit(NewCPUIDRecord &R) {26CurrentBlock.Records.push_back(&R);27return Error::success();28}2930Error BlockIndexer::visit(TSCWrapRecord &R) {31CurrentBlock.Records.push_back(&R);32return Error::success();33}3435Error BlockIndexer::visit(CustomEventRecord &R) {36CurrentBlock.Records.push_back(&R);37return Error::success();38}3940Error BlockIndexer::visit(CustomEventRecordV5 &R) {41CurrentBlock.Records.push_back(&R);42return Error::success();43}4445Error BlockIndexer::visit(TypedEventRecord &R) {46CurrentBlock.Records.push_back(&R);47return Error::success();48}4950Error BlockIndexer::visit(CallArgRecord &R) {51CurrentBlock.Records.push_back(&R);52return Error::success();53}5455Error BlockIndexer::visit(PIDRecord &R) {56CurrentBlock.ProcessID = R.pid();57CurrentBlock.Records.push_back(&R);58return Error::success();59}6061Error BlockIndexer::visit(NewBufferRecord &R) {62if (!CurrentBlock.Records.empty())63if (auto E = flush())64return E;6566CurrentBlock.ThreadID = R.tid();67CurrentBlock.Records.push_back(&R);68return Error::success();69}7071Error BlockIndexer::visit(EndBufferRecord &R) {72CurrentBlock.Records.push_back(&R);73return Error::success();74}7576Error BlockIndexer::visit(FunctionRecord &R) {77CurrentBlock.Records.push_back(&R);78return Error::success();79}8081Error BlockIndexer::flush() {82Index::iterator It;83std::tie(It, std::ignore) =84Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}});85It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID,86CurrentBlock.WallclockTime,87std::move(CurrentBlock.Records)});88CurrentBlock.ProcessID = 0;89CurrentBlock.ThreadID = 0;90CurrentBlock.Records = {};91CurrentBlock.WallclockTime = nullptr;92return Error::success();93}9495} // namespace xray96} // namespace llvm979899