Browse Source

count: add ability to sort on errors field

For completeness.

* count.c (error_cmp): New function.
(set_sortby): Add sort keys for errors field.
* strace.1.in (.SH OPTIONS) <-S>: Document it.
* strace.c (usage): Likewise.
* tests/strace-S.test: Check it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Eugene Syromyatnikov 1 year ago
parent
commit
f9dba1be6f
4 changed files with 20 additions and 1 deletions
  1. 13
    0
      count.c
  2. 1
    0
      strace.1.in
  3. 2
    1
      strace.c
  4. 4
    0
      tests/strace-S.test

+ 13
- 0
count.c View File

@@ -86,6 +86,17 @@ count_cmp(const void *a, const void *b)
86 86
 	return (m < n) ? 1 : (m > n) ? -1 : 0;
87 87
 }
88 88
 
89
+static int
90
+error_cmp(const void *a, const void *b)
91
+{
92
+	const unsigned int *a_int = a;
93
+	const unsigned int *b_int = b;
94
+	unsigned int m = counts[*a_int].errors;
95
+	unsigned int n = counts[*b_int].errors;
96
+
97
+	return (m < n) ? 1 : (m > n) ? -1 : 0;
98
+}
99
+
89 100
 static int (*sortfun)(const void *, const void *);
90 101
 
91 102
 void
@@ -100,6 +111,8 @@ set_sortby(const char *sortby)
100 111
 		{ time_cmp,	"total_time" },
101 112
 		{ count_cmp,	"calls" },
102 113
 		{ count_cmp,	"count" },
114
+		{ error_cmp,	"error" },
115
+		{ error_cmp,	"errors" },
103 116
 		{ syscall_cmp,	"name" },
104 117
 		{ syscall_cmp,	"syscall" },
105 118
 		{ syscall_cmp,	"syscall_name" },

+ 1
- 0
strace.1.in View File

@@ -796,6 +796,7 @@ Sort the output of the histogram printed by the
796 796
 option by the specified criterion.  Legal values are
797 797
 .BR time " (or " time_total " or " total_time ),
798 798
 .BR calls " (or " count ),
799
+.BR errors " (or " error ),
799 800
 .BR name " (or " syscall " or " syscall_name ),
800 801
 and
801 802
 .BR nothing " (or " none );

+ 2
- 1
strace.c View File

@@ -276,7 +276,8 @@ Statistics:\n\
276 276
                  summary\n\
277 277
   -C             like -c but also print regular output\n\
278 278
   -O overhead    set overhead for tracing syscalls to OVERHEAD usecs\n\
279
-  -S sortby      sort syscall counts by: time, calls, name, nothing (default %s)\n\
279
+  -S sortby      sort syscall counts by: time, calls, errors, name, nothing\n\
280
+                 (default %s)\n\
280 281
   -w             summarise syscall latency (default is system time)\n\
281 282
 \n\
282 283
 Filtering:\n\

+ 4
- 0
tests/strace-S.test View File

@@ -43,3 +43,7 @@ for s in name syscall syscall_name; do
43 43
 	test_c "$s" '' \
44 44
 		'/^[[:space:]]+[0-9]/ s/^'"$c$c$c$c"'([[:space:]]+[0-9]+)?'"$c"'$/\6/p'
45 45
 done
46
+for s in error errors; do
47
+	test_c "$s" '-n -r' \
48
+		'/^[[:space:]]+[0-9]/ s/^'"$c$c$c$c"'([[:space:]]+([0-9]+))?'"$c"'$/\6/p'
49
+done

Loading…
Cancel
Save