xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Docs/Examples/sh_wasted_example.txt (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1Many shell programmers are in the habit of using calls to external commands
2instead of using shell built-in commands (an example of this is a call to
3usr/bin/echo instead of using the echo command built into the shell.
4
5This script shows sh_wasted.d tracing a shell script that calls /usr/bin/echo
6instead of using the built-in.
7
8# sh_wasted.d -c ./func_waste.sh
9Tracing... Hit Ctrl-C to end.
10Function A
11Function B
12Function C
13Script duration: 3101631 us
14
15External command elapsed times,
16   FILE                           NAME                   TIME(us)
17   func_waste.sh                  sleep                   3019573
18
19Wasted command elapsed times,
20   FILE                           NAME                   TIME(us)
21   func_waste.sh                  /usr/bin/echo             26510
22
23You can see that the calls to /usr/bin/echo took around 26 thousand
24microseconds; time wasted by the shell having to access an external command.
25
26
27Here we trace the same script, except it uses the shell built-in echo command.
28
29# sh_wasted.d -c ./func_abc.sh
30Function A
31Tracing... Hit Ctrl-C to end.
32Function B
33Function C
34Script duration: 3032616 us
35
36External command elapsed times,
37   FILE                           NAME                   TIME(us)
38   func_abc.sh                    sleep                   3012920
39
40Wasted command elapsed times,
41   FILE                           NAME                   TIME(us)
42
43The total time here is less and there are no 'wasted' calls to external
44commands.
45
46