Turn -XX:+TraceBytecodes output into a FlameGraph compatible stack format

Related tags

Profilers bytestacks
Overview

A tool to turn the output of -XX:+TraceBytecodes (a JDK debug-only feature to print every bytecode executed by the interpreter) into a simple stack format, and a script to turn that into flame graphs showing what happened during program execution, bytecode-by-bytecode: Flame graph generated from running a Hello World program on 9-ea+157

Who/what is this for?

This is a diagnostic tool I've developed and used to visualize what is going on at startup at a high granularity. Since it relies on a very verbose and slow debug option it's not by any means a good estimator of how long time things actually take.

As such, this is more a diagnostic tool than a profiler, but a tool that has served us well to disentangle various startup dependencies and inefficiencies in the JDK itself - and been a valuable aid in diagnosing a number of startup regressions.

Why?

Most profiling tools either have a blind spot when it comes to capturing what happens during the very early initialization of a JVM, e.g., agent based instrumentation, JFR etc, or they are native profiling tools that would attribute everything to "something in the interpreter".

Requirements

  • git and perl required to get FlameGraph working
  • a fastdebug (recommended) or slowdebug build of OpenJDK (you may have to build one yourself)

If you are on Linux, you can download a fastdebug binary from https://www.chriswhocodes.com/ and install it with Jabba:

jabba install fastdebug@11=tgz+https://www.chriswhocodes.com/downloads/jdk11-chriswhocodes-nightly-linux-x86_64-fastdebug.tgz
jabba use fastdebug@11

Jabba also supports XZ format, so you can download nightly and 15 builds:

jabba install shipilev-fastdebug@nightly=tgx+https://builds.shipilev.net/openjdk-jdk/openjdk-jdk-latest-linux-x86_64-fastdebug.tar.xz
jabba install shipilev-fastdebug@15=tgx+https://builds.shipilev.net/openjdk-jdk15/openjdk-jdk15-latest-linux-x86_64-fastdebug.tar.xz

Usage

  • Build: ./gradlew build
  • With a fastdebug build of java, run any (small) program with -XX:+TraceBytecodes, e.g.: java -XX:+TraceBytecodes HelloWorld | ./bytestacks helloworld
    • This generates helloworld.stacks and helloworld.svg only.
  • open helloworld.svg in your favorite SVG viewer. A modern web browser should suffice.

