-
Notifications
You must be signed in to change notification settings - Fork 12
feat(profiler): native malloc/socket stack capture with profiler-hook frame skipping #648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jbachorik
wants to merge
13
commits into
main
Choose a base branch
from
jb/malloc_profiles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
60efe7b
Rename profiler.Malloc JFR event to datadog.NativeMemoryAllocation; f…
jbachorik 29e859d
Fix missing native frames for BCI_NATIVE_SOCKET under default cstack
jbachorik d2d6893
Skip profiler-internal hook frames in native malloc/socket call stacks
jbachorik df9be61
Skip profiler-internal hook frames in walkVM (cstack=vm/vmx) too
jbachorik 002040c
Address review findings on malloc/socket hook-skip stackwalking
jbachorik 15f3132
Merge branch 'main' into jb/malloc_profiles
jbachorik d27a19e
Merge branch 'main' into jb/malloc_profiles
jbachorik bc3ec7d
Merge branch 'main' into jb/malloc_profiles
jbachorik d061e9a
Merge branch 'main' into jb/malloc_profiles
jbachorik d669181
Rename
jbachorik fb32d57
Merge branch 'main' into jb/malloc_profiles
jbachorik ce3a047
Address PR review feedback: mirror hook-boundary counter in walkVM, r…
jbachorik 8e3bb25
Document mark field value domain in NativeFrameResolution
jbachorik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,11 @@ | |
|
|
||
| #if defined(__linux__) | ||
|
|
||
| #include "codeCache.h" | ||
| #include "common.h" | ||
| #include "counters.h" | ||
| #include "flightRecorder.h" | ||
| #include "libraries.h" | ||
| #include "libraryPatcher.h" | ||
| #include "log.h" | ||
| #include "os.h" | ||
|
|
@@ -27,6 +30,30 @@ | |
| static thread_local PoissonSampler _send_sampler; | ||
| static thread_local PoissonSampler _recv_sampler; | ||
|
|
||
| // Marks the hook wrapper's own symbol as MARK_JAVA_PROFILER so native call-stack | ||
| // unwinding (Profiler::convertNativeTrace) can recognize the boundary between | ||
| // profiler-internal frames and the real caller, mirroring MallocHooker::initialize(). | ||
| // Resolved by address (not by symbol-name predicate) because these are mangled | ||
| // C++ static member functions, unlike malloc_hook's extern "C" free functions. | ||
| // Returns false if the symbol could not be resolved/marked, in which case the | ||
| // hook boundary is never recognized and every socket sample's native stack | ||
| // comes back empty (see NATIVE_TRACE_HOOK_PREFIX_NOT_FOUND). | ||
| static bool markJavaProfilerHook(void* fn_addr) { | ||
| CodeCache* lib = Libraries::instance()->findLibraryByAddress(fn_addr); | ||
| if (lib == nullptr) { | ||
| Counters::increment(NATIVE_HOOK_MARK_RESOLVE_FAILED); | ||
| return false; | ||
| } | ||
| const char* name = nullptr; | ||
| lib->binarySearch(fn_addr, &name); | ||
| if (name == nullptr) { | ||
| Counters::increment(NATIVE_HOOK_MARK_RESOLVE_FAILED); | ||
| return false; | ||
| } | ||
| NativeFunc::set_mark(name, MARK_JAVA_PROFILER); | ||
| return true; | ||
| } | ||
|
|
||
| // Debug-only hook-fire counters, paired with TEST_LOG (common.h). Gated at | ||
| // compile time to keep release hot paths free of cross-thread atomic writes. | ||
| #ifdef DEBUG | ||
|
|
@@ -386,6 +413,18 @@ Error NativeSocketSampler::start(Arguments &args) { | |
| TEST_LOG("NativeSocketSampler::start interval_ticks=%ld tsc_freq=%llu", | ||
| init_interval, (unsigned long long)TSC::frequency()); | ||
| #endif | ||
| bool hooks_marked = markJavaProfilerHook((void*)&NativeSocketSampler::send_hook); | ||
| hooks_marked &= markJavaProfilerHook((void*)&NativeSocketSampler::recv_hook); | ||
| hooks_marked &= markJavaProfilerHook((void*)&NativeSocketSampler::write_hook); | ||
| hooks_marked &= markJavaProfilerHook((void*)&NativeSocketSampler::read_hook); | ||
| if (!hooks_marked) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coverage gap (acceptable): nothing exercises this failure branch or the new |
||
| // Not fatal: hooks are still installed and sampling still works, but | ||
| // native stacks for socket samples will come back empty because the | ||
| // hook boundary frame can't be recognized during unwinding. | ||
| Log::warn("NativeSocketSampler: failed to mark one or more hook symbols; " | ||
| "native call stacks for socket samples may be empty"); | ||
| } | ||
|
|
||
| if (!LibraryPatcher::patch_socket_functions()) { | ||
| return Error("failed to install native socket hooks (dlsym returned NULL)"); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.