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 — Running jfr2flame on concatenated JFR files produces nonsense stacktraces · Issue #849 · async-profiler/async-profiler

Running jfr2flame on concatenated JFR files produces nonsense stacktraces #849

New issue
Copy link
New issue
Copy link
Closed
Closed
Running jfr2flame on concatenated JFR files produces nonsense stacktraces#849
Copy link

Description

@gharris1727
gharris1727
opened on Nov 28, 2023
Issue body actions

Hi, and thanks so much for the async-profiler!

I'm trying to use the async-profiler to profile a short-lived JVM from start-to-finish.
I couldn't figure out a way to send a stop command during JVM shutdown, so I have been using this agent string to approximate a full profile:

-agentpath:/path/to/libasyncProfiler.so=start,event=wall,loop=1s,jfr,file=/tmp/output/%n.jfr

This generates multiple JFR files that I then concatenate together, and pass through jfr2flame. But the output isn't what I expect. Here's a repro case:

export PROFILER="/path/to/async/profiler"
echo "Thread.sleep(3000)" | jshell "-J-agentpath:$PROFILER/build/libasyncProfiler.so=start,event=wall,loop=1s,jfr,file=/tmp/output/%n.jfr"
cat /tmp/output/* > /tmp/combined.jfr
java -cp "$PROFILER/converter.jar" jfr2flame /tmp/combined.jfr /tmp/out.html --threads

Open the output HTML, click on the "main" thread, and search for "JShell.eval". For me on 2.9, it looks like this:
Flamegraph showing three separate blocks for JShell.eval
The stacktrace with the most samples appears to be the correct one, the ones on the right side show JShell.eval without a parent frame, or show JShell.eval eventually calling itself, which isn't happening in reality.

I checked the output of the jfr tool for the combined.jfr, and it looks to generate reasonable stacktraces:

jfr print --stack-depth 1000 /tmp/combined.jfr | grep -A 1 JShell.eval

The output looks like this:

    jdk.jshell.JShell.eval(String) line: 513
    jdk.internal.jshell.tool.JShellTool.processSource(String) line: 3633
--
    jdk.jshell.JShell.eval(String) line: 513
    jdk.internal.jshell.tool.JShellTool.processSource(String) line: 3633
--
<snipped>

The jfr tool shows stack frame above JShell.eval is always JShellTool.processSource, where the flame graph does not make this clear. I checked other discrepancies in the flamegraph against the jfr tool, and they sometimes disagree, as if the end of one stacktrace got appended to the other.

I would expect that after profiling a program that only calls a method once, that method would only appear once in the flamegraph with a consistent stacktrace. This should happen whether or not the profile is performed in one JFR file or across multiple JFR files with loop.

  1. The jshell usage is just a concise example, I am profiling a non-trivial program and seeing similar behavior.
  2. I don't see the corruption when running jfr2flame on the individual JFR files generated by the loop.
  3. I tried using the jfr tool to assemble the JFR files and got the same result as plain concatenation
  4. Changing the order of concatenation appears to change the resulting flame graph, but doesn't fix it.

Thanks!

Activity

  1. apangin commented on Nov 28, 2023

    @apangin
    apangin
    on Nov 28, 2023
    Collaborator
    More actions

    I couldn't figure out a way to send a stop command during JVM shutdown

    You don't need to. Active async-profiler recording is automatically stopped at an orderly JVM termination.

  2. apangin commented on Nov 28, 2023

    @apangin
    apangin
    on Nov 28, 2023
    Collaborator
    More actions

    This generates multiple JFR files that I then concatenate together, and pass through jfr2flame. But the output isn't what I expect.

    Yes, it's a known issue. jfr2flame does not currently support merged recordings.
    I will probably fix this, but as mentioned above, you don't need loop option to collect start-to-finish profiles.

  3. gharris1727 commented on Nov 28, 2023

    @gharris1727
    gharris1727
    on Nov 28, 2023
    Author
    More actions

    You don't need to. Active async-profiler recording is automatically stopped at an orderly JVM termination.
    you don't need loop option to collect start-to-finish profiles.

    Ah, thank you! that works great, and now I don't need the combination step that is causing the issue.
    I think I was sending my JFR files into the void, then added the loop parameter, and then fixed the voiding issue, and never checked if the loop parameter was necessary.

    And I just tracked down the source of the corruption: the ids for the different segments overwrite one another before the aggregation is finished, so everything gets messed up. The "appending" behavior I saw was just because method IDs had ascending numerical IDs.

    Thank you for answering this question, and I hope that JfrReader supports multi-segment files correctly in the future!

  4. gharris1727
    closed this as completedon Nov 28, 2023
  5. apangin
    added a commit that references this issue on Dec 3, 2023

    #849: Parse concatenated multi-chunk JFRs

    bfdaa44
  6. apangin commented on Dec 3, 2023

    @apangin
    apangin
    on Dec 3, 2023
    Collaborator
    More actions

    I fixed JfrReader to parse concatenated JFRs correctly.

    Reacted by Suresh and Shani Elharrar
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

    No labels
    No labels

    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.