[compiler-rt] [ctxprof] Auto root detection: trie for stack samples (PR #133106)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 27 13:24:21 PDT 2025
================
@@ -0,0 +1,90 @@
+//===- RootAutodetector.cpp - detect contextual profiling roots -----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "RootAutoDetector.h"
+#include "CtxInstrProfiling.h"
+
+#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_mutex.h"
+#include "sanitizer_common/sanitizer_placement_new.h"
+#include <assert.h>
+#include <dlfcn.h>
+#include <pthread.h>
+
+using namespace __ctx_profile;
+
+uptr PerThreadCallsiteTrie::getFctStartAddr(uptr CallsiteAddress) const {
+ // this requires --linkopt=-Wl,--export-dynamic
+ Dl_info Info;
+ if (dladdr(reinterpret_cast<const void *>(CallsiteAddress), &Info) != 0)
+ return reinterpret_cast<uptr>(Info.dli_saddr);
+ return 0;
+}
+
+void PerThreadCallsiteTrie::insertStack(const StackTrace &ST) {
+ auto *Current = &TheTrie;
+ // the stack is backwards - the first callsite is at the top.
+ for (int I = ST.size - 1; I >= 0; --I) {
+ auto ChildAddr = ST.trace[I];
----------------
snehasish wrote:
nit: s/auto/uptr - same number of letters even :)
https://github.com/llvm/llvm-project/pull/133106
More information about the llvm-commits
mailing list