统计命令的执行时间。
# output function
# param 1: startTimestamp, format $(date +%s%N)
# param 2: endTimestamp, format $(date +%s%N)
# param 3: command ID
# param 4: command result
# param 5: command output
function output() {
typeset START=$(date -d @$(($1/1000000000)) +"%Y-%m-%d %T")
typeset END=$(date -d @$(($2/1000000000)) +"%Y-%m-%d %T")
typeset ID=${3:-ID}
typeset STATUS=${4:-SUCCESS}
typeset OUTPUT=${5:-}
typeset ELAPSE=$((($2- $1)/1000000))
echo "id=${ID}, status=${STATUS}, time=(${START} - ${END} - ${ELAPSE}ms), output=[${OUTPUT}]"
}
# mark command begin timestamp
startTime=$(date +%s%N)
CMDID, CMDSTATUS, CMDOUTPUT = ... execute command and get result ...
# mark command stop timestamp
endTime=$(date +%s%N)
# output command execute timestamp
output $startTime $endTime $CMDID $CMDSTATUS $CMDOUTPUT
例如输出:
id=ID, status=Success, time=(2020-05-08 15:11:05 - 2020-05-08 15:11:06 - 298ms), output=[...]
网友评论