Browse Source

strace-log-merge: enhance pid formatting

* 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.
Dmitry V. Levin 8 months ago
parent
commit
b734e8c1e8
4 changed files with 74 additions and 8 deletions
  1. 1
    0
      NEWS
  2. 43
    8
      strace-log-merge
  3. 1
    0
      tests/Makefile.am
  4. 29
    0
      tests/strace-log-merge-suffix.test

+ 1
- 0
NEWS View File

@@ -20,6 +20,7 @@ Noteworthy changes in release ?.?? (????-??-??)
20 20
   * Enhanced xlat styles support configured by -X option.
21 21
   * Enhanced decoding of bpf syscall.
22 22
   * Enhanced decoding of PTRACE_PEEKUSER and PTRACE_POKEUSER on hppa.
23
+  * Enhanced pid formatting in strace-log-merge output.
23 24
   * Wired up kexec_file_load and rseq syscalls on aarch64, arc, metag, nios2,
24 25
     or1k, riscv, and tile architectures.
25 26
   * Updated lists of BPF_*, BTRFS_*, FAN_*, IFLA_*, KERN_*, KVM_CAP_*, NDA_*,

+ 43
- 8
strace-log-merge View File

@@ -33,18 +33,53 @@ fi
33 33
 
34 34
 logfile=$1
35 35
 
36
-for file in "$logfile".*; do
37
-	[ -f "$file" ] || continue
38
-	suffix=${file#"$logfile".}
39
-	[ "$suffix" -gt 0 ] 2> /dev/null ||
40
-		continue
41
-	pid=$(printf "%-5s" $suffix)
36
+iterate_logfiles()
37
+{
38
+	local file suffix
39
+
40
+	for file in "$logfile".*; do
41
+		[ -f "$file" ] || continue
42
+		suffix=${file#"$logfile".}
43
+		[ "$suffix" -gt 0 ] 2> /dev/null ||
44
+			continue
45
+		"$@" "$suffix" "$file"
46
+	done
47
+}
48
+
49
+max_suffix_length=0
50
+process_suffix()
51
+{
52
+	local suffix len
53
+	suffix="$1"; shift
54
+
55
+	len=${#suffix}
56
+	if [ $len -gt $max_suffix_length ]; then
57
+		max_suffix_length=$len
58
+	fi
59
+}
60
+
61
+process_logfile()
62
+{
63
+	local suffix file pid
64
+	suffix="$1"; shift
65
+	file="$1"; shift
66
+
67
+	pid=$(printf "%-*s" $max_suffix_length $suffix)
42 68
 	# Some strace logs have last line which is not '\n' terminated,
43 69
 	# so add extra newline to every file.
44
-	# grep -v '^$' removes empty lines which may result.
70
+	# Empty lines are removed later.
45 71
 	sed -n "s/^\($dd:\)\?\($dd:\)\?\($ds\.\)\?$ds /\2\4\6\7 $pid \0/p" < "$file"
46 72
 	echo
47
-done |
73
+}
74
+
75
+iterate_logfiles process_suffix
76
+
77
+[ $max_suffix_length -gt 0 ] || {
78
+	echo >&2 "${0##*/}: $logfile: strace output not found"
79
+	exit 1
80
+}
81
+
82
+iterate_logfiles process_logfile |
48 83
 	sort -s -n -k1,1 |
49 84
 	sed -n 's/^[0-9][0-9]* //p' |
50 85
 	grep -v '^$'

+ 1
- 0
tests/Makefile.am View File

@@ -342,6 +342,7 @@ MISC_TESTS = \
342 342
 	strace-V.test \
343 343
 	strace-ff.test \
344 344
 	strace-log-merge-error.test \
345
+	strace-log-merge-suffix.test \
345 346
 	strace-r.test \
346 347
 	strace-t.test \
347 348
 	strace-tt.test \

+ 29
- 0
tests/strace-log-merge-suffix.test View File

@@ -0,0 +1,29 @@
1
+#!/bin/sh
2
+#
3
+# Check strace-log-merge pid formatting.
4
+#
5
+# Copyright (c) 2019 The strace developers.
6
+# All rights reserved.
7
+#
8
+# SPDX-License-Identifier: GPL-2.0-or-later
9
+
10
+. "${srcdir=.}/init.sh"
11
+
12
+rm -f -- "$LOG".[0-9]*
13
+
14
+echo '3456789012.345678 +++ exited with 3 +++' > "$LOG".4294967295
15
+echo '1234567890.123456 +++ exited with 2 +++' > "$LOG".65535
16
+echo '2345678901.234567 +++ exited with 1 +++' > "$LOG".1
17
+
18
+cat > "$EXP" <<'EOF'
19
+65535      1234567890.123456 +++ exited with 2 +++
20
+1          2345678901.234567 +++ exited with 1 +++
21
+4294967295 3456789012.345678 +++ exited with 3 +++
22
+EOF
23
+
24
+"$srcdir"/../strace-log-merge "$LOG" > "$OUT" 2> "$LOG" ||
25
+	dump_log_and_fail_with 'strace-log-merge failed'
26
+
27
+match_diff "$OUT" "$EXP" 'strace-log-merge output mismatch'
28
+
29
+rm -f -- "$LOG".[0-9]*

Loading…
Cancel
Save