Get Superman x-ray vision

Written by Torstein Krause Johansen updated: Wednesday April 12 2017 12:12

We're big Linux users here at Escenic. We run our Escenic Cloud offering on Linux machines, we run our QA test automation server racks on Linux, our internal build and demo infrastructure run on Linux and many of our developers, consultants and operations staff use Linux on their laptops.

Common to all of these environment is that they run many pieces of server software and we want to know exactly what a given process does. However, it's sometimes not possible to get all the information we need from the applications themselves as we have to make due with whatever that application has in place with regards to logging and configuration of this. It's therefore sometimes desirable to be able to peek into what the program does by going one level deeper: the operating system.

On Linux we've got this amazing tool to inspect what operating system calls a given process makes. The tool is available on all Linux distributions and it's called strace (apt-get install strace if you don't have it installed). Solaris users have dtrace with serves a similar purpose.

To see everything your node application is doing, you invoke it with:

$ strace -f node app.js

The output can be quite overwhelming. You can either filter the output with other command line tools like grep or you can use the builtin -e switch, which allows you to filter on pre-defined system calls.

For instance, this will output all system calls your app makes to open files:

$ strace -e open node app.js

Likewise, to see all network related calls your app makes, you can issue this command:

$ strace -e network node app.js

Using strace opens your eyes to exactly what goes on under the hood of your application or its runtime (node in this case). As with all Unix commands, the full documentation is available in the man pages, man strace.

Happy debugging!