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.
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: 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:
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);
}
}
curl localhost:8091/actuator/startup > startup.json
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
Keep in mind to use JDK 16
java -jar converter-spring-boot-startup.jar startup.json startup.collapse
# 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.