Skip to content

Commit da3cc54

Browse files
committed
Tools: Fix time tracking for compiling Tools on older macOS
1 parent 0051b6d commit da3cc54

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Tools/Tools.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,24 @@ execute_tool () {
4242

4343
OS=$(uname -s)
4444

45+
# Cross-platform time measurement function
46+
get_time_ms() {
47+
if [[ "$OS" == "Darwin" ]]; then
48+
# macOS doesn't support %N, use Perl (pre-installed) for millisecond precision
49+
perl -MTime::HiRes=time -e 'printf "%.0f\n", time * 1000'
50+
else
51+
# Linux supports nanoseconds
52+
echo $(($(date +%s%N) / 1000000))
53+
fi
54+
}
55+
4556
# Time the initial build
46-
start_time=$(date +%s%N)
57+
start_time=$(get_time_ms)
4758
call_make build
4859
initial_exit_code=$?
49-
end_time=$(date +%s%N)
50-
build_time=$(( (end_time - start_time) / 1000000000 ))
51-
build_time_frac=$(( (end_time - start_time) % 1000000000 / 1000000 ))
60+
end_time=$(get_time_ms)
61+
build_time=$(( (end_time - start_time) / 1000 ))
62+
build_time_frac=$(( (end_time - start_time) % 1000 ))
5263
printf "Time to compile \"${TOOL_NAME}\" tool: %d.%03d seconds\n" $build_time $build_time_frac
5364

5465
if [ $initial_exit_code -eq 0 ]; then
@@ -57,12 +68,12 @@ else
5768
# It could have failed because of moved files, let's re-try after cleaning
5869
call_make clean
5970
# Time the clean and rebuild
60-
start_time=$(date +%s%N)
71+
start_time=$(get_time_ms)
6172
call_make build
6273
rebuild_exit_code=$?
63-
end_time=$(date +%s%N)
64-
rebuild_time=$(( (end_time - start_time) / 1000000000 ))
65-
rebuild_time_frac=$(( (end_time - start_time) % 1000000000 / 1000000 ))
74+
end_time=$(get_time_ms)
75+
rebuild_time=$(( (end_time - start_time) / 1000 ))
76+
rebuild_time_frac=$(( (end_time - start_time) % 1000 ))
6677
printf "Time to re-compile \"${TOOL_NAME}\" tool after clean: %d.%03d seconds\n" $rebuild_time $rebuild_time_frac
6778
if [ $rebuild_exit_code -eq 0 ]; then
6879
execute_tool "$@"

0 commit comments

Comments
 (0)