Skip to content

Commit 7103e13

Browse files
jbachorikclaude
andcommitted
Fix PID capture to get actual Java process, not wrapper
Use pgrep to find the actual Java child process instead of using the bash wrapper PID. This ensures perf attaches to the correct process. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0efeb58 commit 7103e13

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

ddprof-lib/benchmarks/branch-prediction/test_branch_prediction_perf.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,24 @@ start_benchmark() {
100100
-r 100; done" \
101101
&> /tmp/renaissance_${benchmark}.log &
102102

103-
JAVA_PID=$!
104-
echo ${JAVA_PID} > /tmp/java_perf_test.pid
103+
local WRAPPER_PID=$!
104+
echo ${WRAPPER_PID} > /tmp/java_perf_test_wrapper.pid
105105

106-
log_info "Java process started with PID: ${JAVA_PID}"
106+
log_info "Benchmark wrapper started with PID: ${WRAPPER_PID}"
107107

108-
# Verify process started successfully
109-
sleep 2
110-
if ! kill -0 ${JAVA_PID} 2>/dev/null; then
111-
log_error "Java process ${JAVA_PID} died immediately. Check /tmp/renaissance_${benchmark}.log"
108+
# Wait for Java process to actually start and get its PID
109+
sleep 3
110+
JAVA_PID=$(pgrep -P ${WRAPPER_PID} java)
111+
112+
if [ -z "${JAVA_PID}" ]; then
113+
log_error "Could not find Java process. Check /tmp/renaissance_${benchmark}.log"
114+
kill ${WRAPPER_PID} 2>/dev/null || true
112115
exit 1
113116
fi
114117

118+
echo ${JAVA_PID} > /tmp/java_perf_test.pid
119+
log_info "Java process PID: ${JAVA_PID}"
120+
115121
log_info "Warming up for ${WARMUP} seconds..."
116122
sleep ${WARMUP}
117123

@@ -179,11 +185,22 @@ run_perf_record() {
179185

180186
# Stop the benchmark
181187
stop_benchmark() {
188+
# Kill wrapper process which will kill Java too
189+
if [ -f /tmp/java_perf_test_wrapper.pid ]; then
190+
local wrapper_pid=$(cat /tmp/java_perf_test_wrapper.pid)
191+
log_info "Stopping benchmark wrapper ${wrapper_pid}..."
192+
kill ${wrapper_pid} 2>/dev/null || true
193+
sleep 2
194+
kill -9 ${wrapper_pid} 2>/dev/null || true
195+
rm -f /tmp/java_perf_test_wrapper.pid
196+
fi
197+
198+
# Also kill Java process directly
182199
if [ -f /tmp/java_perf_test.pid ]; then
183200
local pid=$(cat /tmp/java_perf_test.pid)
184201
log_info "Stopping Java process ${pid}..."
185202
kill ${pid} 2>/dev/null || true
186-
sleep 2
203+
sleep 1
187204
kill -9 ${pid} 2>/dev/null || true
188205
rm -f /tmp/java_perf_test.pid
189206
fi

0 commit comments

Comments
 (0)