strace+

I had a problem with one of my programs going abnormally slow.  Being a linux developer, one of the steps I took to diagnosing the problem was to strace the executable. Interestingly it showed me that I was accessing /usr/share/zoneinfo/GMT a ridiculous quantity of times.  What I needed then was a stack trace at the time /usr/share/zoneinfo/GMT was opened.  strace doesn’t provide that information.

A bit of search engine work reveals

http://stackoverflow.com/questions/5863115/gdb-break-when-program-opens-specific-file

but that seemed a bit like too much work.

A bit more learning about gdb taught me that you can break on syscalls using

catch syscall

Now this might have worked but the file I was opening a lot was well after the program startup, so I decided to keep looking for a better solution.  That’s when I discovered

https://code.google.com/p/strace-plus/

strace-plus is a version of strace with a call stack print out at every syscall.  Exactly what I wanted. There are two points to note about that webpage.  First is that the make produces an executable called strace not strace+; so you’ll need to

cp strace strace+

if you want to stay sane.  Secondly in step 3 where they say

./strace+ -o hello.out ./hello

you actually need to use

./strace+ -k -o hello.out ./hello

Note the -k which gets the actual stack trace.

Posted in Uncategorized

Leave a comment