Skip to content

JVMTI based implementation of Wallclock profiler - #126

Merged
jbachorik merged 6 commits into
mainfrom
jb/jvmti_wallclock
Sep 18, 2024
Merged

jbachorik merged 6 commits into
mainfrom
jb/jvmti_wallclock

Conversation

@jbachorik

@jbachorik jbachorik commented Sep 5, 2024 •

Copy link
Copy Markdown
Collaborator

What does this PR do?:
Add a new wallclock engine based on JVMTI GetStackTrace function

Motivation:
We have witnessed a few crashes related to interleaved calls to AsyncGetCallTrace. There were certain rail-guards put in place to avoid that but not having to call AsyncGetCallTrace still feels like the safest option.

Since Java 11 the GetStackTrace function is using thread-local handshake and is not incurring the cost of safepoint. Therefore it is a quite cheap operation which is completely stable, though with slight safepoint bias.

While it is possible to enable this engine also on Java 8, doing so will result in terrible performance.

Additional Notes:
Based on #118 by @richardstartin

How to test the change?:
New unit tests were added

Once you build the library ./gradlew assembleDebugJar you can enable the new wallclock profiler by running your java application like:
java -agentpath:<base>/ddprof-lib/build/lib/main/debug/linux/x64/libjavaProfiler.so=start,cpu,wall,wallsampler=jvmti,jfr,file=/tmp/profile.jfr ...
(this is for linux - if you are building and testing on macos, adjust the paths accordingly)

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: PROF-10079

Unsure? Have a question? Request a review!

@github-actions

github-actions Bot commented Sep 5, 2024 •

Copy link
Copy Markdown
Contributor

🔧 Report generated by pr-comment-cppcheck

CppCheck Report

Errors (1)

Warnings (7)

Style Violations (160)

@github-actions

github-actions Bot commented Sep 5, 2024 •

Copy link
Copy Markdown
Contributor

🔧 Report generated by pr-comment-scanbuild

Scan-Build Report

User:runner@fv-az1535-406
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 clean all
Clang Version:Ubuntu clang version 14.0.0-1ubuntu1.1
Date:Wed Sep 18 08:03:40 2024

Bug Summary

Bug TypeQuantityDisplay?
All Bugs5
Logic error
Assigned value is garbage or undefined1
Dereference of null pointer3
Unused code
Dead nested assignment1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Logic errorAssigned value is garbage or undefineddwarf.cppparseInstructions24420
Unused codeDead nested assignmentvmStructs.cppcheckNativeBinding8791
Logic errorDereference of null pointersafeAccess.hload3218
Logic errorDereference of null pointersymbols_linux.hElfParser12932
Logic errorDereference of null pointerflightRecorder.cppflush15048

@jbachorik
jbachorik marked this pull request as ready for review September 5, 2024 15:37
Comment thread ddprof-lib/src/main/cpp/wallClock.h Resolved
Comment thread ddprof-lib/src/main/cpp/arguments.h Resolved
reservoir.reserve(size);
}

std::vector<T>& sample(const std::vector<T> &input) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't go into the actual algorithm we chose here and whether it was the correct one. Please tell me if I should spend more time here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am quite confident of the algorithm here.
Probably not worth spending a lot of time on it - @richardstartin has a link to an article describing this algorithm, IIRC, if you are interested.

@MattAlp MattAlp left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread ddprof-lib/src/main/cpp/wallClock.cpp Resolved
Comment thread ddprof-lib/src/main/cpp/wallClock.cpp Resolved
@jbachorik
jbachorik merged commit cb43b5c into main Sep 18, 2024
@jbachorik
jbachorik deleted the jb/jvmti_wallclock branch September 18, 2024 08:26
@github-actions github-actions Bot added this to the 1.14.0 milestone Sep 18, 2024
@zhengyu123 zhengyu123 added the fixed_version: v_1.14.0 Version this PR's fix shipped in label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixed_version: v_1.14.0 Version this PR's fix shipped in

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants