diff options
-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() |