GeezerVison is showing github.com — Add time-to-safepoint JFR event · Issue #833 · async-profiler/async-profiler
Add time-to-safepoint JFR event #833DescriptionBackground
One of async-profiler features is time-to-safepoint profiling (--ttsp option) which enables collection of CPU or wall-clock events only in the time window between a safepoint has been requested and all Java threads have been stopped. This helps to diagnose the cause of long time-to-safepoint pauses.
--ttsp option is the most useful with JFR output format, since it preserves all samples with timestamps in a way that they can be matched with the corresponding pauses. However, to trace these pauses, user needs to enable safepoint logging and then manually match JFR samples with the VM logs.
It would be helpful to emit an additional JFR event for each time-to-safepoint pause to make it possible to analyze pauses using only the profiler recording independently of the VM logs.
Proposal
Introduce new event in async-profiler recordings for time-to-safepoint pauses. In fact, this event can be generalized for any combination of --begin/--end triggers, not just for safepoints.
Implementation
Add profiler.Window JFR event with the following fields:
- startTime
- duration
- eventThread
It will be emitted for every time window between --begin and --end traps. In particular, for --ttsp feature, each profiler.Window event will correspond to the time interval between the execution of SafepointSynchronize::begin and RuntimeService::record_safepoint_synchronized functions - in other words, each event will denote a corresponding time-to-safepoint pause. Reacted by Francesco Nigro and Brice Dutheil Activityapangin commented on Nov 2, 2023 CollaboratorAuthor More actions In this example, we see that a Profiling Window event with the duration of 32 ms is followed by 4 Method Profiling Sample events all with the same stack trace ending with MonitorList::unlink_deflated.
The above information suggests that the long time-to-safepoint pause (32 ms) was caused by the VM code doing monitor deflation. This already helped us to diagnose JDK-8319048. richardstartin commented on Nov 2, 2023 Hi @apangin, just for future reference, how does this differ from jdk.SafepointBegin (to get the timing) and jdk.VMOperation (to get the operation name) events? Unless I'm mistaken, jdk.SafepointBegin includes the time to suspend threads. Is this just in case the user wants to use async-profiler without any built in JFR events at all? Reacted by Francesco Nigro franz1981 commented on Nov 2, 2023 I think there's some overlap here as @richardstartin noted, but the profiler.Window generic name is probably there to cover for other types (user-defined) begin/end traps cases too, which ttsp is just an handy shortcut. apangin commented on Nov 2, 2023 CollaboratorAuthor More actions You are both right. First, as the description says, this is a generic event that works for any user-defined begin/end trigger. Second, enabling JDK Flight Recorder at runtime for the first time may have a significant performance impact, so it's better to stay with async-profiler-only events if they are sufficient to solve the problem.
Strictly speaking, the feature does not add anything fundamentally new - it's just a matter of convenience. Reacted by Francesco Nigro and Richard Startin richardstartin commented on Nov 2, 2023 It might be difficult to implement here because it requires state and context propagation to do it, but we (Datadog continuous profiler) record things like times spent in thread pool queues with latency thresholds so you can see what else was executing immediately before on the thread your task ends up running (i.e. blocking tasks clogging up event loops). E.g. in the screenshot below a "mouse" task gets stuck behind an "elephant" and has to wait.

I wonder if this event could be generalised slightly so a user could instrument their code (either with a java agent or manually) to trace events across thread boundaries to produce similar traces? apangin commented on Nov 2, 2023 CollaboratorAuthor More actions @richardstartin What you propose is definitely an interesting feature, although it has no direct relationship with the original problem. Feel free to create a new issue, and let me close this one as completed. Thanks.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|