Building strace-plus
 strace+ is an improved version of strace that collects stack traces associated with each system call. Since system calls require an expensive user-kernel context switch, they are often sources of performance bottlenecks. strace+ allows programmers to do more detailed system call profiling and determine, say, which call sites led to costly syscalls and thus have potential for optimization.
strace+ is an improved version of strace that collects stack traces associated with each system call. Since system calls require an expensive user-kernel context switch, they are often sources of performance bottlenecks. strace+ allows programmers to do more detailed system call profiling and determine, say, which call sites led to costly syscalls and thus have potential for optimization.
strace vs strace+
Build Pre-requisites
- binutils
- autoconf
- gdb
- make
- gcc-c++
- gcc
- gcc-x86_64-linux-gnu
- glibc-static
- python
Compile and Build strace+
- Check out the source code from Git (requires git >= 1.6.6)$ git clone https://code.google.com/p/strace-plus/ 
- Compile strace+$ cd strace-plus/ $ autoreconf -f -i $ ./configure $ make $ cp strace strace+ 
Compile a "hello world" test program
- Create a file named hello.c. hello.c is a simple program that makes four write system calls via printf statements:#include void bar() { printf("bar\n"); printf("bar again\n"); } void foo() { printf("foo\n"); bar(); } int main() { printf("Hello world\n"); foo(); return 0; } 
- Compile it:$ gcc hello.c -o hello 
- Test: $ ./hello 
- Run strace+on the hello executable to generate a trace file named hello.out.$ ./strace+ -o hello.out ./hello 
- Post-process hello.outto print out a list of system calls each augmented with stack tracespython scripts/pretty_print_strace_out.py hello.out --trace 
Build Statically
I like to always try and compile tools statically if possible.  Especially in a case like this where you don't want strace+ to replace strace.
$ cd strace-plus/ $ export CFLAGS="-Os -fomit-frame-pointer -static -static-libgcc -ffunction-sections -fdata-sections -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -Wl,--gc-sections -Wl,-Map=strace.mapfile" $ autoreconf -i -f $ ./configure $ make CFLAGS="$CFLAGS" $ cp strace strace+
# Normal strace $ file /usr/bin/strace /usr/bin/strace: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped # Static strace-plus $ file strace+ strace+: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, not stripped
Bash Aliases Functions
Useful to stick in your .bash_profile
Alias: enhanced strace
alias strace='command strace -fq -s1000 -e trace=all 2>&1'
Alias: trace file calls
alias stracef='command strace -fq -s1000 -e trace=file 2>&1'
Function: tputtrace
function tputtrace ()
{
  ( 2>&2 strace -s5000 -e write tput $1 2>&1 )  | tee -a /dev/stderr | grep --color=always -o '"[^"]*"';
}
See Also
vistrace: a visualization of strace
Comments