testfunc() { 
trap 'echo RETURN' RETURN;
f() { echo "f: $*"; }
g() ( trap 'echo EXIT' EXIT;  echo "g: $*"; )
h() { 
	echo "h: $*"; 
	f "$@"; 
	g "$@";
}

echo 0
{ echo 1; }
( echo 2 )
echo 3 &
{ echo 4; } &

echo 5 | cat | tee

for (( kk=6; kk<10; kk++ )); do
	echo $kk
	h $kk
	for jj in {1..3}; do
		f $kk $jj
		g $kk $jj
	done
done
}


timep testfunc


:<<'EOF'
LINE DEPTH CMD  COMBINED WALL-CLOCK TIME          COMBINED CPU TIME                     COMMAND
line.depth.cmd: ( time | total % | cur depth % )  ( time | total % | cur depth % )      (count) <command>
_______________ __________________________________________________________________      ____________________________________

1.0.0:          ( 0.565324s |100.00% )            ( 0.572306s |100.00% )                (1x)    << (FUNCTION): main.testfunc "${@}" >>
1.1.0:          ( 0.000070s |  0.01% )            ( 0.000093s |  0.01% )                (1x)    testfunc "${@}"

2.1.0:          ( 0.022847s |  4.04% )            ( 0.022775s |  3.97% )                (1x)    trap 'echo RETURN' RETURN

5.1.0:          ( 0.002009s |  0.35% )            ( 0.002016s |  0.35% )                (1x)    TRAP (RETURN): echo RETURN

11.1.0:         ( 0.000095s |  0.01% )            ( 0.000108s |  0.01% )                (1x)    echo 0

12.1.0:         ( 0.000770s |  0.13% )            ( 0.000670s |  0.11% )                (1x)    echo 1

13.1.0:         ( 0.000176s |  0.03% )            ( 0.000203s |  0.03% )                (1x)    << (SUBSHELL) >>
13.2.0:         ( 0.000176s |  0.03% |100.00% )   ( 0.000203s |  0.03% |100.00% )       (1x)     └─echo 2

14.1.0:         ( 0.000480s |  0.08% )            ( 0.000512s |  0.08% )                (1x)    echo 3 (&)

15.1.0:         ( 0.000162s |  0.02% )            ( 0.000188s |  0.03% )                (1x)    << (BACKGROUND FORK) >>
15.2.0:         ( 0.000162s |  0.02% |100.00% )   ( 0.000188s |  0.03% |100.00% )       (1x)     └─echo 4

16.1.0:         ( 0.004038s |  0.71% )            ( 0.013263s |  2.31% )                (1x)    echo 5 | cat | tee

18.1.0:         ( 0.000070s |  0.01% )            ( 0.000084s |  0.01% )                (1x)    ((kk=6))

18.1.0:         ( 0.000282s |  0.04% |  0.01% )   ( 0.000327s |  0.05% |  0.01% )       (4x)    ((kk++ ))

18.1.1:         ( 0.000365s |  0.06% |  0.01% )   ( 0.000434s |  0.07% |  0.01% )       (5x)    ((kk<10))

19.1.0:         ( 0.000289s |  0.05% |  0.01% )   ( 0.000346s |  0.06% |  0.01% )       (4x)    echo $kk

