Skip to content
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

Feature/jdk21 virtual threads getCurrentThread CPU Time #87

Merged
merged 16 commits into from
Feb 1, 2025

Conversation

brunnert
Copy link
Contributor

@brunnert brunnert commented Jan 28, 2025

On JDK 21 with virtual threads enabled, the getCurrentThreadCpuTime always returns -1 if the current code runs in a virtual thread as the platform threads may change over time for a virtual thread:

getCurrentThreadCpuTime Virtual Threads

As a first attempt to solve this issue, we just assume that if a span on a virtual thread starts and ends on the same platform thread, we can account the whole cpu time spend on the platform thread to the virtual thread on the platform thread. In order to do this we are using the platform specific interfaces to fetch the cpuTime instead of relying on the JDK implementations. However, this is not entirely correct, a better approach would be to account for the exact timings a virtual thread has spent on different platform threads by looking at the virtual thread scheduler:

Virtual Thread Scheduling

but this might involve a lot more overhead.

@brunnert brunnert merged commit 991c970 into main Feb 1, 2025
1 check passed
@brunnert brunnert deleted the feature/JDK21VirtualThreads branch February 1, 2025 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant