Skip to content
Advertisement

Collect and sum statistics of `strace` commands?

I know that I can runstrace -c ls to collect system call statistics on the ls executable. However, I want to run the command strace -c {some executable here} mulitiple times over different executables, merge the individual results, and then write to a single file.

I want to merge the ‘syscall’ and the ‘calls’ columns. So for example, if ls makes 19 mmap system calls and tr makes 11 mmap system calls, I would like to merge those results so that the final statistics simply show 30 mmap system calls overall in some file. Moreover, if a system call only appears in one executable, it should still be included in the final results.

How can I do that?

Advertisement

Answer

Using grep to find mmap calls, which are then piped to datamash (on Debian variants, install withapt install datamash) to group by column 5, (i.e. mmap), and sum column 4:

JavaScript

Output:

JavaScript

  1. Example showing what similar data looked like before it was summed:

    JavaScript
  2. The -s switch lets datamash group, sort, and separately sum all the syscalls:

    JavaScript

    (Note that the strace output needs cleaning, which is done by cut, sed, et al…)

    Output:

    JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement