Skip to content

Commit 9ec0f6f

Browse files
committed
Change timestamp format
The old format is precision to seconds, which is too much. The new format allows you to see a more precise time period. Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
1 parent c930413 commit 9ec0f6f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

mk/main.mk.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ include @projectdir@/mk/packimage.mk
5151
endif
5252

5353
ifneq ($(call in-goals,process-config),)
54-
STARTUP_TIME = $(shell date +'%s')
54+
STARTUP_TIME = $(shell date -u +'%s%N')
5555
WORKDIR_SUFFIX = $(basename $(notdir $(INITRD_CONFIG)))
5656
endif
5757

tools/msg-timestamp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
#!/bin/bash -efu
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

4-
echo "[$(date -u -d "@$(($(date +'%s') - ${STARTUP_TIME:-0}))" +"%T")]"
4+
export LANG=C
5+
export LC_ALL=C
6+
7+
duration="0"
8+
suffix="s"
9+
10+
if [ "${STARTUP_TIME:-0}" -gt 0 ]; then
11+
us=$(( $(date -u '+%s%N') / 1000 ))
12+
us=$(( $us - ($STARTUP_TIME / 1000) ))
13+
14+
m=( 3600000000 60000000 1000000 1000 0 )
15+
s=( h m s ms us )
16+
17+
for (( i = 0; $i < ${#m[@]}; i++ )) do
18+
if [ $us -gt ${m[$i]} ]; then
19+
[ ${m[$i]} -ne 0 ] &&
20+
printf -v duration '%g' "$(($us / ${m[$i]})).$(($us / (${m[$i]} / 100) % 100))" ||
21+
printf -v duration '%d' "$us" ||:
22+
suffix="${s[$i]}"
23+
break
24+
fi
25+
done
26+
fi
27+
28+
printf '[%9s ]\n' "${duration}${suffix}"

0 commit comments

Comments
 (0)