Skip to content

Commit

Permalink
Fix for occasionally freezes when enable the profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Jul 20, 2019
1 parent 364ad12 commit 81cc088
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
14 changes: 13 additions & 1 deletion lib/libexec.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#shellcheck shell=sh
#shellcheck shell=sh disable=SC2004

[ "${ZSH_VERSION:-}" ] && setopt shwordsplit

Expand Down Expand Up @@ -96,4 +96,16 @@ abort() {
exit 1
}

sleep_wait() {
case $1 in
*[!0-9]*) timeout=999999999 ;;
*) timeout=$1; shift
esac
while "$@"; do
[ "$timeout" -gt 0 ] || return 1
sleep 0
timeout=$(($timeout - 1))
done
}

use puts putsn
12 changes: 0 additions & 12 deletions lib/libexec/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,3 @@ read_pid_file() {
eval "read -r $1 < \"$2\""
fi
}

sleep_wait() {
case $1 in
*[!0-9]*) timeout=999999999 ;;
*) timeout=$1; shift
esac
while "$@"; do
[ "$timeout" -gt 0 ] || return 1
sleep 0
timeout=$(($timeout - 1))
done
}
6 changes: 5 additions & 1 deletion libexec/shellspec-profiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ terminate() {
echo "$(($end - $start))" >> "$SHELLSPEC_PROFILER_LOG"
i=$(($i + 2))
done
rm "$SHELLSPEC_TMPBASE/profiler.pid"
exit
}

finished() {
: > "$SHELLSPEC_TMPBASE/profiler.done"
}

: > "$SHELLSPEC_PROFILER_LOG"

pid=''
if ( trap - USR1 && trap - TERM ) 2>/dev/null; then
trap handler USR1
trap terminate TERM
trap finished EXIT
pid=$$
fi
echo "$pid" > "$SHELLSPEC_TMPBASE/profiler.pid"
Expand Down
4 changes: 1 addition & 3 deletions libexec/shellspec-reporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ read_time_log "time" "$SHELLSPEC_TIME_LOG"

if [ "$SHELLSPEC_PROFILER" ] && [ "$SHELLSPEC_PROFILER_LOG" ]; then
mkdir -p "$SHELLSPEC_REPORTDIR"
while shellspec_signal -0 "$SHELLSPEC_PROFILER_PID" 2>/dev/null; do
sleep 0
done
sleep_wait 1000 [ ! -e "$SHELLSPEC_TMPBASE/profiler.done" ] ||:
callback() {
eval "profiler_tick$1=\$2 profiler_time$1=\$3" \
"profiler_line=\$profiler_line$1 profiler_count=$(($1 + 1))"
Expand Down
2 changes: 1 addition & 1 deletion libexec/shellspec-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ start_profiler() {
stop_profiler() {
[ "$SHELLSPEC_PROFILER_PID" ] || return 0
signal -TERM "$SHELLSPEC_PROFILER_PID" 2>/dev/null ||:
sleep_wait 1000 [ -e "$SHELLSPEC_TMPBASE/profiler.pid" ] ||:
sleep_wait [ ! -e "$SHELLSPEC_TMPBASE/profiler.done" ] ||:
SHELLSPEC_PROFILER_PID=''
}

Expand Down

0 comments on commit 81cc088

Please sign in to comment.