blob: 8ab24091d4240fbc70f6b92591972506991ac5ac [file] [log] [blame]
Denys Vlasenkoda3657d2012-03-09 13:43:44 +01001#!/bin/sh
Denys Vlasenkoda3657d2012-03-09 13:43:44 +01002
Dmitry V. Levin20f6b542012-03-25 21:04:57 +00003show_usage()
4{
5 cat <<__EOF__
Dmitry V. Levin63c5e632012-03-10 16:10:06 +00006Usage: ${0##*/} STRACE_LOG
7
Denys Vlasenkoda3657d2012-03-09 13:43:44 +01008Finds all STRACE_LOG.PID files, adds PID prefix to every line,
9then combines and sorts them, and prints result to standard output.
10
11It is assumed that STRACE_LOGs were produced by strace with -tt[t]
Dmitry V. Levin63c5e632012-03-10 16:10:06 +000012option which prints timestamps (otherwise sorting won't do any good).
13__EOF__
Dmitry V. Levin20f6b542012-03-25 21:04:57 +000014}
15
16if [ $# -ne 1 ]; then
17 show_usage >&2
Dmitry V. Levin63c5e632012-03-10 16:10:06 +000018 exit 1
Dmitry V. Levin20f6b542012-03-25 21:04:57 +000019elif [ "$1" = '--help' ]; then
20 show_usage
21 exit 0
Denys Vlasenkoda3657d2012-03-09 13:43:44 +010022fi
23
Denys Vlasenkoda3657d2012-03-09 13:43:44 +010024logfile=$1
Denys Vlasenkoda3657d2012-03-09 13:43:44 +010025
26for file in "$logfile".*; do
Dmitry V. Levin63c5e632012-03-10 16:10:06 +000027 [ -f "$file" ] || continue
Dmitry V. Levin030d5552012-03-26 12:10:01 +000028 suffix=${file#"$logfile".}
Dmitry V. Levin20f6b542012-03-25 21:04:57 +000029 [ "$suffix" -gt 0 ] 2> /dev/null ||
Denys Vlasenkoda3657d2012-03-09 13:43:44 +010030 continue
Denys Vlasenkoda3657d2012-03-09 13:43:44 +010031 pid=$(printf "%-5s" $suffix)
Dmitry V. Levin63c5e632012-03-10 16:10:06 +000032 # Some strace logs have last line which is not '\n' terminated,
33 # so add extra newline to every file.
Denys Vlasenkoda3657d2012-03-09 13:43:44 +010034 # grep -v '^$' removes empty lines which may result.
Dmitry V. Levin63c5e632012-03-10 16:10:06 +000035 sed "s/^/$pid /" < "$file"
36 echo
Denys Vlasenkoda3657d2012-03-09 13:43:44 +010037done \
Dmitry V. Levin20f6b542012-03-25 21:04:57 +000038| sort -s -k2,2 | grep -v '^$'
39
40rc=$?
41[ $rc -eq 1 ] &&
42 echo >&2 "${0##*/}: $logfile: strace output not found"
43exit $rc