Skip to content

Commit 3d8f626

Browse files
committed
main: show details of the loading time
1 parent b0e3973 commit 3d8f626

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

ble.pp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,40 @@
66
#%[leakvar = ""]
77
#%#----------------------------------------------------------------------------
88
#%if measure_load_time
9+
_ble_init_measure_prev=
10+
_ble_init_measure_section=
11+
function ble/init/measure/section {
12+
local now=${EPOCHREALTIME:-$(date +'%s.%N')}
13+
14+
local s=${now%%[!0-9]*} u=000000
15+
if [[ $s != "$now" ]]; then
16+
u=${now##*[!0-9]}000000
17+
u=${u::6}
18+
fi
19+
local stime=$s.$u time=$((s*1000000+10#0$u))
20+
21+
if [[ $_ble_init_measure_section ]]; then
22+
local elapsed=$((time-_ble_init_measure_prev))
23+
s=$((elapsed/1000))
24+
u=00$((elapsed%1000))
25+
u=${u:${#u}-3}
26+
elapsed=$s.${u}ms
27+
builtin printf '[ble.sh init %s] %s done (%s)\n' "$stime" "$_ble_init_measure_section" "$elapsed" >&2
28+
else
29+
builtin printf '[ble.sh init %s] start\n' "$stime" >&2
30+
fi
31+
32+
_ble_init_measure_section=$1
33+
_ble_init_measure_prev=$time
34+
}
935
_ble_debug_measure_fork_count=$(echo $BASHPID)
10-
TIMEFORMAT='[Elapsed %Rs; CPU U:%Us S:%Ss (%P%%)]'
36+
TIMEFORMAT=' [Elapsed %Rs; CPU U:%Us S:%Ss (%P%%)]'
1137
function ble/debug/measure-set-timeformat {
1238
local title=$1 opts=$2
1339
local new=$(echo $BASHPID)
1440
local fork=$(((new-_ble_debug_measure_fork_count-1)&0xFFFF))
1541
_ble_debug_measure_fork_count=$new
16-
TIMEFORMAT="[Elapsed %Rs; CPU U:%Us S:%Ss (%P%%)] $title"
42+
TIMEFORMAT=" [Elapsed %Rs; CPU U:%Us S:%Ss (%P%%)] $title"
1743
[[ :$opts: != *:nofork:* ]] &&
1844
TIMEFORMAT=$TIMEFORMAT" ($fork forks)"
1945
}
@@ -60,9 +86,9 @@ function ble/util/print { printf '%s\n' "$1"; }
6086
#
6187

6288
#%if measure_load_time
63-
echo "ble.sh: $EPOCHREALTIME load start" >&2
89+
ble/init/measure/section 'parse'
6490
time {
65-
echo "ble.sh: $EPOCHREALTIME parsed" >&2
91+
ble/init/measure/section 'source'
6692
# load_time (2015-12-03)
6793
# core 12ms
6894
# decode 10ms
@@ -2625,6 +2651,9 @@ function ble-attach {
26252651
fi
26262652

26272653
[[ ! $_ble_attached ]] || return 0
2654+
#%if measure_load_time
2655+
ble/init/measure/section 'prompt'
2656+
#%end
26282657
_ble_attached=1
26292658
BLE_ATTACHED=1
26302659

@@ -2694,6 +2723,10 @@ function ble-attach {
26942723
ble_attach_first_prompt=1 \
26952724
ble/canvas/panel/render # 42ms
26962725
ble/util/buffer.flush # 0.2ms
2726+
#%if measure_load_time
2727+
ble/util/print >&2
2728+
ble/init/measure/section 'bind'
2729+
#%end
26972730

26982731
#%if leakvar
26992732
ble/debug/leakvar#check $"leakvar" A6-edit
@@ -2746,6 +2779,9 @@ function ble-attach {
27462779
# Note: ble-decode/{initialize,reset-default-keymap} 内で
27472780
# info を設定する事があるので表示する。
27482781
ble/edit/info/default
2782+
#%if measure_load_time
2783+
ble/init/measure/section 'idle'
2784+
#%end
27492785
#%if leakvar
27502786
ble/debug/leakvar#check $"leakvar" A11-info
27512787
#%end.i
@@ -3150,9 +3186,9 @@ function ble/base/sub:lib { return 0; } # do nothing
31503186
fi
31513187

31523188
#%if measure_load_time
3153-
ble/debug/measure-set-timeformat Total nofork; }
3189+
ble/debug/measure-set-timeformat 'Total' nofork; }
31543190
_ble_init_exit=$?
3155-
echo "ble.sh: $EPOCHREALTIME load end" >&2
3191+
[[ ${BLE_ATTACHED-} ]] || ble/init/measure/section 'wait'
31563192
ble/util/setexit "$_ble_init_exit"
31573193
#%end
31583194

docs/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@
304304
- global: rename `ret` not used as `REPLY` `#D2300` 86cbf78e
305305
- global: avoid raw word splitting `#D2309` b55c4003
306306
- global: use `ble/util/assign` in more places `#D2312` xxxxxxxx
307+
- main: show details of the loading time (motivated by tessus, Darukutsu) `#D2313` xxxxxxxx
307308

308309
<!---------------------------------------------------------------------------->
309310
# ble-0.4.0-devel3

make_command.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ function sub:scan {
610610
\Z\(ble/builtin/bind\|ble/builtin/bind/\*\|bind\|ble/decode/read-inputrc/test\)Zd
611611
\Ztitle=['\''"]([^"]*: )?bind \(ble\.sh\)['\''"]Zd
612612
\Zwarning: readline \\"bind -x\\" does not supportZd
613+
\Zble/init/measure/section '\''bind'\''Zd
613614
g'
614615
sub:scan/builtin 'read' |
615616
sed -E 'h;s/'"$_make_rex_escseq"'//g;s/^[^:]*:[0-9]+:[[:blank:]]*//

note.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7730,6 +7730,15 @@ bash_tips
77307730

77317731
2024-12-31
77327732

7733+
* main: 初期化時刻の表示 (motivated by tessus, Darukutsu) [#D2313]
7734+
https://github.com/akinomyoga/ble.sh/issues/340
7735+
https://forum.atuin.sh/t/atuin-bash-and-ble-sh/175/26?u=akinomyoga
7736+
7737+
議論に上る度に修正して自分で計算してまた元に戻すのは面倒なので、parse,
7738+
load, attach, prompt, bind の一連の処理の時間も全て計測して表示する事にした。
7739+
idle についてはユーザーが勘違いしそうなので積極的には表示しない。必要であれ
7740+
ば自分で書き換えて表示して使う事にする。
7741+
77337742
* global: ble/util/assign をもっと広く使う [#D2312]
77347743

77357744
初期化の段階で $() を使っていた箇所があるが、もっと早く ble/util/assign の

0 commit comments

Comments
 (0)