Skip to content

Commit 7b9529a

Browse files
jbachorikclaude
andcommitted
feat(profiling): Add convenience script for JFR to OTLP conversion
Added convert-jfr.sh script that provides a simplified interface for converting JFR files to OTLP format without needing to remember Gradle task paths. Features: - Automatic compilation if needed - Simplified command-line interface - Colored output for better visibility - File size reporting - Comprehensive help message - Error handling with clear messages Usage: ./convert-jfr.sh recording.jfr output.pb ./convert-jfr.sh --json recording.jfr output.json ./convert-jfr.sh --pretty recording.jfr output.json ./convert-jfr.sh file1.jfr file2.jfr merged.pb Updated CLI.md documentation with: - Quick start section featuring the convenience script - Complete usage examples - Feature list and when to use the script vs Gradle directly The script wraps the existing Gradle convertJfr task, providing a more user-friendly interface for development and testing workflows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a5197b9 commit 7b9529a

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
3+
# JFR to OTLP Converter Script
4+
#
5+
# This script provides a convenient wrapper around the Gradle-based JFR converter.
6+
# It automatically handles the classpath and provides a simpler interface.
7+
#
8+
# Usage:
9+
# ./convert-jfr.sh [options] <input.jfr> [input2.jfr ...] <output.pb|output.json>
10+
#
11+
# Options:
12+
# --json Output in JSON format instead of protobuf
13+
# --pretty Pretty-print JSON output (implies --json)
14+
# --include-payload Include original JFR payload in OTLP output
15+
# --help Show this help message
16+
#
17+
# Examples:
18+
# ./convert-jfr.sh recording.jfr output.pb
19+
# ./convert-jfr.sh --json recording.jfr output.json
20+
# ./convert-jfr.sh --pretty recording.jfr output.json
21+
# ./convert-jfr.sh file1.jfr file2.jfr combined.pb
22+
23+
set -e
24+
25+
# Script directory and project root
26+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
27+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
28+
29+
# Colors
30+
RED='\033[0;31m'
31+
GREEN='\033[0;32m'
32+
BLUE='\033[0;34m'
33+
NC='\033[0m'
34+
35+
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
36+
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
37+
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
38+
39+
show_help() {
40+
cat << EOF
41+
JFR to OTLP Converter
42+
43+
Usage:
44+
$(basename "$0") [options] <input.jfr> [input2.jfr ...] <output.pb|output.json>
45+
46+
Options:
47+
--json Output in JSON format instead of protobuf
48+
--pretty Pretty-print JSON output (implies --json)
49+
--include-payload Include original JFR payload in OTLP output
50+
--help Show this help message
51+
52+
Examples:
53+
# Convert to protobuf (default)
54+
$(basename "$0") recording.jfr output.pb
55+
56+
# Convert to JSON
57+
$(basename "$0") --json recording.jfr output.json
58+
59+
# Convert to pretty JSON
60+
$(basename "$0") --pretty recording.jfr output.json
61+
62+
# Include original JFR in output
63+
$(basename "$0") --include-payload recording.jfr output.pb
64+
65+
# Combine multiple JFR files
66+
$(basename "$0") file1.jfr file2.jfr combined.pb
67+
68+
Notes:
69+
- Uses Gradle's convertJfr task under the hood
70+
- Automatically compiles if needed
71+
- Output format is detected from extension (.pb or .json)
72+
73+
EOF
74+
}
75+
76+
# Parse arguments
77+
if [ $# -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
78+
show_help
79+
exit 0
80+
fi
81+
82+
# Convert all arguments to a space-separated string for Gradle --args
83+
ARGS="$*"
84+
85+
log_info "Converting JFR to OTLP format..."
86+
log_info "Arguments: $ARGS"
87+
88+
cd "$PROJECT_ROOT"
89+
90+
# Run Gradle task with arguments
91+
if ./gradlew -q :dd-java-agent:agent-profiling:profiling-otel:convertJfr --args="$ARGS"; then
92+
# Extract output file (last argument)
93+
OUTPUT_FILE="${!#}"
94+
95+
log_success "Conversion completed successfully!"
96+
97+
if [ -f "$OUTPUT_FILE" ]; then
98+
SIZE=$(du -h "$OUTPUT_FILE" | cut -f1)
99+
log_info "Output file: $OUTPUT_FILE ($SIZE)"
100+
fi
101+
else
102+
EXIT_CODE=$?
103+
log_error "Conversion failed with exit code $EXIT_CODE"
104+
exit $EXIT_CODE
105+
fi

dd-java-agent/agent-profiling/profiling-otel/doc/CLI.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Command-line tool for converting JFR recordings to OTLP profiles format for test
44

55
## Quick Start
66

7+
### Using the Convenience Script
8+
9+
The simplest way to convert JFR files:
10+
11+
```bash
12+
cd dd-java-agent/agent-profiling/profiling-otel
13+
./convert-jfr.sh recording.jfr output.pb
14+
```
15+
16+
The script automatically handles compilation and classpath. See [Convenience Script](#convenience-script) section below.
17+
18+
### Using Gradle Directly
19+
720
Convert a JFR file to OTLP protobuf format:
821

922
```bash
@@ -295,6 +308,85 @@ See [PROFCHECK_INTEGRATION.md](PROFCHECK_INTEGRATION.md) for:
295308
- Integration with CI/CD
296309
- Validation coverage details
297310

311+
## Convenience Script
312+
313+
The `convert-jfr.sh` script provides a simpler interface that wraps the Gradle task:
314+
315+
### Location
316+
317+
```bash
318+
dd-java-agent/agent-profiling/profiling-otel/convert-jfr.sh
319+
```
320+
321+
### Usage
322+
323+
```bash
324+
./convert-jfr.sh [options] <input.jfr> [input2.jfr ...] <output.pb|output.json>
325+
```
326+
327+
### Options
328+
329+
- `--json` - Output in JSON format instead of protobuf
330+
- `--pretty` - Pretty-print JSON output (implies --json)
331+
- `--include-payload` - Include original JFR payload in OTLP output
332+
- `--help` - Show help message
333+
334+
### Examples
335+
336+
Basic conversion:
337+
```bash
338+
./convert-jfr.sh recording.jfr output.pb
339+
```
340+
341+
Convert to JSON:
342+
```bash
343+
./convert-jfr.sh --json recording.jfr output.json
344+
```
345+
346+
Convert to pretty-printed JSON:
347+
```bash
348+
./convert-jfr.sh --pretty recording.jfr output.json
349+
```
350+
351+
Include original JFR payload:
352+
```bash
353+
./convert-jfr.sh --include-payload recording.jfr output.pb
354+
```
355+
356+
Combine multiple files:
357+
```bash
358+
./convert-jfr.sh file1.jfr file2.jfr file3.jfr merged.pb
359+
```
360+
361+
### Features
362+
363+
- **Automatic compilation**: Compiles code if needed before conversion
364+
- **Simplified interface**: No need to remember Gradle task paths
365+
- **Colored output**: Visual feedback for success/errors
366+
- **File size reporting**: Shows output file size after conversion
367+
- **Error handling**: Clear error messages if conversion fails
368+
369+
### Script Output
370+
371+
```
372+
[INFO] Converting JFR to OTLP format...
373+
[INFO] Arguments: recording.jfr output.pb
374+
[SUCCESS] Conversion completed successfully!
375+
[INFO] Output file: output.pb (45K)
376+
```
377+
378+
### When to Use
379+
380+
- **Quick conversions**: When you want the simplest interface
381+
- **Development workflow**: Rapid iteration during development
382+
- **Testing**: Quick validation of JFR files
383+
- **Scripting**: Easy to use in shell scripts
384+
385+
Use the Gradle task directly when you need:
386+
- Integration with build system
387+
- Custom Gradle configuration
388+
- CI/CD pipeline integration
389+
298390
## See Also
299391

300392
- [ARCHITECTURE.md](ARCHITECTURE.md) - Converter design and implementation details

0 commit comments

Comments
 (0)