3 # This script processes strace -ff -tt output. It merges the contents of all
4 # STRACE_LOG.PID files and sorts them, printing result on the standard output.
6 # Copyright (c) 2012-2019 The strace developers.
8 # SPDX-License-Identifier: LGPL-2.1-or-later
13 Usage: ${0##*/} STRACE_LOG
15 Finds all STRACE_LOG.PID files, adds PID prefix to every line,
16 then combines and sorts them, and prints result to standard output.
18 It is assumed that STRACE_LOGs were produced by strace with -tt[t]
19 option which prints timestamps (otherwise sorting won't do any good).
29 elif [ "$1" = '--help' ]; then
40 for file in "$logfile".*; do
41 [ -f "$file" ] || continue
42 suffix=${file#"$logfile".}
43 [ "$suffix" -gt 0 ] 2> /dev/null ||
45 "$@" "$suffix" "$file"
56 if [ $len -gt $max_suffix_length ]; then
57 max_suffix_length=$len
67 pid=$(printf "%-*s" $max_suffix_length $suffix)
68 # Some strace logs have last line which is not '\n' terminated,
69 # so add extra newline to every file.
70 # Empty lines are removed later.
71 sed -n "s/^\($dd:\)\?\($dd:\)\?\($ds\.\)\?$ds /\2\4\6\7 $pid \0/p" < "$file"
75 iterate_logfiles process_suffix
77 [ $max_suffix_length -gt 0 ] || {
78 echo >&2 "${0##*/}: $logfile: strace output not found"
82 iterate_logfiles process_logfile |
84 sed -n 's/^[0-9][0-9]* //p' |
89 echo >&2 "${0##*/}: $logfile: strace output not found"