66
77SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
88REPO_ROOT=" ${SCRIPT_DIR} /../../.."
9- TEST_SCRIPT=" ${SCRIPT_DIR} /test_branch_prediction_perf.sh"
109
1110# Color output
1211GREEN=' \033[0;32m'
1312YELLOW=' \033[1;33m'
1413BLUE=' \033[0;34m'
14+ RED=' \033[0;31m'
1515NC=' \033[0m'
1616
1717log_info () {
@@ -26,6 +26,26 @@ log_warn() {
2626 echo -e " ${YELLOW} [WARN]${NC} $1 "
2727}
2828
29+ log_error () {
30+ echo -e " ${RED} [ERROR]${NC} $1 "
31+ }
32+
33+ # Cleanup worktrees on exit
34+ cleanup () {
35+ log_info " Cleaning up worktrees..."
36+ cd " ${REPO_ROOT} "
37+
38+ if [ -n " ${BASELINE_WORKTREE} " ] && [ -d " ${BASELINE_WORKTREE} " ]; then
39+ git worktree remove -f " ${BASELINE_WORKTREE} " 2> /dev/null || true
40+ fi
41+
42+ if [ -n " ${OPTIMIZED_WORKTREE} " ] && [ -d " ${OPTIMIZED_WORKTREE} " ]; then
43+ git worktree remove -f " ${OPTIMIZED_WORKTREE} " 2> /dev/null || true
44+ fi
45+ }
46+
47+ trap cleanup EXIT
48+
2949# Compare two perf stat results
3050compare_results () {
3151 local baseline=" $1 "
@@ -86,89 +106,87 @@ compare_results() {
86106
87107main () {
88108 local benchmark=" ${1:- akka-uct} "
109+ local baseline_branch=" ${2:- main} "
110+ local optimized_branch=" ${3:- jb/ likely} "
89111
90112 log_info " === Branch Prediction Comparison Test ==="
91- log_info " This will test baseline (main) vs optimized (jb/likely) branches"
113+ log_info " Baseline branch: ${baseline_branch} "
114+ log_info " Optimized branch: ${optimized_branch} "
92115 log_info " Benchmark: ${benchmark} "
93116 echo " "
94117
95- if [ ! -f " ${TEST_SCRIPT} " ]; then
96- log_warn " Test script not found at ${TEST_SCRIPT} "
97- exit 1
98- fi
118+ cd " ${REPO_ROOT} "
99119
100- # Current branch (should be jb/likely)
101- local current_branch=$( git branch --show-current)
102- log_info " Current branch: ${current_branch} "
103-
104- if [ " ${current_branch} " != " jb/likely" ]; then
105- log_warn " You are not on jb/likely branch. Switch to it first?"
106- read -p " Continue anyway? (y/N) " -n 1 -r
107- echo
108- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
109- exit 1
110- fi
111- fi
120+ # Create worktrees for both branches
121+ BASELINE_WORKTREE=" ${REPO_ROOT} /../java-profiler-baseline-$$ "
122+ OPTIMIZED_WORKTREE=" ${REPO_ROOT} /../java-profiler-optimized-$$ "
112123
113- # Save test script since it won't exist on main branch
114- local temp_test_script=" /tmp/test_branch_prediction_perf_$$ .sh"
115- cp " ${TEST_SCRIPT} " " ${temp_test_script} "
124+ log_step " 1/6: Creating worktree for baseline (${baseline_branch} )..."
125+ git worktree add " ${BASELINE_WORKTREE} " " ${baseline_branch} "
116126
117- # Test optimized version (current branch)
118- log_step " 1/4: Building optimized version (${current_branch} )..."
119- cd " ${REPO_ROOT} "
120- ./gradlew ddprof-lib:build -x test
121- cd - > /dev/null
127+ log_step " 2/6: Creating worktree for optimized (${optimized_branch} )..."
128+ git worktree add " ${OPTIMIZED_WORKTREE} " " ${optimized_branch} "
122129
123- log_step " 2/4: Testing optimized version..."
124- " ${temp_test_script} " " ${benchmark} " " optimized"
130+ # Build baseline
131+ log_step " 3/6: Building baseline version..."
132+ cd " ${BASELINE_WORKTREE} "
133+ ./gradlew ddprof-lib:build -x test
125134
126- # Switch to main and test baseline
127- log_step " 3/4: Switching to main branch and building baseline..."
128- cd " ${REPO_ROOT} "
129- git stash push -m " Temporary stash for perf comparison"
130- git checkout main
135+ # Build optimized
136+ log_step " 4/6: Building optimized version..."
137+ cd " ${OPTIMIZED_WORKTREE} "
131138 ./gradlew ddprof-lib:build -x test
132- cd - > /dev/null
133139
134- log_step " 4/4: Testing baseline version..."
135- " ${temp_test_script} " " ${benchmark} " " baseline"
140+ # Test baseline
141+ log_step " 5/6: Testing baseline version..."
142+ local baseline_test_script=" ${OPTIMIZED_WORKTREE} /ddprof-lib/benchmarks/branch-prediction/test_branch_prediction_perf.sh"
136143
137- # Switch back
138- log_info " Switching back to ${current_branch} ..."
139- cd " ${REPO_ROOT} "
140- git checkout " ${current_branch} "
141- git stash pop || true
142- cd - > /dev/null
144+ if [ ! -f " ${baseline_test_script} " ]; then
145+ log_error " Test script not found at ${baseline_test_script} "
146+ log_error " Benchmark scripts may not exist on ${optimized_branch} branch"
147+ exit 1
148+ fi
149+
150+ # Run tests from optimized worktree but with baseline library
151+ cd " ${OPTIMIZED_WORKTREE} /ddprof-lib/benchmarks/branch-prediction"
152+
153+ # Temporarily override PROFILER_LIB for baseline test
154+ PROFILER_LIB_OVERRIDE=" ${BASELINE_WORKTREE} /ddprof-lib/build/lib/main/release/linux/x64/libjavaProfiler.so" \
155+ " ${baseline_test_script} " " ${benchmark} " " baseline"
143156
144- # Cleanup temp script
145- rm -f " ${temp_test_script} "
157+ # Test optimized
158+ log_step " 6/6: Testing optimized version..."
159+ " ${baseline_test_script} " " ${benchmark} " " optimized"
146160
147161 # Compare results
148162 echo " "
149163 compare_results \
150- " ${SCRIPT_DIR} /perf_results/baseline_stat.txt" \
151- " ${SCRIPT_DIR} /perf_results/optimized_stat.txt"
164+ " ${OPTIMIZED_WORKTREE} /ddprof-lib/benchmarks/branch-prediction /perf_results/baseline_stat.txt" \
165+ " ${OPTIMIZED_WORKTREE} /ddprof-lib/benchmarks/branch-prediction /perf_results/optimized_stat.txt"
152166
153167 log_info " === Comparison Complete ==="
154- log_info " Detailed results in perf_results/ directory "
168+ log_info " Detailed results in ${OPTIMIZED_WORKTREE} /ddprof-lib/benchmarks/branch-prediction/ perf_results/"
155169 log_info " "
156170 log_info " To view detailed perf reports:"
157- log_info " perf report -i perf_results/baseline_record.data --dsos=libjavaProfiler.so"
158- log_info " perf report -i perf_results/optimized_record.data --dsos=libjavaProfiler.so"
171+ log_info " cd ${OPTIMIZED_WORKTREE} /ddprof-lib/benchmarks/branch-prediction/perf_results"
172+ log_info " perf report -i baseline_record.data --dsos=libjavaProfiler.so"
173+ log_info " perf report -i optimized_record.data --dsos=libjavaProfiler.so"
159174}
160175
161176if [ " $1 " = " -h" ] || [ " $1 " = " --help" ]; then
162- echo " Usage: $0 [benchmark]"
177+ echo " Usage: $0 [benchmark] [baseline_branch] [optimized_branch] "
163178 echo " "
164- echo " Compares branch prediction performance between main and jb/likely branches "
179+ echo " Compares branch prediction performance between two branches using git worktrees "
165180 echo " "
166181 echo " Arguments:"
167- echo " benchmark Renaissance benchmark to use (default: akka-uct)"
182+ echo " benchmark Renaissance benchmark to use (default: akka-uct)"
183+ echo " baseline_branch Baseline branch (default: main)"
184+ echo " optimized_branch Optimized branch (default: jb/likely)"
168185 echo " "
169186 echo " Examples:"
170- echo " $0 # Compare using akka-uct"
171- echo " $0 finagle-chirper # Compare using finagle-chirper"
187+ echo " $0 # Compare main vs jb/likely using akka-uct"
188+ echo " $0 finagle-chirper # Compare using finagle-chirper"
189+ echo " $0 akka-uct main jb/likely # Explicit branch names"
172190 exit 0
173191fi
174192
0 commit comments