From f9dba1be6f2f717d76f49433d3554eadededf591 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Tue, 4 Sep 2018 19:20:36 +0200 Subject: [PATCH] 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 --- count.c | 13 +++++++++++++ strace.1.in | 1 + strace.c | 3 ++- tests/strace-S.test | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/count.c b/count.c index 57af23f8..a1cdf823 100644 --- a/count.c +++ b/count.c @@ -86,6 +86,17 @@ count_cmp(const void *a, const void *b) return (m < n) ? 1 : (m > n) ? -1 : 0; } +static int +error_cmp(const void *a, const void *b) +{ + const unsigned int *a_int = a; + const unsigned int *b_int = b; + unsigned int m = counts[*a_int].errors; + unsigned int n = counts[*b_int].errors; + + return (m < n) ? 1 : (m > n) ? -1 : 0; +} + static int (*sortfun)(const void *, const void *); void @@ -100,6 +111,8 @@ set_sortby(const char *sortby) { time_cmp, "total_time" }, { count_cmp, "calls" }, { count_cmp, "count" }, + { error_cmp, "error" }, + { error_cmp, "errors" }, { syscall_cmp, "name" }, { syscall_cmp, "syscall" }, { syscall_cmp, "syscall_name" }, diff --git a/strace.1.in b/strace.1.in index 1437bb72..3ac46bac 100644 --- a/strace.1.in +++ b/strace.1.in @@ -796,6 +796,7 @@ Sort the output of the histogram printed by the option by the specified criterion. Legal values are .BR time " (or " time_total " or " total_time ), .BR calls " (or " count ), +.BR errors " (or " error ), .BR name " (or " syscall " or " syscall_name ), and .BR nothing " (or " none ); diff --git a/strace.c b/strace.c index 59097e14..8d9e465c 100644 --- a/strace.c +++ b/strace.c @@ -276,7 +276,8 @@ Statistics:\n\ summary\n\ -C like -c but also print regular output\n\ -O overhead set overhead for tracing syscalls to OVERHEAD usecs\n\ - -S sortby sort syscall counts by: time, calls, name, nothing (default %s)\n\ + -S sortby sort syscall counts by: time, calls, errors, name, nothing\n\ + (default %s)\n\ -w summarise syscall latency (default is system time)\n\ \n\ Filtering:\n\ diff --git a/tests/strace-S.test b/tests/strace-S.test index 25f095e2..55a01c49 100755 --- a/tests/strace-S.test +++ b/tests/strace-S.test @@ -43,3 +43,7 @@ for s in name syscall syscall_name; do test_c "$s" '' \ '/^[[:space:]]+[0-9]/ s/^'"$c$c$c$c"'([[:space:]]+[0-9]+)?'"$c"'$/\6/p' done +for s in error errors; do + test_c "$s" '-n -r' \ + '/^[[:space:]]+[0-9]/ s/^'"$c$c$c$c"'([[:space:]]+([0-9]+))?'"$c"'$/\6/p' +done -- 2.40.0