GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add time-to-safepoint JFR event · Issue #833 · async-profiler/async-profiler

Add time-to-safepoint JFR event #833

New issue
Copy link
New issue
Copy link
Closed
Closed
Add time-to-safepoint JFR event#833
Copy link
Labels
enhancement

Description

@apangin
apangin
opened on Nov 2, 2023
Issue body actions

Background

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

Activity

  1. apangin
    added
    enhancement
    on Nov 2, 2023
  2. apangin commented on Nov 2, 2023

    @apangin
    apangin
    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.

    jfr

    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.

  3. apangin
    added a commit that references this issue on Nov 2, 2023

    #833: Time-to-safepoint JFR event

    a237cad
  4. richardstartin commented on Nov 2, 2023

    @richardstartin
    richardstartin
    on Nov 2, 2023
    More actions

    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
  5. franz1981 commented on Nov 2, 2023

    @franz1981
    franz1981
    on Nov 2, 2023
    More actions

    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.

    Reacted by Andrei Pangin
  6. apangin commented on Nov 2, 2023

    @apangin
    apangin
    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
  7. richardstartin commented on Nov 2, 2023

    @richardstartin
    richardstartin
    on Nov 2, 2023
    More actions

    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.
    Screenshot 2023-11-02 at 11 28 54

    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?

  8. apangin commented on Nov 2, 2023

    @apangin
    apangin
    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.

  9. apangin
    closed this as completedon Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.