diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2012-03-10 16:10:06 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2012-03-10 16:10:06 +0000 |
commit | 63c5e63f2ceadbecbb98b4b30a2f255270e00357 (patch) | |
tree | c05a8e98c81f47f687250bc3b974aa6c0b282788 /strace-log-merge | |
parent | d92029ef88a62ee8b4efec091ff76fe859a3fbbb (diff) | |
download | strace-63c5e63f2ceadbecbb98b4b30a2f255270e00357.tar.gz strace-63c5e63f2ceadbecbb98b4b30a2f255270e00357.tar.bz2 strace-63c5e63f2ceadbecbb98b4b30a2f255270e00357.tar.xz |
strace-log-merge: cleanup
* strace-log-merge: Redirect usage to stderr, make the check
for numeric suffix simpler.
Diffstat (limited to 'strace-log-merge')
-rwxr-xr-x | strace-log-merge | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/strace-log-merge b/strace-log-merge index a8efb9d..9dc03b8 100755 --- a/strace-log-merge +++ b/strace-log-merge @@ -1,46 +1,33 @@ #!/bin/sh if test $# = 0; then - echo "Usage: ${0##*/} STRACE_LOG" - echo - echo "\ + cat >&2 <<__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).\ -" - exit +option which prints timestamps (otherwise sorting won't do any good). +__EOF__ + exit 1 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 + [ -f "$file" ] || continue suffix=${file:1+$pfxlen} - is_numeric "$suffix" || { + [ "$suffix" -gt 0 ] 2> /dev/null || { 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. + # 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 -e "s/^/$pid /" -e 's/$/\n/' <"$file" + sed "s/^/$pid /" < "$file" + echo done \ | grep -v '^$' | sort -k2 |