summaryrefslogtreecommitdiff
path: root/strace-log-merge
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-03-09 14:21:59 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-03-09 14:21:59 +0100
commit796f6e82b4fa61c8775da7ec8bbc57f1d05c9929 (patch)
tree36574011b9ef475e72e093f7055deb880f4fe73b /strace-log-merge
parentda3657d4e70ee3ac7986d9769e2ee20c93e8044f (diff)
downloadstrace-796f6e82b4fa61c8775da7ec8bbc57f1d05c9929.tar.gz
install strace-log-merge by "make install"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'strace-log-merge')
-rwxr-xr-xstrace-log-merge46
1 files changed, 46 insertions, 0 deletions
diff --git a/strace-log-merge b/strace-log-merge
new file mode 100755
index 000000000..a8efb9df9
--- /dev/null
+++ b/strace-log-merge
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+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