[compiler-rt] [compiler-rt][ctx_profile] Add the instrumented contextual profiling APIs (PR #89838)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Mon May 6 08:46:43 PDT 2024
================
@@ -20,3 +29,148 @@ TEST(ArenaTest, Basic) {
Arena::freeArenaList(A);
EXPECT_EQ(A, nullptr);
}
+
+TEST_F(ContextTest, Basic) {
+ auto *Ctx = __llvm_ctx_profile_start_context(&Root, 1, 10, 4);
+ EXPECT_NE(Ctx, nullptr);
+ EXPECT_NE(Root.CurrentMem, nullptr);
+ EXPECT_EQ(Root.FirstMemBlock, Root.CurrentMem);
+ EXPECT_EQ(Ctx->size(), sizeof(ContextNode) + 10 * sizeof(uint64_t) +
+ 4 * sizeof(ContextNode *));
+ EXPECT_EQ(Ctx->counters_size(), 10U);
+ EXPECT_EQ(Ctx->callsites_size(), 4U);
+ EXPECT_EQ(__llvm_ctx_profile_current_context_root, &Root);
+ Root.Taken.CheckLocked();
+ EXPECT_FALSE(Root.Taken.TryLock());
+ __llvm_ctx_profile_release_context(&Root);
+ EXPECT_EQ(__llvm_ctx_profile_current_context_root, nullptr);
+ EXPECT_TRUE(Root.Taken.TryLock());
+ Root.Taken.Unlock();
+}
+
+TEST_F(ContextTest, Callsite) {
+ auto *Ctx = __llvm_ctx_profile_start_context(&Root, 1, 10, 4);
+ int OpaqueValue = 0;
+ const bool IsScratch = isScratch(Ctx);
+ EXPECT_FALSE(IsScratch);
+ __llvm_ctx_profile_expected_callee[0] = &OpaqueValue;
+ __llvm_ctx_profile_callsite[0] = &Ctx->subContexts()[2];
+ auto *Subctx = __llvm_ctx_profile_get_context(&OpaqueValue, 2, 3, 1);
+ EXPECT_EQ(Ctx->subContexts()[2], Subctx);
+ EXPECT_EQ(Subctx->counters_size(), 3U);
+ EXPECT_EQ(Subctx->callsites_size(), 1U);
+ EXPECT_EQ(__llvm_ctx_profile_expected_callee[0], nullptr);
+ EXPECT_EQ(__llvm_ctx_profile_callsite[0], nullptr);
+
+ EXPECT_EQ(Subctx->size(), sizeof(ContextNode) + 3 * sizeof(uint64_t) +
+ 1 * sizeof(ContextNode *));
+ __llvm_ctx_profile_release_context(&Root);
+}
+
+TEST_F(ContextTest, ScratchNoCollection) {
+ EXPECT_EQ(__llvm_ctx_profile_current_context_root, nullptr);
+ int OpaqueValue = 0;
+ // this would be the very first function executing this. the TLS is empty,
----------------
teresajohnson wrote:
Can you clarify - I assume it is scratch because start context hasn't been called?
https://github.com/llvm/llvm-project/pull/89838
More information about the llvm-commits
mailing list