https://github.com/omarmahamid/async
async profiler for spring applications
https://github.com/omarmahamid/async
async-profiler flamegraph java jvm profiling spring-boot
Last synced: 10 months ago
JSON representation
async profiler for spring applications
- Host: GitHub
- URL: https://github.com/omarmahamid/async
- Owner: omarmahamid
- Created: 2024-10-09T16:13:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-17T21:55:24.000Z (over 1 year ago)
- Last Synced: 2025-04-22T14:09:39.003Z (10 months ago)
- Topics: async-profiler, flamegraph, java, jvm, profiling, spring-boot
- Language: Java
- Homepage:
- Size: 399 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# async profiler embedded in java applications
This project provides an embedded solution for Async Profiler https://github.com/async-profiler/async-profiler within a Java applications, with modules for core functionality, Spring integration, and annotations. It enables you to capture profiling data at regular intervals and automatically generate HTML reports that can be viewed in a browser.
## Features
1. Embedded Async Profiler for Java applications.
2. Captures profiling data at scheduled intervals.
3. Generates easy-to-read HTML reports.
4. Supports multiple profiling events like CPU, ALLOC, and WALL.
5. Can profile main method within async-annotation.
## Artifacts
1. `async-core`: Core profiling functionalities.
2. `async-spring`: Profiling integration with Spring applications.
3. `async-annotation`: Annotations for easy profiling in main methods.
# pre-requisite
`Java 17+`
## Supported Machines
| CPU Arch | Linux | MacOS | Windows |
|----------|-------|-------|---------|
| x86_64 | ✔️ | ✔️ | ❌ |
| arm | ✔️ | ✔️ | ❌ |
| arm64 | ✔️ | ✔️ | ❌ |
# Module Details
## async-core
The core module of the project, responsible for managing the actual profiling tasks.
### Dependency
io.github.omarmahamid
async-core
${LATEST_VERSION}
## async-spring
Provides seamless integration with Spring, allowing you to enable async profiling in your Spring services. Profiling reports are generated automatically at scheduled intervals.
### Dependency
io.github.omarmahamid
async-spring
${LATEST_VERSION}
### Configuration
`async-profiler-enabled` - Enable profiler to work.
`async-profiler-event` - Event of async profiler (CPU, ALLOC, WALL). (Default is CPU)
`async-profiler-duration` - Duration of interval profiling in seconds. (Default is 1000)
`async-profiler-basedir` - The based directory to dump the html files in. (Default is base application dir)
### Generated File
async will generate a html file that can be shown in the browser.


## async-annotation
Allows you to use custom annotations to specify which parts of your code should be profiled. This makes it easy to apply profiling to specific methods or classes.
### Dependency
io.github.omarmahamid
async-annotation
${LATEST_VERSION}
## Usage
adding @Profiling annotation on main method
```java
package io.github.omarmahamid.annotation;
import io.github.omarmahamid.async.ModeAsyncProfiler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Profiling {
ModeAsyncProfiler mode() default ModeAsyncProfiler.CPU;
long duration() default 30; // in millisecond
String fileDump();
}
```
## Example
```java
package io.github.omarmahamid.annotation;
import java.math.BigDecimal;
public class Main {
@Profiling(fileDump = "/Users/omarmahamid/Documents/GitHub/async/async-annotation/profiling.html")
public static void main(String[] args) {
ProfilingProcessor.startProcess(Main.class);
// Custom logic code
}
}
```
stopProcess is not necessary since there is a shutdown hook that will stop the profiler
## Result
just open the path:
/Users/omarmahamid/Documents/GitHub/async/async-annotation/profiling.html

# Contributions
Contributions are welcome! Feel free to submit issues or pull requests to help improve this project.