# without profiling gcc -g -Wall -o countchars countchars.c cat /dev/urandom | hexdump -C | head -n 100 > bigfile.txt time ./countchars ./bigfile.txt cat /dev/urandom | hexdump -C | head -n 500 > bigfile.txt time ./countchars ./bigfile.txt # add profiling by compiling and linking with the "-pg" command-line argument gcc -pg -g -Wall -o countchars countchars.c ./countchars ./bigfile.txt ls -al # note the "gmon.out" file produced by gprof gprof ./countchars | less # try a more pretty representation wget http://gprof2dot.jrfonseca.googlecode.com/hg/gprof2dot.py chmod 755 gprof2dot.py gprof ./countchars | ./gprof2dot.py -n0 -e0 | dot -Tpng | display # Hmm....close, but gprof doesn't cut it, as it can't see inside # glibc without getting a profile-enabled glibc. Let's try # valgrind! sudo yum install kdesdk # for the "kcachegrind" visualization tool gcc -g -Wall -o countchars countchars.c cat /dev/urandom | hexdump -C | head -n 500 > bigfile.txt valgrind --tool=callgrind ./countchars ./bigfile.txt ls -al # note callgrind.out.[pid] callgrind_annotate callgrind.out.[pid] kcachegrind # or, use gprof2dot.py ./gprof2dot.py -f callgrind -n0 -e0 callgrind.out.[pid] | dot -Tpng | display