Feature requests: list of PIDS, and all threads

Denys Vlasenko dvlasenk at redhat.com
Fri Mar 9 12:43:21 UTC 2012


On 03/08/2012 02:47 PM, Alexander Kriegisch wrote:
>>>> 3) A third thing that would be really nice would be a "don't break system
>>>>      calls" option.  Basically, if one system call is pending when a second
>>>>      happens, DON'T display<pending...>   unless a reasonable timeout has
>>>>      elapsed; rather just defer printing anything for the first system
>>>>      call until it returns, when it can be printed on one line.
>>>
>>> Uhhuh. That would not be so easy to implement. And some people
>>> do want to know exact moment syscalls were entered/exited.
>>>
>>> -tt -ff does almost what you want. It separates logs one output file
>>> per pid. A script can be written to combine them into one file,
>>> using timestamps for ordering. Would this satisfy you?
>>
>> I am writing such a script right now, but saw on Ubuntu 11.10 (strace
>> 4.5.20) that -ff does not record PID information inside the log file,
>> only append the pid to the log file name. With my self-compiled strace
>> 4.6 on mipsel embedded platform though, the logs contain pid information
>> as first column. The NEWS document does not mention a change in log file
>> format though. Can you comment on this please? I can easily create a
>> script which supports both versions, doing different 'sed' replacements,
>> but I was just wondering why this is necessary at all.
>
> Okay, I just saw that the PIDs are only inserted into the log file if
> strace is called with multiple -p arguments, which is what I did on the
> mipsel platform. Anyway, these two cases need to be handled anyway:
>
>> Necessary 'sed' replacement in 4.5.20: insert pid after timestamp
>> (otherwise we cannot sort by timestamp).
>>
>> Necessary 'sed' replacement in 4.6: move pid from first column (before
>> timestamp) to second column (otherwise we again cannot sort by timestamp).
>
> Okay, here is the script as an attachment. Call it like this:
>
> ./strace_no_pending mc.log mc
> ./strace_no_pending test.log -p 719 -p 1010
>
> Please note:
>    - If you want the PID as first column, you need to do that *after*
>      sorting by timestamp, which would make the script more complicated.
>      I guess this is not needed.
>    - The "trap" avoids the script to be aborted before log file
>      unification if the user wants to stop strace via Ctrl-C.
>    - The pid-numbered logfiles are cleaned up after unification. If you
>      still want to keep them, remove the last command.
>
> Enjoy!

I think you should not run strace. Write a separate tool
which post process the logs. Such as this.
-- 
vda


#!/bin/sh

if test $# = 0; then
         echo "Usage: ${0##*/} STRACE_LOG"
         echo
         echo "\
Finds all STRACE_LOG.PID files, adds PID prefix to every line,
then combines and sorts them, and prints result to standard output.

It is assumed that STRACE_LOGs were produced by strace with -tt[t]
option which prints timestamps (otherwise sorting won't do any good).\
"
         exit
fi

is_numeric() {
         # Remove digits. If something remains,
         # then $1 is not a number

         u=$1
         test "$u" || return 1 # "" is not a number

         while true; do
                 v=${u#[0123456789]} # remove one digit
                 test "$v" || return 0 # we removed all chars. ok
                 test "$v" = "$u" && return 1 # we have non-digit. bad
                 u=$v
         done
}

logfile=$1
pfxlen=${#1}

for file in "$logfile".*; do
         suffix=${file:1+$pfxlen}
         is_numeric "$suffix" || {
                 echo "Skipped file '$file' (bad suffix)" >&2
                 continue
         }
         pid=$(printf "%-5s" $suffix)
         # Some strace logs have last line which is not '\n' terminated.
         # 's/$/\n/' adds extra newlines to every line.
         # grep -v '^$' removes empty lines which may result.
         sed -e "s/^/$pid /" -e 's/$/\n/' <"$file"
done \
| grep -v '^$' | sort -k2




More information about the Strace-devel mailing list