strace-plusstrace+ 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.

Table of Contents

  1. Introduction
    1. strace vs strace+
    2. Build Pre-requisites
    3. Compile and Build strace+
    4. Compile a "hello world" test program
    5. Build Statically
    6. Bash Aliases Functions
      1. Alias: enhanced strace
      2. Alias: trace file calls
      3. Function: tputtrace
    7. See Also

strace vs strace+

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+

  1. Check out the source code from Git (requires git >= 1.6.6)
    $ git clone https://code.google.com/p/strace-plus/
  2. Compile strace+
    $ cd strace-plus/
    $ autoreconf -f -i
    $ ./configure
    $ make
    $ cp strace strace+

Compile a "hello world" test program

  1. 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;
    }
  2. Compile it:
    $ gcc hello.c -o hello
  3. Test:
    $ ./hello
  4. Run strace+ on the hello executable to generate a trace file named hello.out.
    $ ./strace+ -o hello.out ./hello
  5. Post-process hello.out to print out a list of system calls each augmented with stack traces
    python 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

Building strace-plus - AskApache

Charles Torvalds
26 Jun 2013

gcc, linux, strace

  • Site Map WireShark GNU Non-GNU Tor Project cURL TLDP - Documentation
  • Htaccess Files Hacking Htaccess Javascript Linux Optimization PHP Security Shell Scripting WordPress
  • Base64 Image Converter Raw HTTP Header Debugger Graphical ASCII Text Generator Mac Address Vendor Lookup Who Am I – Your IP Information Request Method Security Scanner .htpasswd file Generator Compress CSS DNS Tracer
Copyright © 2025 AskApache
  • Site Map
  • Htaccess Files
  • Hacking
  • Htaccess
  • Javascript
  • Linux
  • Optimization
  • PHP
  • Security
  • Shell Scripting
  • WordPress
  • Base64 Image Converter
  • Raw HTTP Header Debugger
  • Graphical ASCII Text Generator
  • Mac Address Vendor Lookup
  • Who Am I – Your IP Information
  • Request Method Security Scanner
  • .htpasswd file Generator
  • Compress CSS
  • DNS Tracer
Exit mobile version