Skip to content

Commit

Permalink
Merge branch 'main' into storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
iva2k committed Jul 19, 2024
2 parents 4b1473f + e52ffcf commit ab3bcdf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
27 changes: 15 additions & 12 deletions scripts/git-merge_main-to-all-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ git config user.name "IVA2K"
DEBUG=0
# DEBUG=1

[ -z "$EPOCHREALTIME" ] && { echo "$0 needs bash>5.0(2019-01) for EPOCHREALTIME"; exit 1; }

STATE_FILE=".logs/.git-merge-all.state.local"
STATE_FILE_BACKUP=".logs/.git-merge-all.backup.local"

Expand Down Expand Up @@ -106,33 +108,34 @@ function load_state() {

function time_it() {
# Function to execute and time another function
# Captures start time, executes $2 with the rest args, captures end time, calculates time difference into tms_real[$1]
# If function $2 returns non-0 code, exits with that code.
# Args:
local i="$1"
local func_name="$2"
shift 2 # Remove the first two arguments, leaving only the function arguments

# Capture start time, exec, capture end time, calculate time difference
TIMESTART=$(date +%s%N)
local t t_real TIMESTART TIMEEND TIMEDIFF
# For measuring time, Since bash 5.0 (2019) use EPOCHREALTIME:
# remove the decimal separator (s → µs), remove last 3 digits (µs → ms)
t=${EPOCHREALTIME/[^0-9]/}; TIMESTART=${t%???}
"$func_name" "$@"
local return_value="$?"
if [ $return_value -ne 0 ]; then
[ "$DEBUG" -ne 0 ] && echo "DEBUG: '$func_name' exited with status $return_value" >&2
exit "$return_value"
fi
TIMEEND=$(date +%s%N)
TIMEDIFF=$(( TIMEEND - TIMESTART ))
TIMEDIFF_SEC=$(( TIMEDIFF / 1000000000 ))
TIMEDIFF_MSEC=$(( (TIMEDIFF % 1000000000) / 1000000 ))
t_real=$(printf "%d.%03d" "0$TIMEDIFF_SEC" "$TIMEDIFF_MSEC")
t=${EPOCHREALTIME/[^0-9]/}; TIMEEND=${t%???}

TIMEDIFF=$(( TIMEEND < TIMESTART ? TIMEEND - TIMESTART + 1000000000 : TIMEEND - TIMESTART ))
t_real=$(printf "%s.%s" $(( TIMEDIFF / 1000 )) $(( TIMEDIFF % 1000 )))
tms_real[i]="$t_real"
# tms_user[i]="$t_user"
# tms_sys[i]="$t_system"

[ "$DEBUG" -ne 0 ] && echo "DEBUG: time_it() func=$func_name status=$return_value TIMESTART=$TIMESTART TIMEEND=$TIMEEND TIMEDIFF=$TIMEDIFF TIMEDIFF_SEC=$TIMEDIFF_SEC t_real=$t_real tms_real[$i]=${tms_real[$i]}"
[ "$DEBUG" -ne 0 ] && echo "DEBUG: time_it() func=$func_name status=$return_value TIMESTART=$TIMESTART TIMEEND=$TIMEEND TIMEDIFF=$TIMEDIFF t_real=$t_real tms_real[$i]=${tms_real[$i]}"
# [ "$DEBUG" -ne 0 ] && echo "DEBUG: time_it() func=$func_name status=$return_value real=$t_real user=$t_user system=$t_system tms_real[$i]=${tms_real[$i]}"

# Return the result of the executed function
return $return_value
} 3>&1 4>&2
}

