@@ -60,6 +60,10 @@ ENABLE_PIDSTAT="${ENABLE_PIDSTAT:-false}"
6060PIDSTAT_INTERVAL=" ${PIDSTAT_INTERVAL:- 1} "
6161PIDSTAT_OUTPUT=" ${PIDSTAT_OUTPUT:- pidstat.log} "
6262
63+ # perf stat configuration
64+ ENABLE_PERF_STAT=" ${ENABLE_PERF_STAT:- false} "
65+ PERF_STAT_OUTPUT=" ${PERF_STAT_OUTPUT:- perf-stat.txt} "
66+
6367# Output directory
6468OUTPUT_DIR=" ${OUTPUT_DIR:- ./ benchmark-results} "
6569
@@ -184,6 +188,12 @@ cleanup() {
184188 kill " $PIDSTAT_PID " 2> /dev/null || true
185189 fi
186190
191+ # Kill perf stat (should already be done, but clean up just in case)
192+ if [[ -n " ${PERF_STAT_PID:- } " ]]; then
193+ log " Stopping perf stat (PID: $PERF_STAT_PID )"
194+ kill " $PERF_STAT_PID " 2> /dev/null || true
195+ fi
196+
187197 log " Cleanup complete"
188198}
189199
@@ -379,6 +389,30 @@ stop_pidstat() {
379389 fi
380390}
381391
392+ # ============================================================================
393+ # Start perf stat
394+ # ============================================================================
395+
396+ start_perf_stat () {
397+ if [[ " $ENABLE_PERF_STAT " != " true" ]]; then
398+ return
399+ fi
400+
401+ log " Starting perf stat for handoff server (PID: $SERVER_PID )..."
402+
403+ local warmup_secs=$( parse_duration_to_seconds " $WARMUP_DURATION " )
404+ local total_secs=$( parse_duration_to_seconds " $TOTAL_DURATION " )
405+ local profiling_secs=$(( total_secs - warmup_secs))
406+ local output_file=" $OUTPUT_DIR /$PERF_STAT_OUTPUT "
407+
408+ perf stat -p " $SERVER_PID " -o " $output_file " sleep " $profiling_secs " &
409+ PERF_STAT_PID=$!
410+
411+ log " perf stat running (PID: $PERF_STAT_PID ) for ${profiling_secs} s"
412+ }
413+
414+ # Note: perf stat stops automatically after the sleep duration, no explicit stop needed
415+
382416# ============================================================================
383417# Run Load Test
384418# ============================================================================
@@ -468,6 +502,12 @@ print_config() {
468502 log " Output: $PIDSTAT_OUTPUT "
469503 fi
470504 log " "
505+ log " perf stat:"
506+ log " Enabled: $ENABLE_PERF_STAT "
507+ if [[ " $ENABLE_PERF_STAT " == " true" ]]; then
508+ log " Output: $PERF_STAT_OUTPUT "
509+ fi
510+ log " "
471511 log " Output Directory: $OUTPUT_DIR "
472512 log " =============================================="
473513}
@@ -526,6 +566,10 @@ pidstat:
526566 PIDSTAT_INTERVAL Collection interval in seconds (default: 1)
527567 PIDSTAT_OUTPUT Output file (default: pidstat.log)
528568
569+ perf stat:
570+ ENABLE_PERF_STAT Enable perf stat collection (default: false)
571+ PERF_STAT_OUTPUT Output file (default: perf-stat.txt)
572+
529573General:
530574 JAVA_HOME Path to Java installation (required)
531575 OUTPUT_DIR Output directory (default: ./benchmark-results)
586630 # Start monitoring after warmup
587631 start_profiler
588632 start_pidstat
633+ start_perf_stat
589634
590635 # Run actual load test
591636 run_load_test
0 commit comments