Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 1 | #!/bin/sh |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 2 | |
Dmitry V. Levin | 20f6b54 | 2012-03-25 21:04:57 +0000 | [diff] [blame] | 3 | show_usage() |
| 4 | { |
| 5 | cat <<__EOF__ |
Dmitry V. Levin | 63c5e63 | 2012-03-10 16:10:06 +0000 | [diff] [blame] | 6 | Usage: ${0##*/} STRACE_LOG |
| 7 | |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 8 | Finds all STRACE_LOG.PID files, adds PID prefix to every line, |
| 9 | then combines and sorts them, and prints result to standard output. |
| 10 | |
| 11 | It is assumed that STRACE_LOGs were produced by strace with -tt[t] |
Dmitry V. Levin | 63c5e63 | 2012-03-10 16:10:06 +0000 | [diff] [blame] | 12 | option which prints timestamps (otherwise sorting won't do any good). |
| 13 | __EOF__ |
Dmitry V. Levin | 20f6b54 | 2012-03-25 21:04:57 +0000 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | if [ $# -ne 1 ]; then |
| 17 | show_usage >&2 |
Dmitry V. Levin | 63c5e63 | 2012-03-10 16:10:06 +0000 | [diff] [blame] | 18 | exit 1 |
Dmitry V. Levin | 20f6b54 | 2012-03-25 21:04:57 +0000 | [diff] [blame] | 19 | elif [ "$1" = '--help' ]; then |
| 20 | show_usage |
| 21 | exit 0 |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 22 | fi |
| 23 | |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 24 | logfile=$1 |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 25 | |
| 26 | for file in "$logfile".*; do |
Dmitry V. Levin | 63c5e63 | 2012-03-10 16:10:06 +0000 | [diff] [blame] | 27 | [ -f "$file" ] || continue |
Dmitry V. Levin | 030d555 | 2012-03-26 12:10:01 +0000 | [diff] [blame] | 28 | suffix=${file#"$logfile".} |
Dmitry V. Levin | 20f6b54 | 2012-03-25 21:04:57 +0000 | [diff] [blame] | 29 | [ "$suffix" -gt 0 ] 2> /dev/null || |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 30 | continue |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 31 | pid=$(printf "%-5s" $suffix) |
Dmitry V. Levin | 63c5e63 | 2012-03-10 16:10:06 +0000 | [diff] [blame] | 32 | # Some strace logs have last line which is not '\n' terminated, |
| 33 | # so add extra newline to every file. |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 34 | # grep -v '^$' removes empty lines which may result. |
Dmitry V. Levin | 63c5e63 | 2012-03-10 16:10:06 +0000 | [diff] [blame] | 35 | sed "s/^/$pid /" < "$file" |
| 36 | echo |
Denys Vlasenko | da3657d | 2012-03-09 13:43:44 +0100 | [diff] [blame] | 37 | done \ |
Dmitry V. Levin | 20f6b54 | 2012-03-25 21:04:57 +0000 | [diff] [blame] | 38 | | sort -s -k2,2 | grep -v '^$' |
| 39 | |
| 40 | rc=$? |
| 41 | [ $rc -eq 1 ] && |
| 42 | echo >&2 "${0##*/}: $logfile: strace output not found" |
| 43 | exit $rc |