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