#!/bin/bash
clear
(echo "Get a summary of what a program did and how much runtime it spent doing it.
	A simple form of profiling"
echo "$ strace -c echo hello"
strace -c echo hello ) 2>&1 | less -S
clear
(
echo "Now a normal trace with all the details"
echo "$ strace echo hello"
strace echo hello
) 2>&1 | less -S
clear
(
echo "We run into problems when we run a program that runs another program"
echo "$ strace sh -c /bin/date  2>&1"
strace sh -c /bin/date  2>&1
) 2>&1 | less -S
clear
echo "The date doesn't seem to be anywhere in there" | less -S
( echo "We can follow a processes children too"
echo "$ strace -f sh -c /bin/date  2>&1"
strace -f sh -c /bin/date  2>&1
) 2>&1 | less -S
clear
echo "OK, but still TMI!" | less -S
(
echo "We can use filters with strace -e"
echo "This one on shows file system activity. You could use it in place of inotify"
echo "$ strace -e trace=file id "
strace -e trace=file id
) 2>&1 | less -S
clear
echo "Ick, why all those errors!" | less -S
clear
(
echo "We can filter on process managment too"
echo "$ strace -e trace=process sh -c /bin/date"
strace -e trace=process sh -c /bin/date
) 2>&1 | less -S
clear
(
echo "or even network activity like tcpdump does"
echo "$ strace -e trace=network ping -c 1 127.0.0.1"
strace -e trace=network ping -c 1 127.0.0.1
) 2>&1 | less -S  
clear
(
echo "You can even attach to a process already running with -> strace -p PID <-"
echo "If you are attaching to a process when you type ctrl+c it will kill strace but 
not the target"
echo "You can combine this and all the other options as you please"
) | less -S
clear
echo "End of Demo"
read -sn 1 x

