|
| 1 | +#!/bin/bash |
| 2 | +# ================================================ |
| 3 | +# 🌱 Sprout JIT Profiling with Gatling |
| 4 | +# ----------------------------------------------- |
| 5 | +# 1. IntelliJ에서 서버 실행 (JFR + JIT 로그) |
| 6 | +# 2. Gatling 부하 테스트 실행 |
| 7 | +# 3. 결과 분석: JFR, Hotspot 로그, Gatling 리포트 |
| 8 | +# ================================================ |
| 9 | + |
| 10 | +OUTPUT_DIR="./jit-profile" |
| 11 | +PORT=8080 |
| 12 | + |
| 13 | +# ================================================ |
| 14 | +# 준비 |
| 15 | +# ================================================ |
| 16 | +mkdir -p "$OUTPUT_DIR" |
| 17 | + |
| 18 | +echo "════════════════════════════════════════════════════════════════" |
| 19 | +echo " 🌱 Sprout JIT Profiling with Gatling" |
| 20 | +echo "════════════════════════════════════════════════════════════════" |
| 21 | +echo "" |
| 22 | + |
| 23 | +# ================================================ |
| 24 | +# 서버 구동 확인 |
| 25 | +# ================================================ |
| 26 | +echo "[1/3] Checking if Sprout server is running..." |
| 27 | +if ! curl -s "http://localhost:$PORT/benchmark/hello" > /dev/null 2>&1; then |
| 28 | + echo "" |
| 29 | + echo "Server is NOT running on port $PORT" |
| 30 | + echo "" |
| 31 | + echo "Start the server from IntelliJ with these VM options:" |
| 32 | + echo "────────────────────────────────────────────────────────────────" |
| 33 | + cat << 'VMEOF' |
| 34 | +--add-opens=java.base/java.lang=ALL-UNNAMED |
| 35 | +--add-opens=java.base/java.lang.reflect=ALL-UNNAMED |
| 36 | +--add-opens=java.base/java.io=ALL-UNNAMED |
| 37 | +--add-opens=java.base/java.util=ALL-UNNAMED |
| 38 | +-XX:StartFlightRecording=filename=jit-profile/recording.jfr,duration=300s,settings=profile |
| 39 | +-XX:+UnlockDiagnosticVMOptions |
| 40 | +-XX:+LogCompilation |
| 41 | +-XX:LogFile=jit-profile/hotspot_%p.log |
| 42 | +-XX:+PrintInlining |
| 43 | +-XX:+PrintCompilation |
| 44 | +-XX:+PrintCodeCache |
| 45 | +-XX:+PrintAssembly |
| 46 | +-XX:PrintAssemblyOptions=intel |
| 47 | +-XX:CompileCommand=print,*benchmark* |
| 48 | +-XX:+DebugNonSafepoints |
| 49 | +VMEOF |
| 50 | + echo "────────────────────────────────────────────────────────────────" |
| 51 | + echo "" |
| 52 | + echo "Note: -XX:+PrintAssembly requires hsdis library" |
| 53 | + echo " Download: https://chriswhocodes.com/hsdis/" |
| 54 | + echo " Place at: \$JAVA_HOME/lib/server/" |
| 55 | + echo "" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +echo "✓ Server is running on port $PORT" |
| 60 | +echo "" |
| 61 | + |
| 62 | +# ================================================ |
| 63 | +# Gatling 부하 테스트 |
| 64 | +# ================================================ |
| 65 | +echo "[2/3] Running Gatling Heavy Load test..." |
| 66 | +echo "────────────────────────────────────────────────────────────────" |
| 67 | +echo " Simulation: HeavyLoadSimulation" |
| 68 | +echo " Warm-up: ~20,000 requests" |
| 69 | +echo " Load test: ~80,000 requests" |
| 70 | +echo " Total: ~100,000 requests" |
| 71 | +echo "────────────────────────────────────────────────────────────────" |
| 72 | +echo "" |
| 73 | + |
| 74 | +# Gatling 실행 |
| 75 | +./gradlew gatlingRun --simulation=benchmark.HeavyLoadSimulation |
| 76 | + |
| 77 | +GATLING_EXIT_CODE=$? |
| 78 | + |
| 79 | +if [ $GATLING_EXIT_CODE -ne 0 ]; then |
| 80 | + echo "" |
| 81 | + echo "Gatling test failed with exit code: $GATLING_EXIT_CODE" |
| 82 | + exit $GATLING_EXIT_CODE |
| 83 | +fi |
| 84 | + |
| 85 | +echo "" |
| 86 | +echo "✓ Gatling test completed" |
| 87 | +echo "" |
| 88 | + |
| 89 | +# ================================================ |
| 90 | +# 결과 정리 |
| 91 | +# ================================================ |
| 92 | +echo "[3/3] Collecting profiling results..." |
| 93 | +echo "" |
| 94 | + |
| 95 | +# Gatling 리포트 경로 찾기 |
| 96 | +LATEST_GATLING_REPORT=$(find build/reports/gatling -type d -name "*HeavyLoadSimulation*" 2>/dev/null | sort -r | head -n 1) |
| 97 | + |
| 98 | +echo "════════════════════════════════════════════════════════════════" |
| 99 | +echo " Profiling Complete!" |
| 100 | +echo "════════════════════════════════════════════════════════════════" |
| 101 | +echo "" |
| 102 | +echo "Profiling Data:" |
| 103 | +echo " • JIT Compilation Log: $OUTPUT_DIR/hotspot_*.log" |
| 104 | +echo " • JFR Recording: $OUTPUT_DIR/recording.jfr" |
| 105 | +echo " • Assembly Output: $OUTPUT_DIR/hotspot_*.log (if hsdis available)" |
| 106 | +echo "" |
| 107 | +echo "Gatling Report:" |
| 108 | +if [ -n "$LATEST_GATLING_REPORT" ]; then |
| 109 | + echo " • HTML Report: $LATEST_GATLING_REPORT/index.html" |
| 110 | + echo "" |
| 111 | + echo " Open report:" |
| 112 | + echo " open $LATEST_GATLING_REPORT/index.html" |
| 113 | +else |
| 114 | + echo " • Check: build/reports/gatling/" |
| 115 | +fi |
| 116 | +echo "" |
| 117 | +echo "Analysis Tools" |
| 118 | +echo " 1. JITWatch: Analyze hotspot_*.log for JIT compilation details" |
| 119 | +echo " 2. JDK Mission Control: Open recording.jfr for performance profiling" |
| 120 | +echo " 3. Gatling: View HTML report for load test metrics" |
| 121 | +echo "" |
| 122 | +echo "════════════════════════════════════════════════════════════════" |
0 commit comments