strace_log_merge: new file. Helper to merge timestamped strace -ff logs

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2012-03-09 13:43:44 +01:00
parent fd88338067
commit da3657d4e7

48
strace_log_merge Executable file
View File

@ -0,0 +1,48 @@
#!/bin/sh
#
# TODO: install alongside strace on "make install" time?
if test $# = 0; then
echo "Usage: ${0##*/} STRACE_LOG"
echo
echo "\
Finds all STRACE_LOG.PID files, adds PID prefix to every line,
then combines and sorts them, and prints result to standard output.
It is assumed that STRACE_LOGs were produced by strace with -tt[t]
option which prints timestamps (otherwise sorting won't do any good).\
"
exit
fi
is_numeric() {
# Remove digits. If something remains,
# then $1 is not a number
u=$1
test "$u" || return 1 # "" is not a number
while true; do
v=${u#[0123456789]} # remove one digit
test "$v" || return 0 # we removed all chars. ok
test "$v" = "$u" && return 1 # we have non-digit. bad
u=$v
done
}
logfile=$1
pfxlen=${#1}
for file in "$logfile".*; do
suffix=${file:1+$pfxlen}
is_numeric "$suffix" || {
echo "Skipped file '$file' (bad suffix)" >&2
continue
}
pid=$(printf "%-5s" $suffix)
# Some strace logs have last line which is not '\n' terminated.
# 's/$/\n/' adds extra newlines to every line.
# grep -v '^$' removes empty lines which may result.
sed -e "s/^/$pid /" -e 's/$/\n/' <"$file"
done \
| grep -v '^$' | sort -k2