Skip to content

Instantly share code, notes, and snippets.

@donjohnson
Created May 10, 2012 16:46
Show Gist options
  • Save donjohnson/2654410 to your computer and use it in GitHub Desktop.
Save donjohnson/2654410 to your computer and use it in GitHub Desktop.
per-process-timings.sh
#!/bin/bash
hertz=100
host=`cat /etc/hn`
for pidfile in `find /var/run -type f -name '*.pid*'`
do
progname=`basename $pidfile|sed -e 's/\.pid$//g'`;
# if progname = agent, progname = puppet-agent.
if [ $progname = "agent" ]
then
progname="puppet_agent"
fi
pid=`cat $pidfile`
stats=`cut -d ' ' -f 14-17 /proc/$pid/stat`
utime=`echo "$stats"|cut -d' ' -f 1`
stime=`echo "$stats"|cut -d' ' -f 2`
#cutime=`echo "$stats"|cut -d' ' -f 3`
#cstime=`echo "$stats"|cut -d' ' -f 4`
#time_tics=$((utime + stime + cutime + cstime))
time_tics=$((utime + stime))
time_secs=`echo "scale=0; $time_tics * ( 1000 / $hertz )" | bc` #ticks * 10 = ms
echo "put test.per_proc_timings `date +%s` $time_secs process=$progname host=$host"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment