blob: a8efb9df92ce95c78b9d1d663c6983cabc07dd6e [file] [log] [blame]
Denys Vlasenkoda3657d2012-03-09 13:43:44 +01001#!/bin/sh
Denys Vlasenkoda3657d2012-03-09 13:43:44 +01002
3if test $# = 0; then
4 echo "Usage: ${0##*/} STRACE_LOG"
5 echo
6 echo "\
7Finds all STRACE_LOG.PID files, adds PID prefix to every line,
8then combines and sorts them, and prints result to standard output.
9
10It is assumed that STRACE_LOGs were produced by strace with -tt[t]
11option which prints timestamps (otherwise sorting won't do any good).\
12"
13 exit
14fi
15
16is_numeric() {
17 # Remove digits. If something remains,
18 # then $1 is not a number
19
20 u=$1
21 test "$u" || return 1 # "" is not a number
22
23 while true; do
24 v=${u#[0123456789]} # remove one digit
25 test "$v" || return 0 # we removed all chars. ok
26 test "$v" = "$u" && return 1 # we have non-digit. bad
27 u=$v
28 done
29}
30
31logfile=$1
32pfxlen=${#1}
33
34for file in "$logfile".*; do
35 suffix=${file:1+$pfxlen}
36 is_numeric "$suffix" || {
37 echo "Skipped file '$file' (bad suffix)" >&2
38 continue
39 }
40 pid=$(printf "%-5s" $suffix)
41 # Some strace logs have last line which is not '\n' terminated.
42 # 's/$/\n/' adds extra newlines to every line.
43 # grep -v '^$' removes empty lines which may result.
44 sed -e "s/^/$pid /" -e 's/$/\n/' <"$file"
45done \
46| grep -v '^$' | sort -k2