Skip to content

Commit f3439fc

Browse files
jbachorikclaude
andcommitted
feat(profiling): Add JFR to OTLP conversion convenience script with diagnostics
Added convert-jfr.sh convenience wrapper for JFR to OTLP conversion with comprehensive diagnostic output and cross-platform compatibility. Features: - Simple CLI interface wrapping Gradle convertJfr task - Support for all converter options (--json, --pretty, --include-payload) - --diagnostics flag showing detailed metrics: * Input/output file sizes with human-readable formatting * Actual conversion time (parsed from converter output) * Compression ratios and savings - Colored output for better readability - Cross-platform file size detection (Linux and macOS) - Automatic compilation via Gradle Implementation: - Parses converter's own timing output to show actual conversion time (e.g., 141ms) instead of total Gradle execution time (13+ seconds) - Uses try-fallback approach for stat command (GNU stat → BSD stat) - Works on Linux, macOS with GNU coreutils, and native macOS Documentation: - Added "Convenience Script" section to doc/CLI.md - Usage examples and feature list - Diagnostic output examples Example: ./convert-jfr.sh --diagnostics recording.jfr output.pb Shows: 141ms conversion time, 2.0MB → 2.2KB (99.9% reduction) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1b30ff2 commit f3439fc

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

dd-java-agent/agent-profiling/profiling-otel/convert-jfr.sh

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ get_file_size() {
5555
get_file_size_bytes() {
5656
local file="$1"
5757
if [ -f "$file" ]; then
58-
# Cross-platform file size in bytes
59-
if [[ "$OSTYPE" == "darwin"* ]]; then
60-
stat -f%z "$file"
58+
# Try GNU stat first (Linux, or GNU coreutils on macOS)
59+
local size=$(stat -c %s "$file" 2>/dev/null)
60+
if [ -n "$size" ] && [ "$size" != "" ]; then
61+
echo "$size"
6162
else
62-
stat -c%s "$file"
63+
# Fall back to BSD stat (macOS native)
64+
stat -f %z "$file" 2>/dev/null || echo "0"
6365
fi
6466
else
6567
echo "0"
@@ -188,19 +190,17 @@ log_info "Converting JFR to OTLP format..."
188190

189191
cd "$PROJECT_ROOT"
190192

191-
# Measure conversion time
192-
START_TIME=$(date +%s%N)
193-
START_CPU=$(ps -o cputime= -p $$ | tr -d ' :')
194-
195-
# Run Gradle task with arguments
196-
if ./gradlew -q :dd-java-agent:agent-profiling:profiling-otel:convertJfr --args="$ARGS"; then
197-
# Measure end time
198-
END_TIME=$(date +%s%N)
199-
END_CPU=$(ps -o cputime= -p $$ | tr -d ' :')
193+
# Run Gradle task with arguments and capture output
194+
GRADLE_OUTPUT=$(./gradlew -q :dd-java-agent:agent-profiling:profiling-otel:convertJfr --args="$ARGS" 2>&1)
195+
GRADLE_EXIT=$?
200196

197+
if [ $GRADLE_EXIT -eq 0 ]; then
201198
# Extract output file (last argument)
202199
OUTPUT_FILE="${CONVERTER_ARGS[-1]}"
203200

201+
# Print gradle output
202+
echo "$GRADLE_OUTPUT"
203+
204204
log_success "Conversion completed successfully!"
205205

206206
if [ -f "$OUTPUT_FILE" ]; then
@@ -212,10 +212,11 @@ if ./gradlew -q :dd-java-agent:agent-profiling:profiling-otel:convertJfr --args=
212212
echo ""
213213
log_diagnostic "=== Conversion Diagnostics ==="
214214

215-
# Calculate wall time
216-
WALL_TIME_NS=$((END_TIME - START_TIME))
217-
WALL_TIME_MS=$(awk "BEGIN {printf \"%.1f\", $WALL_TIME_NS/1000000}")
218-
log_diagnostic "Wall time: ${WALL_TIME_MS}ms"
215+
# Extract conversion time from converter output (looks for "Time: XXX ms")
216+
CONVERSION_TIME=$(echo "$GRADLE_OUTPUT" | grep -o 'Time: [0-9]* ms' | grep -o '[0-9]*' | head -1)
217+
if [ -n "$CONVERSION_TIME" ] && [ "$CONVERSION_TIME" != "" ]; then
218+
log_diagnostic "Conversion time: ${CONVERSION_TIME}ms"
219+
fi
219220

220221
# Show size comparison
221222
if [ ${#INPUT_FILES[@]} -gt 0 ]; then
@@ -234,7 +235,7 @@ if ./gradlew -q :dd-java-agent:agent-profiling:profiling-otel:convertJfr --args=
234235
fi
235236
fi
236237
else
237-
EXIT_CODE=$?
238-
log_error "Conversion failed with exit code $EXIT_CODE"
239-
exit $EXIT_CODE
238+
echo "$GRADLE_OUTPUT"
239+
log_error "Conversion failed with exit code $GRADLE_EXIT"
240+
exit $GRADLE_EXIT
240241
fi

0 commit comments

Comments
 (0)