Skip to content

wyhasany/spring-startup-to-collapse-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Startup To Collapse Stack

spring-startup-to-collapse-stack is CLI tool converting output of startup endpoint to collapse stack format. Collapsed stack can be converted to the flame graph with help of AsyncProfiler.

Motivation

Spring Boot allows to gather startup metrics since version 2.4.0 (actuator docs, Spring Boot docs, Spring Framework docs). However there is lack of tool to visualize where our Spring Boot app spends time during the startup. Startup events could be gathered by JFR events and shown in JDK Mission Control: img/jdk-mission-control.png or can be listed by actuator as a json:

{
  "springBootVersion": "2.5.4",
  "timeline": {
    "startTime": "2021-10-09T17:35:50.813987Z",
    "events": [
      {
        "endTime": "2021-10-09T17:35:50.899008Z",
        "duration": 0.021545,
        "startupStep": {
          "name": "spring.boot.application.starting",
          "id": 0,
          "tags": [
            {
              "key": "mainApplicationClass",
              "value": "com.github.wyhasany.Application"
            }
          ]
        },
        "startTime": "2021-10-09T17:35:50.877463Z"
      },
      "..."
    ]
  }
}

Both approaches are troublesome to analyze that data.

We can reinvent the wheel and create new visualization tool as it was tried before ( [1], [2], [3]). Or we can reuse flame graphs which ideally fits for that purpose. That approach has been chosen by this project.

Example generated flame graph: img/flamegraph.png

Usage

Spring configuration

Configure your app to collect startup events:

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        new SpringApplicationBuilder()
            .applicationStartup(new BufferingApplicationStartup(2048))
            .sources(Application.class)
            .run(args);
    }
}

Download startup json

curl localhost:8091/actuator/startup > startup.json

Download spring-startup-to-collapse-stack converter

curl -L https://github.com/wyhasany/spring-startup-to-collapse-stack/releases/download/0.1-alpha/converter-spring-boot-startup.jar --output converter-spring-boot-startup.jar

Convert startup.json to collapse format

Keep in mind to use JDK 16

java -jar converter-spring-boot-startup.jar startup.json startup.collapse

Convert collapse format to HTML 5 Flame Graph

# Download async-profiler's converter
curl -L https://github.com/jvm-profiling-tools/async-profiler/releases/download/v2.5/converter.jar --output converter.jar
# convert to flame graph
java -cp converter.jar FlameGraph startup.collapse output.html

Open it in browser and explore as other Flame Graphs.

Note:

Shown samples actually refers to the duration µseconds of given step.

About

Spring Startup Actuator to Collapsed Stack converter

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages