b053dd53ed
Employing strace -ttt for the logs destined to be fed to strace-log-merge is ultimately the best solution except for the logs that pass the following dates: Thu Jan 1 00:00:09 UTC 1970 Thu Jan 1 00:01:39 UTC 1970 Thu Jan 1 00:16:39 UTC 1970 Thu Jan 1 02:46:39 UTC 1970 Fri Jan 2 03:46:39 UTC 1970 Mon Jan 12 13:46:39 UTC 1970 Sun Apr 26 17:46:39 UTC 1970 Sat Mar 3 09:46:39 UTC 1973 Sun Sep 9 01:46:39 UTC 2001 Sat Nov 20 17:46:39 UTC 2286 Wed Nov 16 09:46:39 UTC 5138 Fri Sep 27 01:46:39 UTC 33658 Sun May 20 17:46:39 UTC 318857 Sat Nov 7 09:46:39 UTC 3170843 Sun Jul 5 01:46:39 UTC 31690708 Sat Jan 25 17:46:39 UTC 316889355 Let's lift this limitation. * strace-log-merge: Generate numeric-only key for sorting, use sort -n option.
74 lines
2.6 KiB
Bash
Executable File
74 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# This script processes strace -ff -tt output. It merges the contents of all
|
|
# STRACE_LOG.PID files and sorts them, printing result on the standard output.
|
|
#
|
|
# Copyright (c) 2012 The strace developers.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions
|
|
# are met:
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
# 3. The name of the author may not be used to endorse or promote products
|
|
# derived from this software without specific prior written permission.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
show_usage()
|
|
{
|
|
cat <<__EOF__
|
|
Usage: ${0##*/} STRACE_LOG
|
|
|
|
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).
|
|
__EOF__
|
|
}
|
|
|
|
dd='\([0-9][0-9]\)'
|
|
ds='\([0-9][0-9]*\)'
|
|
|
|
if [ $# -ne 1 ]; then
|
|
show_usage >&2
|
|
exit 1
|
|
elif [ "$1" = '--help' ]; then
|
|
show_usage
|
|
exit 0
|
|
fi
|
|
|
|
logfile=$1
|
|
|
|
for file in "$logfile".*; do
|
|
[ -f "$file" ] || continue
|
|
suffix=${file#"$logfile".}
|
|
[ "$suffix" -gt 0 ] 2> /dev/null ||
|
|
continue
|
|
pid=$(printf "%-5s" $suffix)
|
|
# Some strace logs have last line which is not '\n' terminated,
|
|
# so add extra newline to every file.
|
|
# grep -v '^$' removes empty lines which may result.
|
|
sed -n "s/^\($dd:\)\?\($dd:\)\?\($ds\.\)\?$ds /\2\4\6\7 $pid \0/p" < "$file"
|
|
echo
|
|
done \
|
|
| sort -s -n -k1,1 | sed -n 's/^[0-9][0-9]* //p'
|
|
|
|
rc=$?
|
|
[ $rc -eq 1 ] &&
|
|
echo >&2 "${0##*/}: $logfile: strace output not found"
|
|
exit $rc
|