20.1.0:         ( 0.144182s | 25.50% |  6.37% )   ( 0.143671s | 25.10% |  6.27% )       (4x)    << (FUNCTION): main.testfunc.h $kk >>
1.2.0:          ( 0.000305s |  0.05% |  0.21% )   ( 0.000362s |  0.06% |  0.25% )       (4x)     ├─h $kk
2.2.0:          ( 0.000306s |  0.05% |  0.21% )   ( 0.000359s |  0.06% |  0.24% )       (4x)     │ echo "h: $*"
3.2.0:          ( 0.008277s |  1.46% |  5.74% )   ( 0.008419s |  1.47% |  5.85% )       (4x)     │ << (FUNCTION): main.testfunc.h.f "$@" >>
1.3.0:          ( 0.000270s |  0.04% |  3.26% )   ( 0.000324s |  0.05% |  3.84% )       (4x)     │  ├─f "$@"
2.3.0:          ( 0.000344s |  0.06% |  4.15% )   ( 0.000400s |  0.06% |  4.75% )       (4x)     │  │ echo "f: $*"
2.3.1:          ( 0.007663s |  1.35% | 92.58% )   ( 0.007695s |  1.34% | 91.40% )       (4x)     │  └─TRAP (RETURN): echo RETURN
4.2.0:          ( 0.127463s | 22.54% | 88.40% )   ( 0.126675s | 22.13% | 88.17% )       (4x)     │ << (FUNCTION): main.testfunc.h.g "$@" >>
1.3.0:          ( 0.004500s |  0.79% |  3.53% )   ( 0.003950s |  0.69% |  3.11% )       (4x)     │  ├─g "$@"
2.3.0:          ( 0.110687s | 19.57% | 86.83% )   ( 0.110437s | 19.29% | 87.18% )       (4x)     │  │ << (SUBSHELL) >>
2.4.0:          ( 0.102756s | 18.17% | 92.83% )   ( 0.102422s | 17.89% | 92.74% )       (4x)     │  │  ├─trap 'echo EXIT' EXIT
2.4.1:          ( 0.000361s |  0.06% |  0.32% )   ( 0.000423s |  0.07% |  0.38% )       (4x)     │  │  │ echo "g: $*"
-453.4.0:       ( 0.007570s |  1.33% |  6.83% )   ( 0.007592s |  1.32% |  6.87% )       (4x)     │  │  └─TRAP (EXIT): echo EXIT
2.3.1:          ( 0.012276s |  2.17% |  9.63% )   ( 0.012288s |  2.14% |  9.70% )       (4x)     │  └─TRAP (RETURN): echo RETURN
1.2.0:          ( 0.007831s |  1.38% |  5.43% )   ( 0.007856s |  1.37% |  5.46% )       (4x)     └─TRAP (RETURN): echo RETURN

21.1.0:         ( 0.000778s |  0.13% |  0.01% )   ( 0.000947s |  0.16% |  0.01% )       (12x)   for jj in {1..3}

22.1.0:         ( 0.025140s |  4.44% |  0.37% )   ( 0.025556s |  4.46% |  0.37% )       (12x)   << (FUNCTION): main.testfunc.f $kk $jj >>
1.2.0:          ( 0.000890s |  0.15% |  3.54% )   ( 0.001055s |  0.18% |  4.12% )       (12x)    ├─f $kk $jj
2.2.0:          ( 0.000962s |  0.17% |  3.82% )   ( 0.001129s |  0.19% |  4.41% )       (12x)    │ echo "f: $*"
2.2.1:          ( 0.023288s |  4.11% | 92.63% )   ( 0.023372s |  4.08% | 91.45% )       (12x)    └─TRAP (RETURN): echo RETURN

23.1.0:         ( 0.363571s | 64.31% |  5.35% )   ( 0.361113s | 63.09% |  5.25% )       (12x)   << (FUNCTION): main.testfunc.g $kk $jj >>
1.2.0:          ( 0.012459s |  2.20% |  3.42% )   ( 0.010637s |  1.85% |  2.94% )       (12x)    ├─g $kk $jj
2.2.0:          ( 0.315287s | 55.77% | 86.71% )   ( 0.314600s | 54.97% | 87.11% )       (12x)    │ << (SUBSHELL) >>
2.3.0:          ( 0.291214s | 51.51% | 92.36% )   ( 0.290281s | 50.72% | 92.26% )       (12x)    │  ├─trap 'echo EXIT' EXIT
2.3.1:          ( 0.001094s |  0.19% |  0.34% )   ( 0.001247s |  0.21% |  0.39% )       (12x)    │  │ echo "g: $*"
-453.3.0:       ( 0.022979s |  4.06% |  7.28% )   ( 0.023072s |  4.03% |  7.33% )       (12x)    │  └─TRAP (EXIT): echo EXIT
2.2.1:          ( 0.035825s |  6.33% |  9.85% )   ( 0.035876s |  6.26% |  9.93% )       (12x)    └─TRAP (RETURN): echo RETURN

TOTAL RUN TIME: 0.565324s
TOTAL CPU TIME: 0.572306s
EOF
