Feature requests: list of PIDS, and all threads

Alexander Kriegisch kriegaex at freetz.org
Thu Mar 8 12:52:10 UTC 2012


Denys Vlasenko, 08.03.2012 12:32:
> On 03/07/2012 08:59 PM, George Spelvin wrote:
>> With multi-process and multi-threaded programs becoming more common,
>> there are a couple of things I wish strace gave me:
>>
>> 1) Some way to supply a *list* of pids to be traced, without having to
>>     prefix each with "-p".  This would make it much easier to paste
>>     in the output of "pgrep" or the like.
>>
>>     Two options come to mind:
>>     -P means "all bare arguments are pids"; the case of mixing
>>        pids and a commnd line process is somewhat uncommon.
>>     -p takes a whitespace-separated list of pids.  So I could
>>        use -p "`pgrep foo`".
> 
> I guess we can support -p PID1,PID2 _and_ -p "PID1 PID2".
> Why not?
> 
>> 2) A simple way to trace all threads of a process.  strace doesn't really
>>     take process IDs but thread IDs, so if a process has multiple threads,
>>     only the primary process gets traced.  I'd like an easy way to say
>>     "what the heck is firefox doing?" and get all the threads.
>>     (Once again, this is working around a limitation of pgrep.)
> 
> The code to do so is there (-p PID -f would do what you want even today -
> but it will also follow forks which you didn't ask for).
> We only need an option to indicate this. -T and -t are taken. -P is taken too.
> We are running out of alphabet! :)

Why is -P taken? Because of (1)? But you said that "-p" could also
support multiple pids, so theoretically -P would be available. Other
than that, if we have -tt and -ff, we could also use -pp, couldn't we? ;-)

>> 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.

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).




More information about the Strace-devel mailing list