From da3657d4e70ee3ac7986d9769e2ee20c93e8044f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 9 Mar 2012 13:43:44 +0100 Subject: [PATCH] strace_log_merge: new file. Helper to merge timestamped strace -ff logs Signed-off-by: Denys Vlasenko --- strace_log_merge | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 strace_log_merge diff --git a/strace_log_merge b/strace_log_merge new file mode 100755 index 00000000..5f96c2a4 --- /dev/null +++ b/strace_log_merge @@ -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 -- 2.50.1