diff options
author | Dean Michael Berris <dberris@google.com> | 2018-09-06 05:55:57 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2018-09-06 05:55:57 +0000 |
commit | 02f097e122cd7d83753e27c5ce0e6cd3c610eef4 (patch) | |
tree | 2fa1e40d9b0ebcc4433a8216d0379804694d516d /llvm/lib/XRay | |
parent | f90154069c908c628daf1b89d8fe6d96b11da688 (diff) | |
download | bcm5719-llvm-02f097e122cd7d83753e27c5ce0e6cd3c610eef4.tar.gz bcm5719-llvm-02f097e122cd7d83753e27c5ce0e6cd3c610eef4.zip |
[XRay] Add a BlockIndexer visitor for FDR Records.
Summary:
This change adds a `BlockIndexer` type which maintains pointers to
records that belong to the same process+thread pairs. The indexing
happens with order of appearance of records as they are visited.
This version of the indexer currently only supports FDR version 3 logs,
which contain `BufferExtent` records. We will add support for v2 and v1
logs in follow-up patches.
This is another part of D50441.
Reviewers: eizan, kpw, mboerger
Reviewed By: mboerger
Subscribers: mboerger, mgorny, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D51673
llvm-svn: 341518
Diffstat (limited to 'llvm/lib/XRay')
-rw-r--r-- | llvm/lib/XRay/BlockIndexer.cpp | 97 | ||||
-rw-r--r-- | llvm/lib/XRay/CMakeLists.txt | 1 |
2 files changed, 98 insertions, 0 deletions
diff --git a/llvm/lib/XRay/BlockIndexer.cpp b/llvm/lib/XRay/BlockIndexer.cpp new file mode 100644 index 00000000000..4b76ad9ecdc --- /dev/null +++ b/llvm/lib/XRay/BlockIndexer.cpp @@ -0,0 +1,97 @@ +//===- BlockIndexer.cpp - FDR Block Indexing VIsitor ----------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// An implementation of the RecordVisitor which generates a mapping between a +// thread and a range of records representing a block. +// +//===----------------------------------------------------------------------===// +#include "llvm/XRay/BlockIndexer.h" + +namespace llvm { +namespace xray { + +Error BlockIndexer::visit(BufferExtents &) { + if (CurrentState == State::ThreadIDFound) { + Index::iterator It; + std::tie(It, std::ignore) = + Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}}); + It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID, + std::move(CurrentBlock.Records)}); + CurrentBlock.ProcessID = 0; + CurrentBlock.ThreadID = 0; + CurrentBlock.Records = {}; + } + CurrentState = State::ExtentsFound; + return Error::success(); +} + +Error BlockIndexer::visit(WallclockRecord &R) { + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::visit(NewCPUIDRecord &R) { + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::visit(TSCWrapRecord &R) { + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::visit(CustomEventRecord &R) { + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::visit(CallArgRecord &R) { + CurrentBlock.Records.push_back(&R); + return Error::success(); +}; + +Error BlockIndexer::visit(PIDRecord &R) { + CurrentBlock.ProcessID = R.pid(); + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::visit(NewBufferRecord &R) { + CurrentState = State::ThreadIDFound; + CurrentBlock.ThreadID = R.tid(); + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::visit(EndBufferRecord &R) { + CurrentState = State::SeekExtents; + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::visit(FunctionRecord &R) { + CurrentBlock.Records.push_back(&R); + return Error::success(); +} + +Error BlockIndexer::flush() { + CurrentState = State::SeekExtents; + Index::iterator It; + std::tie(It, std::ignore) = + Indices.insert({{CurrentBlock.ProcessID, CurrentBlock.ThreadID}, {}}); + It->second.push_back({CurrentBlock.ProcessID, CurrentBlock.ThreadID, + std::move(CurrentBlock.Records)}); + CurrentBlock.ProcessID = 0; + CurrentBlock.ThreadID = 0; + CurrentBlock.Records = {}; + return Error::success(); +} + +} // namespace xray +} // namespace llvm diff --git a/llvm/lib/XRay/CMakeLists.txt b/llvm/lib/XRay/CMakeLists.txt index 26e12ed73f3..ab6e0373c9e 100644 --- a/llvm/lib/XRay/CMakeLists.txt +++ b/llvm/lib/XRay/CMakeLists.txt @@ -1,4 +1,5 @@ add_llvm_library(LLVMXRay + BlockIndexer.cpp FDRRecordProducer.cpp FDRRecords.cpp FDRTraceWriter.cpp |