* strace-log-merge (max_suffix_length): New variable.
(iterate_logfiles, process_suffix, process_logfile): New functions.
Use them to choose the optimum width for pid column.
* NEWS: Mention this enhancement.
* tests/strace-log-merge-suffix.test: New test.
* tests/Makefile.am (MISC_TESTS): Add it.
* Enhanced xlat styles support configured by -X option.
* Enhanced decoding of bpf syscall.
* Enhanced decoding of PTRACE_PEEKUSER and PTRACE_POKEUSER on hppa.
+ * Enhanced pid formatting in strace-log-merge output.
* Wired up kexec_file_load and rseq syscalls on aarch64, arc, metag, nios2,
or1k, riscv, and tile architectures.
* Updated lists of BPF_*, BTRFS_*, FAN_*, IFLA_*, KERN_*, KVM_CAP_*, NDA_*,
logfile=$1
-for file in "$logfile".*; do
- [ -f "$file" ] || continue
- suffix=${file#"$logfile".}
- [ "$suffix" -gt 0 ] 2> /dev/null ||
- continue
- pid=$(printf "%-5s" $suffix)
+iterate_logfiles()
+{
+ local file suffix
+
+ for file in "$logfile".*; do
+ [ -f "$file" ] || continue
+ suffix=${file#"$logfile".}
+ [ "$suffix" -gt 0 ] 2> /dev/null ||
+ continue
+ "$@" "$suffix" "$file"
+ done
+}
+
+max_suffix_length=0
+process_suffix()
+{
+ local suffix len
+ suffix="$1"; shift
+
+ len=${#suffix}
+ if [ $len -gt $max_suffix_length ]; then
+ max_suffix_length=$len
+ fi
+}
+
+process_logfile()
+{
+ local suffix file pid
+ suffix="$1"; shift
+ file="$1"; shift
+
+ pid=$(printf "%-*s" $max_suffix_length $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.
+ # Empty lines are removed later.
sed -n "s/^\($dd:\)\?\($dd:\)\?\($ds\.\)\?$ds /\2\4\6\7 $pid \0/p" < "$file"
echo
-done |
+}
+
+iterate_logfiles process_suffix
+
+[ $max_suffix_length -gt 0 ] || {
+ echo >&2 "${0##*/}: $logfile: strace output not found"
+ exit 1
+}
+
+iterate_logfiles process_logfile |
sort -s -n -k1,1 |
sed -n 's/^[0-9][0-9]* //p' |
grep -v '^$'
strace-V.test \
strace-ff.test \
strace-log-merge-error.test \
+ strace-log-merge-suffix.test \
strace-r.test \
strace-t.test \
strace-tt.test \
--- /dev/null
+#!/bin/sh
+#
+# Check strace-log-merge pid formatting.
+#
+# Copyright (c) 2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+rm -f -- "$LOG".[0-9]*
+
+echo '3456789012.345678 +++ exited with 3 +++' > "$LOG".4294967295
+echo '1234567890.123456 +++ exited with 2 +++' > "$LOG".65535
+echo '2345678901.234567 +++ exited with 1 +++' > "$LOG".1
+
+cat > "$EXP" <<'EOF'
+65535 1234567890.123456 +++ exited with 2 +++
+1 2345678901.234567 +++ exited with 1 +++
+4294967295 3456789012.345678 +++ exited with 3 +++
+EOF
+
+"$srcdir"/../strace-log-merge "$LOG" > "$OUT" 2> "$LOG" ||
+ dump_log_and_fail_with 'strace-log-merge failed'
+
+match_diff "$OUT" "$EXP" 'strace-log-merge output mismatch'
+
+rm -f -- "$LOG".[0-9]*