diff options
author | P. J. McDermott <pj@pehjota.net> | 2016-02-25 02:27:40 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2016-02-25 02:27:40 (EST) |
commit | 4ebdf962897f4401b062cb3475b93042a3ce3e53 (patch) | |
tree | bdc868c77a6fe55cf808a3cfa4f9d0cf28274935 | |
parent | 0f38e66b1a5d2abdf027b87a464751b9653e8b11 (diff) | |
download | eggshell-4ebdf962897f4401b062cb3475b93042a3ce3e53.zip eggshell-4ebdf962897f4401b062cb3475b93042a3ce3e53.tar.gz eggshell-4ebdf962897f4401b062cb3475b93042a3ce3e53.tar.bz2 |
eshprof: Store times as integers
Don't fork() and exec() awk.
mksh doesn't seem to have sufficient precision here. We'll have to
either ignore mksh for eshprof or maybe use bc.
-rw-r--r-- | eshprof/flat-profile.esh | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/eshprof/flat-profile.esh b/eshprof/flat-profile.esh index ecf2a6e..01201cc 100644 --- a/eshprof/flat-profile.esh +++ b/eshprof/flat-profile.esh @@ -67,9 +67,7 @@ frame_inc_time() local p="${1}" local value="${2}" - eval "frame_${p}_time=\$(awk \ - -v time=\${frame_${p}_time} -v value=\${value} \ - 'BEGIN { print(time + value); }')" + eval "frame_${p}_time=\$((\${frame_${p}_time} + \${value}))" } frame_dec_time() @@ -77,9 +75,7 @@ frame_dec_time() local p="${1}" local value="${2}" - eval "frame_${p}_time=\$(awk \ - -v time=\${frame_${p}_time} -v value=\${value} \ - 'BEGIN { print(time - value); }')" + eval "frame_${p}_time=\$((\${frame_${p}_time} - \${value}))" } ctxsw() @@ -101,9 +97,8 @@ record() case " ${fns} " in "${name}") - eval "fn_timing_${name}=\$(awk \ - -v time=\${fn_timing_${name}} -v inc=\${time} \ - 'BEGIN { print(time + inc); }')" + eval "fn_timing_${name}=\$((\${fn_timing_${name}} + \ + \${time}))" eval "fn_calls_${name}=\$((\${fn_calls_${name}} + 1))" ;; *) @@ -112,8 +107,7 @@ record() fns="${fns} ${name}" ;; esac - total_runtime=$(awk -v total=${total_runtime} -v inc=${time} \ - 'BEGIN { print(total + inc); }') + total_runtime=$((${total_runtime} + ${time})) } fn_begin() @@ -151,7 +145,8 @@ read_profile() shift 1 while read time change fn; do - #time="${time%.*}${time#*.}" + # Convert to int. + time="${time%.*}${time#*.}" case "${change}" in 'B') fn_begin "${fn}" "${time}" @@ -174,14 +169,15 @@ show_table() printf '%% time seconds calls name\n' for fn in ${fns}; do eval "time=\${fn_timing_${fn}}" - percent=$(awk -v time=${time} -v total=${total_runtime} \ - 'BEGIN { print(time / total * 100); }') + percent=$(printf 'scale = 2; 100 * %d / %d\n' \ + ${time} ${total_runtime} | bc) + time=$(printf 'scale = 9; %d / 1000000000\n' ${time} | bc) eval "calls=\${fn_calls_${fn}}" printf '%6.2f ' ${percent} printf '%14.9f ' ${time} printf '%8d ' ${calls} printf '%s\n' "${fn}" - done | sort -r -k 2,4 + done | sort -nr -k 1,4 } flat_profile() |