]> granicus.if.org Git - strace/blob - strace-log-merge
Fix lame kernel version checking code
[strace] / strace-log-merge
1 #!/bin/sh
2
3 if test $# = 0; then
4         cat >&2 <<__EOF__
5 Usage: ${0##*/} STRACE_LOG
6
7 Finds all STRACE_LOG.PID files, adds PID prefix to every line,
8 then combines and sorts them, and prints result to standard output.
9
10 It is assumed that STRACE_LOGs were produced by strace with -tt[t]
11 option which prints timestamps (otherwise sorting won't do any good).
12 __EOF__
13         exit 1
14 fi
15
16 logfile=$1
17 pfxlen=${#1}
18
19 for file in "$logfile".*; do
20         [ -f "$file" ] || continue
21         suffix=${file:1+$pfxlen}
22         [ "$suffix" -gt 0 ] 2> /dev/null || {
23                 echo "Skipped file '$file' (bad suffix)" >&2
24                 continue
25         }
26         pid=$(printf "%-5s" $suffix)
27         # Some strace logs have last line which is not '\n' terminated,
28         # so add extra newline to every file.
29         # grep -v '^$' removes empty lines which may result.
30         sed "s/^/$pid /" < "$file"
31         echo
32 done \
33 | grep -v '^$' | sort -k2