# Function to display usage information
function usage() {
Expand Down
32 changes: 18 additions & 14 deletions scripts/git-run-all-in-branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ git config user.name "IVA2K"
DEBUG=0
# DEBUG=1

[ -z "$EPOCHREALTIME" ] && { echo "$0 needs bash>5.0(2019-01) for EPOCHREALTIME"; exit 1; }

STATE_FILE=".logs/.git-run-all.state.local"
STATE_FILE_BACKUP=".logs/.git-run-all.backup.local"

Expand Down Expand Up @@ -119,33 +121,34 @@ function load_state() {

function time_it() {
# Function to execute and time another function
# Captures start time, executes $2 with the rest args, captures end time, calculates time difference into tms_real[$1]
# If function $2 returns non-0 code, exits with that code.
# Args:
local i="$1"
local func_name="$2"
shift 2 # Remove the first two arguments, leaving only the function arguments

# Capture start time, exec, capture end time, calculate time difference
TIMESTART=$(date +%s%N)
local t t_real TIMESTART TIMEEND TIMEDIFF
# For measuring time, Since bash 5.0 (2019) use EPOCHREALTIME:
# remove the decimal separator (s → µs), remove last 3 digits (µs → ms)
t=${EPOCHREALTIME/[^0-9]/}; TIMESTART=${t%???}
"$func_name" "$@"
local return_value="$?"
if [ $return_value -ne 0 ]; then
[ "$DEBUG" -ne 0 ] && echo "DEBUG: '$func_name' exited with status $return_value" >&2
exit "$return_value"
fi
TIMEEND=$(date +%s%N)
TIMEDIFF=$(( TIMEEND - TIMESTART ))
TIMEDIFF_SEC=$(( TIMEDIFF / 1000000000 ))
TIMEDIFF_MSEC=$(( (TIMEDIFF % 1000000000) / 1000000 ))
t_real=$(printf "%d.%03d" "0$TIMEDIFF_SEC" "$TIMEDIFF_MSEC")
t=${EPOCHREALTIME/[^0-9]/}; TIMEEND=${t%???}

TIMEDIFF=$(( TIMEEND < TIMESTART ? TIMEEND - TIMESTART + 1000000000 : TIMEEND - TIMESTART ))
t_real=$(printf "%s.%s" $(( TIMEDIFF / 1000 )) $(( TIMEDIFF % 1000 )))
tms_real[i]="$t_real"
# tms_user[i]="$t_user"
# tms_sys[i]="$t_system"

[ "$DEBUG" -ne 0 ] && echo "DEBUG: time_it() func=$func_name status=$return_value TIMESTART=$TIMESTART TIMEEND=$TIMEEND TIMEDIFF=$TIMEDIFF TIMEDIFF_SEC=$TIMEDIFF_SEC t_real=$t_real tms_real[$i]=${tms_real[$i]}"
[ "$DEBUG" -ne 0 ] && echo "DEBUG: time_it() func=$func_name status=$return_value TIMESTART=$TIMESTART TIMEEND=$TIMEEND TIMEDIFF=$TIMEDIFF t_real=$t_real tms_real[$i]=${tms_real[$i]}"
# [ "$DEBUG" -ne 0 ] && echo "DEBUG: time_it() func=$func_name status=$return_value real=$t_real user=$t_user system=$t_system tms_real[$i]=${tms_real[$i]}"

# Return the result of the executed function
return $return_value
} 3>&1 4>&2
}

# alias decolor='sed "s/\x1B\[\([0-9]\{1,2\}\(;[0-9]\{1,2\}\)\?\)\?[mGK]//g"'
function decolor() {
Expand Down Expand Up @@ -288,8 +291,9 @@ function print_summary() {
pass_cnt=0
total_cnt=0
total_time=0
logdir="$(dirname "$LOGFILE")"; logdir="$([ "$logdir" = "." ] && echo "" || echo "${logdir:+($logdir/)}")"
FORMAT="| %-20s | %6s | %-30s | %9s | %-100s |"
HEAD=$(printf "$FORMAT" "Branch" "Error" "Log File" "Time (s)" "Output")
HEAD=$(printf "$FORMAT" "Branch" "Error" "Log File ${logdir}" "Time (s)" "Output")
LINE=$(printf "$FORMAT" "" "" "" "" "")
LINE="${LINE// /-}"
echo | tee -a "$LOGFILE"
Expand All @@ -314,7 +318,7 @@ function print_summary() {
fi
total_time=$(awk "BEGIN {print ($total_time+0${tms_real[$i]})}")
[ "$color_red" -ne 0 ] && echo -n -e "\033[31m"
printf "$FORMAT\n" "$TARGET_BRANCH" "$error" "$LOGFILE_I" "$(format_float "${tms_real[$i]}")" "${output:0:102}" | tee -a "$LOGFILE"
printf "$FORMAT\n" "$TARGET_BRANCH" "$error" "$(basename "$LOGFILE_I")" "$(format_float "${tms_real[$i]}")" "${output:0:102}" | tee -a "$LOGFILE"
[ "$color_red" -ne 0 ] && echo -n -e "\033[39m"
done
echo "$LINE" | tee -a "$LOGFILE"
Expand Down

0 comments on commit ab3bcdf

Please sign in to comment.