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