aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ProfileData/MemProfTest.cpp
diff options
context:
space:
mode:
authorSnehasish Kumar <snehasishk@google.com>2022-01-19 13:26:37 -0800
committerSnehasish Kumar <snehasishk@google.com>2022-02-14 09:53:45 -0800
commit9b67165285c5e752fce3b554769f5a22e7b38da8 (patch)
tree82b193895deb12178f5afaa7d39a08ee641021f2 /llvm/unittests/ProfileData/MemProfTest.cpp
parent9def83c6d02944b2931efd50cd2491953a772aab (diff)
downloadllvm-9b67165285c5e752fce3b554769f5a22e7b38da8.zip
llvm-9b67165285c5e752fce3b554769f5a22e7b38da8.tar.gz
llvm-9b67165285c5e752fce3b554769f5a22e7b38da8.tar.bz2
[memprof] Introduce a wrapper around MemInfoBlock.
Use the macro based format to add a wrapper around the MemInfoBlock when stored in the MemProfRecord. This wrapped block can then be serialized/deserialized based on a schema specified by a list of enums. Differential Revision: https://reviews.llvm.org/D117256
Diffstat (limited to 'llvm/unittests/ProfileData/MemProfTest.cpp')
-rw-r--r--llvm/unittests/ProfileData/MemProfTest.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp
index 09ffe8f..38dc863 100644
--- a/llvm/unittests/ProfileData/MemProfTest.cpp
+++ b/llvm/unittests/ProfileData/MemProfTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/ProfileData/RawMemProfReader.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MD5.h"
+#include "llvm/Support/raw_ostream.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -24,6 +25,9 @@ using ::llvm::DILocal;
using ::llvm::memprof::CallStackMap;
using ::llvm::memprof::MemInfoBlock;
using ::llvm::memprof::MemProfRecord;
+using ::llvm::memprof::MemProfSchema;
+using ::llvm::memprof::Meta;
+using ::llvm::memprof::PortableMemInfoBlock;
using ::llvm::memprof::RawMemProfReader;
using ::llvm::memprof::SegmentEntry;
using ::llvm::object::SectionedAddress;
@@ -99,6 +103,14 @@ MATCHER_P4(FrameContains, Function, LineOffset, Column, Inline, "") {
return false;
}
+MemProfSchema getFullSchema() {
+ MemProfSchema Schema;
+#define MIBEntryDef(NameTag, Name, Type) Schema.push_back(Meta::Name);
+#include "llvm/ProfileData/MIBEntryDef.inc"
+#undef MIBEntryDef
+ return Schema;
+}
+
TEST(MemProf, FillsValue) {
std::unique_ptr<MockSymbolizer> Symbolizer(new MockSymbolizer());
@@ -136,8 +148,8 @@ TEST(MemProf, FillsValue) {
}
EXPECT_EQ(Records.size(), 2U);
- EXPECT_EQ(Records[0].Info.AllocCount, 1U);
- EXPECT_EQ(Records[1].Info.AllocCount, 2U);
+ EXPECT_EQ(Records[0].Info.getAllocCount(), 1U);
+ EXPECT_EQ(Records[1].Info.getAllocCount(), 2U);
EXPECT_THAT(Records[0].CallStack[0], FrameContains("foo", 5U, 30U, false));
EXPECT_THAT(Records[0].CallStack[1], FrameContains("bar", 51U, 20U, true));
@@ -147,4 +159,29 @@ TEST(MemProf, FillsValue) {
EXPECT_THAT(Records[1].CallStack[3], FrameContains("bar", 51U, 20U, true));
}
+TEST(MemProf, PortableWrapper) {
+ MemInfoBlock Info(/*size=*/16, /*access_count=*/7, /*alloc_timestamp=*/1000,
+ /*dealloc_timestamp=*/2000, /*alloc_cpu=*/3,
+ /*dealloc_cpu=*/4);
+
+ const auto Schema = getFullSchema();
+ PortableMemInfoBlock WriteBlock(Info);
+
+ std::string Buffer;
+ llvm::raw_string_ostream OS(Buffer);
+ WriteBlock.serialize(Schema, OS);
+ OS.flush();
+
+ PortableMemInfoBlock ReadBlock(
+ Schema, reinterpret_cast<const unsigned char *>(Buffer.data()));
+
+ EXPECT_EQ(ReadBlock, WriteBlock);
+ // Here we compare directly with the actual counts instead of MemInfoBlock
+ // members. Since the MemInfoBlock struct is packed and the EXPECT_EQ macros
+ // take a reference to the params, this results in unaligned accesses.
+ EXPECT_EQ(1, ReadBlock.getAllocCount());
+ EXPECT_EQ(7, ReadBlock.getTotalAccessCount());
+ EXPECT_EQ(3, ReadBlock.getAllocCpuId());
+}
+
} // namespace