By not retaining the trace output we'll run a lot faster and we avoid wasting disk space, but if you need the tracing output it's easy to split the steps apart:

  • Run java -XX:TraceBytecodes > helloworld (this dumps the raw tracing output to helloworld
  • Run ./bytestacks helloworld (this generates helloworld.stacks and uses FlameGraph to produce helloworld.svg)

Going deeper...

  • To get the full picture of what's going on, especially on a longer running program, it might be interesting to run your program with -Xint, since as things start to get compiled they will disappear from view...
  • For performance reasons there is a granularity option which allows setting a threshold for how small methods are output in the stack output, defaulting to 25. By setting this to a lower value, the generated flame graph will become more detailed, but may also become very heavy to render

References

You might also like...

documents4j is a Java library for converting documents into another document format

documents4j is a Java library for converting documents into another document format. This is achieved by delegating the conversion to any

Dec 23, 2022

Convert Journeymap image data into Xaero format for Xaero's minecraft map mod

Convert Journeymap image data into Xaero format for Xaero's minecraft map mod

JMtoXaero JMtoXaero is a tool to convert JourneyMap tiles to regions used by Xaero's World Map Description Reads images from the Journeymap folder Wri

Dec 21, 2022

Split into data blocks,In this format, efficient reading can be realized,Avoid unnecessary data reading operations.

Split into data blocks,In this format, efficient reading can be realized,Avoid unnecessary data reading operations.

dataTear 切换至:中文文档 knowledge base dataTear Split into data fragments for data management. In this format, efficient reading can be achieved to avoid un

Dec 15, 2022

Your window into the Elastic Stack

Kibana Kibana is your window into the Elastic Stack. Specifically, it's a browser-based analytics and search dashboard for Elasticsearch. Getting Star

Jan 2, 2023

JVM Profiler Sending Metrics to Kafka, Console Output or Custom Reporter

Uber JVM Profiler Uber JVM Profiler provides a Java Agent to collect various metrics and stacktraces for Hadoop/Spark JVM processes in a distributed w

Dec 22, 2022

Inspect pmap -X output of a java process, requires Java11, likely not 100% accurate

java-pmap-inspector Inspect pmap -X output of a java process, requires Java 11, likely not 100% accurate. Usage examples $ pmap -X pid pmap.txt; jav

Jul 6, 2022

🎯 ConsoleCaptor captures console output for unit testing purposes

ConsoleCaptor Install library with: Install with maven dependency groupIdio.github.hakky54/groupId artifactIdconsolecaptor/artifactId

Dec 9, 2022

A query language for JSON and a template engine to generate text output.

Josson & Jossons Josson is a query language for JSON. Jossons is a template engine to generate text output. Features and Capabilities of Josson Query

Dec 14, 2022

Output Keycloak Events and Admin Events to a Kafka topic.

keycloak-kafka-eventlistener Output Keycloak Events and Admin Events to a Kafka topic. Based on Keycloak 15.0.2+ / RH-SSO 7.5.0+ How to use the plugin

Oct 10, 2022

A doclet to output javadoc as an XML document.

xml-doclet This library provides a doclet to output the javadoc comments from Java source code to an XML document. Works with Java 11 and above, suppo

Oct 28, 2022

Kryptonite is a turn-key ready transformation (SMT) for Apache Kafka® Connect to do field-level 🔒 encryption/decryption 🔓 of records. It's an UNOFFICIAL community project.

Kryptonite - An SMT for Kafka Connect Kryptonite is a turn-key ready transformation (SMT) for Apache Kafka® to do field-level encryption/decryption of

Jan 3, 2023

Partially implemented interprocess game of "Scotland Yard". Fork, fill in the gaps, and turn in on Moodle!

Scotland Yard The Game The city is an 8 x 8 grid, a Fugitive runs amok. In a single turn, the Fugitive can move like a chess Queen: horizontally, vert

May 4, 2022

This app/widget is based on the work of Anthony (tonesto7), which is in turn based on the earlier work of David Schablowsky

This app/widget is based on the work of Anthony (tonesto7), which is in turn based on the earlier work of David Schablowsky

Mustang Mach-E Widget for Android Intro This app/widget is based on the work of Anthony (tonesto7), which is in turn based on the earlier work of Davi

Nov 15, 2022

Kingdoms Wars - a turn-based strategy game created with Java.

Kingdoms Wars - a turn-based strategy game created with Java.

Kingdoms Wars is a turn-based strategy game created with Java. The game is loosely based on the Punic Wars.

Feb 7, 2022

A turn-based strategy game

Stalemate Game This is a turn-based strategy game. Support You can report issues in issue tracker. Contributing Contributions are welcomed. Building T

Jul 6, 2022

A Text Based, Turn-Based, Strategy Game to be played in console

ConsoleGame A Text Based, Turn-Based, Strategy Game to be played in console. Feel free to fix any retardation in my code (meaning bugs, stupid/spaghet

Jul 17, 2022

A java.util.HashMap compatible map that won't stall puts or gets when resizing

/* * Written by Gil Tene, based on Apache Harmony version of java.util.HashMap. */ PauselessHashMap: A java.util.HashMap compatible Map implementat

Oct 19, 2022

NoSQL data store using the seastar framework, compatible with Apache Cassandra

Scylla What is Scylla? Scylla is the real-time big data database that is API-compatible with Apache Cassandra and Amazon DynamoDB. Scylla embraces a s

Dec 27, 2022
Owner
Claes Redestad
Claes Redestad
JVM Profiler Sending Metrics to Kafka, Console Output or Custom Reporter

Uber JVM Profiler Uber JVM Profiler provides a Java Agent to collect various metrics and stacktraces for Hadoop/Spark JVM processes in a distributed w

Uber Common 1.7k Dec 22, 2022
Inspect pmap -X output of a java process, requires Java11, likely not 100% accurate

java-pmap-inspector Inspect pmap -X output of a java process, requires Java 11, likely not 100% accurate. Usage examples $ pmap -X pid > pmap.txt; jav

Brice Dutheil 7 Jul 6, 2022
production heap profiling for the JVM. compatible with google-perftools.

Heapster Heapster provides an agent library to do heap profiling for JVM processes with output compatible with Google perftools. The goal of Heapster

marius a. eriksen 392 Dec 27, 2022
Generate flame graph in HTML format from jfr(Java Flight Recorder) file

jfr-flamegraph-generator Generate Flame Graph from .jfr file. Get Started Executable jar and executable binary for Linux, Windows and macOS are provid

Lawrence Ching 3 Sep 22, 2022
A short and practical intro into project loom

project-loom Project loom is all about making concurrency easier (for developers) on the JVM. It is in experimental phase. Download the early access b

Ashwin Bhaskar 16 Dec 15, 2021
Get Method Sampling from Java Flight Recorder Dump and convert to FlameGraph compatible format.

Note: Travis has removed the support for Oracle JDK 8. Therefore the build status is removed temporarily. Converting JFR Method Profiling Samples to F

M. Isuru Tharanga Chrishantha Perera 248 Dec 16, 2022
When it is snowing leaves will slowly turn white, and when it is not they will turn back to normal

SnowyLeavesPlus In Bedrock Edition, leaves turn white when it is snowing. SnowyLeavesPlus brings this feature to Java Edition! When it is snowing leav

Ilesh Thiada 8 Nov 26, 2022
Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.

Description Jansi is a small java library that allows you to use ANSI escape codes to format your console output which works even on Windows. It also

FuseSource 955 Dec 28, 2022
a simple program to turn stockX images into gifs!

StockX Gif Converter make stockx images look cool Idea I got this idea from Fyko/stockx-gif-next Usage import me.brennan.stockxgiffer.StockXGiffer; p

Brennan 7 Jul 19, 2022
An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

DevOpsify Description An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or t

obaydah bouifadene 14 Nov 8, 2022