Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strace-log-merge 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. #
  3. # This script processes strace -ff -tt output. It merges the contents of all
  4. # STRACE_LOG.PID files and sorts them, printing result on the standard output.
  5. #
  6. # Copyright (c) 2012-2018 The strace developers.
  7. #
  8. # SPDX-License-Identifier: LGPL-2.1-or-later
  9. show_usage()
  10. {
  11. cat <<__EOF__
  12. Usage: ${0##*/} STRACE_LOG
  13. Finds all STRACE_LOG.PID files, adds PID prefix to every line,
  14. then combines and sorts them, and prints result to standard output.
  15. It is assumed that STRACE_LOGs were produced by strace with -tt[t]
  16. option which prints timestamps (otherwise sorting won't do any good).
  17. __EOF__
  18. }
  19. dd='\([0-9][0-9]\)'
  20. ds='\([0-9][0-9]*\)'
  21. if [ $# -ne 1 ]; then
  22. show_usage >&2
  23. exit 1
  24. elif [ "$1" = '--help' ]; then
  25. show_usage
  26. exit 0
  27. fi
  28. logfile=$1
  29. for file in "$logfile".*; do
  30. [ -f "$file" ] || continue
  31. suffix=${file#"$logfile".}
  32. [ "$suffix" -gt 0 ] 2> /dev/null ||
  33. continue
  34. pid=$(printf "%-5s" $suffix)
  35. # Some strace logs have last line which is not '\n' terminated,
  36. # so add extra newline to every file.
  37. # grep -v '^$' removes empty lines which may result.
  38. sed -n "s/^\($dd:\)\?\($dd:\)\?\($ds\.\)\?$ds /\2\4\6\7 $pid \0/p" < "$file"
  39. echo
  40. done \
  41. | sort -s -n -k1,1 | sed -n 's/^[0-9][0-9]* //p'
  42. rc=$?
  43. [ $rc -eq 1 ] &&
  44. echo >&2 "${0##*/}: $logfile: strace output not found"
  45. exit $rc