-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load timer #405
base: main
Are you sure you want to change the base?
Load timer #405
Changes from all commits
2edc75c
622ead6
651f73b
4763901
c73aba9
3325367
3cc05d0
7056fa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
module_options+=( | ||
["set_checkpoint,author"]="@armbian" | ||
["set_checkpoint,maintainer"]="@igorpecovnik" | ||
["set_checkpoint,feature"]="set_checkpoint" | ||
["set_checkpoint,example"]="help start mark stop show" | ||
["set_checkpoint,desc"]="Helper module for timing code execution" | ||
["set_checkpoint,status"]="" | ||
["set_checkpoint,doc_link"]="" | ||
["set_checkpoint,group"]="Development" | ||
["set_checkpoint,port"]="" | ||
["set_checkpoint,arch"]="x86-64 arm64" | ||
) | ||
# | ||
# Function to manage timer with multiple checkpoints | ||
function set_checkpoint() { | ||
case "$1" in | ||
help) | ||
echo "Usage: set_checkpoint <start|stop|mark|show> [description] [show]" | ||
echo "Commands:" | ||
echo " start Start the timer." | ||
echo " stop Stop the timer." | ||
echo " mark [description] [time] Mark a checkpoint with an optional description and an optional flag to show the output." | ||
echo " show Show the total elapsed time and checkpoints." | ||
;; | ||
Comment on lines
+18
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing indent? Same for other cases. |
||
start) | ||
set_checkpoint_START=$(date +%s) | ||
set_checkpoint_CHECKPOINTS=() | ||
set_checkpoint_DESCRIPTIONS=() | ||
set_checkpoint_PREV=$set_checkpoint_START | ||
;; | ||
stop) | ||
set_checkpoint_STOP=$(date +%s) | ||
;; | ||
mark) | ||
local checkpoint_time=$(date +%s) | ||
local checkpoint_duration=$((checkpoint_time - set_checkpoint_PREV)) | ||
set_checkpoint_PREV=$checkpoint_time | ||
set_checkpoint_CHECKPOINTS+=($checkpoint_time) | ||
set_checkpoint_DESCRIPTIONS+=("$2") | ||
local count=${#set_checkpoint_DESCRIPTIONS[@]} | ||
if [[ "$3" == "true" && $UXMODE == "true" ]]; then | ||
printf "%-30s %10d seconds\n" "$2:" "${checkpoint_duration}" | ||
fi | ||
Comment on lines
+36
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, but if you do this, you can avoid unnecessary calculations in non-UX mode: mark)
if [[ "$UXMODE" == "true" ]]; then
local checkpoint_time=$(date +%s)
local checkpoint_duration=$((checkpoint_time - set_checkpoint_PREV))
set_checkpoint_PREV=$checkpoint_time
set_checkpoint_CHECKPOINTS+=($checkpoint_time)
set_checkpoint_DESCRIPTIONS+=("$2")
local count=${#set_checkpoint_DESCRIPTIONS[@]}
[[ "$3" == "true" ]] && printf "%-30s %10d seconds\n" "$2:" "${checkpoint_duration}"
fi
;; |
||
;; | ||
show) | ||
if [[ -n "$set_checkpoint_START" && -n "$set_checkpoint_STOP" ]]; then | ||
set_checkpoint_DURATION=$((set_checkpoint_STOP - set_checkpoint_START)) | ||
printf "%-30s: %d seconds\n" "Total elapsed time" "${set_checkpoint_DURATION}" | ||
|
||
local previous_time=$set_checkpoint_START | ||
for i in "${!set_checkpoint_CHECKPOINTS[@]}"; do | ||
local checkpoint_time=${set_checkpoint_CHECKPOINTS[$i]} | ||
local checkpoint_duration=$((checkpoint_time - previous_time)) | ||
local description=${set_checkpoint_DESCRIPTIONS[$i]} | ||
printf "%-30s: %d seconds\n" "${description:-Checkpoint $((i+1))}" "${checkpoint_duration}" | ||
previous_time=$checkpoint_time | ||
Comment on lines
+53
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing indent inside for-loop? |
||
done | ||
else | ||
echo "Timer has not been started and stopped properly." | ||
fi | ||
;; | ||
*) | ||
echo "Usage: set_checkpoint <start|stop|mark|show> [description]" | ||
;; | ||
esac | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW can be replaced with: