Skip to content

Commit d7b833c

Browse files
authored
Profiling support for spring-boot or quarkus (#103)
* Improved cursor rule for profiling with support for spring-boot or quarkus * Updating pipeline
1 parent e6d0e9e commit d7b833c

File tree

27 files changed

+2608
-133
lines changed

27 files changed

+2608
-133
lines changed

.cursor/rules/161-java-profiling-detect.mdc

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,22 @@ The rule ensures consistent, repeatable profiling procedures while providing the
2727

2828
## ⚠️ CRITICAL INSTRUCTION FOR AI ASSISTANTS ⚠️
2929

30-
**WHEN USING THE PROFILING SCRIPT TEMPLATE:**
31-
- **COPY THE BASH SCRIPT EXACTLY** from `java-profiling-script-template.md`
30+
**WHEN USING THE PROFILING SCRIPT TEMPLATES:**
31+
- **COPY THE BASH SCRIPT EXACTLY** from `java-profiling-script-template.md` or `java-profiling-script-run-app-template.md`
3232
- **NO MODIFICATIONS, INTERPRETATIONS, OR ENHANCEMENTS** allowed
3333
- **USE EVERY LINE VERBATIM** - do not change logic, structure, or features
3434
- **DO NOT CREATE YOUR OWN VERSION** - use the provided template only
35-
- The template script is complete, tested, and production-ready
35+
- The template scripts are complete, tested, and production-ready
3636

3737
---
3838

3939
This rule provides comprehensive Java application profiling using async-profiler v4.0, including automatic OS detection, profiler download, and flamegraph generation with the latest features.
4040

41-
## Problem Identification
42-
43-
Before starting the profiling process, identify what specific performance problem you're trying to solve.
44-
45-
**Reference the profiling questions template:** [java-profiling-questions-template.md](mdc:.cursor/rules/templates/java-profiling-questions-template.md)
46-
47-
The template categorizes problems into:
48-
- **Performance Bottlenecks** (CPU hotspots, inefficient algorithms, unnecessary allocations, string operations)
49-
- **Memory-Related Problems** (memory leaks, heap usage, object retention, off-heap issues)
50-
- **Concurrency and Threading Issues** (lock contention, thread pool issues, deadlocks, context switching)
51-
- **Garbage Collection Problems** (GC pressure, long pauses, generational issues)
52-
- **I/O and Network Bottlenecks** (blocking operations, connection leaks, serialization issues)
53-
5441
## Overview
5542

5643
Java profiling helps identify performance bottlenecks, memory leaks, and CPU hotspots in Java applications. This rule automates the process of:
5744
1. **Problem Identification**: Determine what specific performance issue you're investigating
58-
2. **Process Detection**: Detecting running Java processes using `jps`
45+
2. **Application Setup**: Configure your application to run with profiling-friendly JVM flags
5946
3. **Environment Setup**: Identifying the operating system and architecture
6047
4. **Tool Download**: Downloading the appropriate async-profiler v4.0 binary
6148
5. **Profile Execution**: Attaching to a Java process and generating flamegraphs and heatmaps
@@ -84,20 +71,58 @@ The profiling setup uses a clean folder structure with everything contained in t
8471

8572
```
8673
your-project/
74+
├── run-with-profiler.sh # ← Step 1: Run main application with profiling JVM flags
8775
└── profiler/ # ← All profiling-related files
8876
├── scripts/ # ← Profiling scripts and tools
89-
│ └── java-profile.sh # ← Main profiling script
77+
│ └── java-profile.sh # ← Step 2: Interactive profiling script
9078
├── results/ # ← Generated profiling output
9179
│ ├── *.html # ← Flamegraph files
9280
│ └── *.jfr # ← JFR recording files
9381
├── current/ # ← Symlink to current profiler version
9482
└── async-profiler-*/ # ← Downloaded profiler binaries
9583
```
9684

85+
## Step-by-Step Profiling Workflow
86+
87+
Follow this workflow in order to set up profiling for your Java application:
88+
89+
### Step 1: Setup Application Runner Script (`run-with-profiler.sh`)
90+
91+
**IMPORTANT**: Use the exact bash script from the template without any modification or interpretation.
92+
93+
The application runner script is available at: [java-profiling-script-run-app-template.md](mdc:.cursor/rules/templates/java-profiling-script-run-app-template.md)
94+
95+
**CRITICAL INSTRUCTION FOR AI ASSISTANTS:**
96+
- **COPY THE BASH SCRIPT EXACTLY** from the template file
97+
- **DO NOT MODIFY, INTERPRET, OR ENHANCE** the script content
98+
- **DO NOT ADD NEW FEATURES** or change the logic
99+
- **USE THE SCRIPT VERBATIM** - every line, comment, and function exactly as provided
100+
- The script is already complete and tested - no improvements needed
101+
102+
**Script Location:**
103+
```
104+
your-project/
105+
└── run-with-profiler.sh # ← Run main application with the right JVM flags for profiling
106+
```
107+
108+
**Setup Instructions:**
109+
1. Copy the **EXACT** bash script content from `java-profiling-script-run-app-template.md`
110+
2. Save it as `run-with-profiler.sh` in your project root
111+
3. Make it executable: `chmod +x run-with-profiler.sh`
112+
4. **NO MODIFICATIONS** to the script content are needed or allowed
113+
114+
**Purpose:**
115+
- Configures JVM with profiling-friendly flags
116+
- Ensures proper async-profiler compatibility
117+
- Starts your application ready for profiling
118+
97119
**Usage:**
98-
- Run `./profiler/scripts/java-profile.sh` for comprehensive interactive profiling
120+
```bash
121+
# Start your application with profiling-ready JVM settings
122+
./run-with-profiler.sh
123+
```
99124

100-
## Automated Profiling Script
125+
### Step 2: Setup Interactive Profiling Script (`java-profile.sh`)
101126

102127
**IMPORTANT**: Use the exact bash script from the template without any modification or interpretation.
103128

@@ -118,37 +143,39 @@ The complete interactive profiling script is available at: [java-profiling-scrip
118143
```
119144

120145
**Setup Instructions:**
121-
1. Copy the **EXACT** bash script content from `java-profiling-script-template.md`
122-
2. Save it as `profiler/scripts/java-profile.sh`
123-
3. Make it executable: `chmod +x profiler/scripts/java-profile.sh`
124-
4. **NO MODIFICATIONS** to the script content are needed or allowed
146+
1. Create the profiler directory structure: `mkdir -p profiler/scripts profiler/results`
147+
2. Copy the **EXACT** bash script content from `java-profiling-script-template.md`
148+
3. Save it as `profiler/scripts/java-profile.sh`
149+
4. Make it executable: `chmod +x profiler/scripts/java-profile.sh`
150+
5. **NO MODIFICATIONS** to the script content are needed or allowed
151+
152+
**Purpose:**
153+
- Detects running Java processes automatically
154+
- Downloads and configures async-profiler v4.0
155+
- Provides interactive menu for different profiling scenarios
156+
- Generates flamegraphs and analysis reports
125157

126158
## Profiling Execution Workflow
127159

128-
After setting up the profiling scripts, follow this execution workflow to profile your Java application and store results in the profiler/results directory:
160+
After setting up both scripts, follow this execution workflow:
129161

130-
### Step 1: Create and Make Script Executable
162+
### Step 1: Start Your Application with Profiling Support
131163

132-
**CRITICAL**: Use the exact script from the template without any changes:
164+
First, start your application using the profiling-ready runner:
133165

134166
```bash
135-
# Create the profiler directory structure
136-
mkdir -p profiler/scripts
137-
mkdir -p profiler/results
138-
139-
# Copy the EXACT bash script from java-profiling-script-template.md
140-
# Save it as profiler/scripts/java-profile.sh
141-
# DO NOT MODIFY THE SCRIPT CONTENT - USE IT EXACTLY AS PROVIDED
142-
143-
# Make the script executable
144-
chmod +x profiler/scripts/java-profile.sh
167+
# Start your application with JVM flags optimized for profiling
168+
./run-with-profiler.sh
145169
```
146170

147-
**REMINDER**: The script in `java-profiling-script-template.md` is complete and should be copied verbatim. No interpretation, enhancement, or modification is required or allowed.
171+
This script:
172+
- Applies JVM flags that make profiling more accurate
173+
- Ensures async-profiler can attach properly
174+
- Starts your application in profiling-ready mode
148175

149-
### Step 2: Execute the Profiling Script
176+
### Step 2: Run Interactive Profiling
150177

151-
Run the script from your project root directory:
178+
In a separate terminal, execute the interactive profiling script:
152179

153180
```bash
154181
# Execute the interactive profiling script
@@ -164,7 +191,7 @@ Run the script from your project root directory:
164191

165192
### Step 3: Problem-Specific Profiling Commands
166193

167-
Based on the problem you identified, execute these specific profiling commands:
194+
Based on the problem you identified, the script will execute these specific profiling commands:
168195

169196
#### For CPU Hotspots and Performance Bottlenecks
170197
```bash

.cursor/rules/templates/java-profiling-questions-template.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)