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/unittests/XRay/FDRBlockIndexerTest.cpp | |
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/unittests/XRay/FDRBlockIndexerTest.cpp')
-rw-r--r-- | llvm/unittests/XRay/FDRBlockIndexerTest.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/llvm/unittests/XRay/FDRBlockIndexerTest.cpp b/llvm/unittests/XRay/FDRBlockIndexerTest.cpp new file mode 100644 index 00000000000..6f9d3eed33f --- /dev/null +++ b/llvm/unittests/XRay/FDRBlockIndexerTest.cpp @@ -0,0 +1,83 @@ +//===- llvm/unittest/XRay/FDRTraceWriterTest.cpp ----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include "llvm/XRay/BlockIndexer.h" +#include "llvm/XRay/FDRLogBuilder.h" +#include "llvm/XRay/FDRRecords.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace llvm { +namespace xray { +namespace { + +using ::testing::ElementsAre; +using ::testing::Eq; +using ::testing::Field; +using ::testing::Not; +using ::testing::SizeIs; + +// This test ensures that we can index blocks that follow version 3 of the log +// format. +TEST(FDRBlockIndexerTest, IndexBlocksV3) { + auto Block0 = LogBuilder() + .add<BufferExtents>(80) + .add<NewBufferRecord>(1) + .add<WallclockRecord>(1, 2) + .add<PIDRecord>(1) + .add<NewCPUIDRecord>(1) + .add<FunctionRecord>(RecordTypes::ENTER, 1, 1) + .add<FunctionRecord>(RecordTypes::EXIT, 1, 100) + .consume(); + auto Block1 = LogBuilder() + .add<BufferExtents>(80) + .add<NewBufferRecord>(1) + .add<WallclockRecord>(1, 2) + .add<PIDRecord>(1) + .add<NewCPUIDRecord>(1) + .add<FunctionRecord>(RecordTypes::ENTER, 1, 1) + .add<FunctionRecord>(RecordTypes::EXIT, 1, 100) + .consume(); + auto Block2 = LogBuilder() + .add<BufferExtents>(80) + .add<NewBufferRecord>(2) + .add<WallclockRecord>(1, 2) + .add<PIDRecord>(1) + .add<NewCPUIDRecord>(2) + .add<FunctionRecord>(RecordTypes::ENTER, 1, 1) + .add<FunctionRecord>(RecordTypes::EXIT, 1, 100) + .consume(); + BlockIndexer::Index Index; + BlockIndexer Indexer(Index); + // Iterate through the contrived blocks we have created above. + for (auto B : {std::ref(Block0), std::ref(Block1), std::ref(Block2)}) { + // For each record in the block, we apply the indexer. + for (auto &R : B.get()) + ASSERT_FALSE(errorToBool(R->apply(Indexer))); + ASSERT_FALSE(errorToBool(Indexer.flush())); + } + + ASSERT_THAT(Index.size(), Eq(2u)); + auto T1Blocks = Index.find({1, 1}); + ASSERT_THAT(T1Blocks, Not(Eq(Index.end()))); + + // Expect only six records, because we're ignoring the BufferExtents record. + EXPECT_THAT(T1Blocks->second, + ElementsAre(Field(&BlockIndexer::Block::Records, SizeIs(6u)), + Field(&BlockIndexer::Block::Records, SizeIs(6u)))); + auto T2Blocks = Index.find({1, 2}); + ASSERT_THAT(T2Blocks, Not(Eq(Index.end()))); + EXPECT_THAT(T2Blocks->second, ElementsAre(Field(&BlockIndexer::Block::Records, + SizeIs(Eq(6u))))); +} + +// FIXME: Support indexing V2 and V1 blocks. + +} // namespace +} // namespace xray +} // namespace llvm |