Hello,

In my quest to get rid of scripts parsing strace output, I wrote this
small patch that adds a "min" and "max" column to strace -c. Could you
please consider this for inclusion?

Could you also please either tell me what's wrong with
0001-Implement-C-option-to-combine-regular-output-and-c.patch
I posted earlier that contained suggested simplifications or
include it as well?

Please CC me in reply as I am not subscribed to this list.

Thanks,
Adrien
From 2289ecdc5c2bf3c70f4aa8cb95416478372218e5 Mon Sep 17 00:00:00 2001
From: Adrien Kunysz <[email protected]>
Date: Fri, 28 Aug 2009 22:48:50 +0100
Subject: [PATCH] Add "min" and "max" columns for -c.

---
 count.c |   45 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/count.c b/count.c
index 4e272a3..0b3aa84 100644
--- a/count.c
+++ b/count.c
@@ -35,10 +35,13 @@
  *	$Id$
  */
 
+#include <limits.h>
 #include "defs.h"
 
 struct call_counts {
 	struct timeval time;
+	struct timeval min;
+	struct timeval max;
 	int calls, errors;
 };
 
@@ -65,7 +68,10 @@ count_syscall(struct tcb *tcp, struct timeval *tv)
 		}
 	}
 
-	counts[tcp->scno].calls++;
+	if (!counts[tcp->scno].calls++) {
+		counts[tcp->scno].max.tv_sec = -1;
+		counts[tcp->scno].min.tv_sec = INT_MAX;
+	}
 	if (tcp->u_error)
 		counts[tcp->scno].errors++;
 
@@ -102,6 +108,11 @@ count_syscall(struct tcb *tcp, struct timeval *tv)
 		shortest = *tv;
 	tv_add(&counts[tcp->scno].time, &counts[tcp->scno].time, tv);
 
+	if (tv_cmp(&counts[tcp->scno].min, &tcp->dtime) > 0)
+		counts[tcp->scno].min = tcp->dtime;
+	if (tv_cmp(&counts[tcp->scno].max, &tcp->dtime) < 0)
+		counts[tcp->scno].max = tcp->dtime;
+
 	return 0;
 }
 
@@ -160,7 +171,7 @@ call_summary_pers(FILE *outf)
 {
 	int     i, j;
 	int     call_cum, error_cum;
-	struct timeval tv_cum, dtv;
+	struct timeval tv_cum, max_cum, min_cum, dtv;
 	double  percent;
 	char   *dashes = "-------------------------";
 	char    error_str[16];
@@ -173,6 +184,8 @@ call_summary_pers(FILE *outf)
 	}
 
 	call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0;
+	max_cum.tv_sec = max_cum.tv_usec = -1;
+	min_cum.tv_sec = min_cum.tv_usec = INT_MAX;
 	if (overhead.tv_sec == -1)
 	{
 		tv_mul(&overhead, &shortest, 8);
@@ -188,14 +201,19 @@ call_summary_pers(FILE *outf)
 		call_cum += counts[i].calls;
 		error_cum += counts[i].errors;
 		tv_add(&tv_cum, &tv_cum, &counts[i].time);
+		if (tv_cmp(&counts[i].min, &min_cum) < 0)
+			min_cum = counts[i].min;
+		if (tv_cmp(&counts[i].max, &max_cum) > 0)
+			max_cum = counts[i].max;
 	}
 	if (counts && sortfun)
 		qsort((void *) sorted_count, nsyscalls, sizeof(int), sortfun);
-	fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n",
-		"% time", "seconds", "usecs/call",
-		"calls", "errors", "syscall");
-	fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
-		dashes, dashes, dashes, dashes, dashes, dashes);
+	fprintf(outf, "%6.6s %11.11s %11.11s %11.11s %11.11s %9.9s %9.9s %s\n",
+		"% time", "seconds", "usecs/call", "min", "max", "calls",
+		"errors", "syscall");
+	fprintf(outf,
+		"%6.6s %11.11s %11.11s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
+		dashes, dashes, dashes, dashes, dashes, dashes, dashes, dashes);
 	if (counts)
 	{
 		for (i = 0; i < nsyscalls; i++)
@@ -210,23 +228,28 @@ call_summary_pers(FILE *outf)
 				error_str[0] = '\0';
 			percent = (100.0 * tv_float(&counts[j].time)
 				   / tv_float(&tv_cum));
-			fprintf(outf, "%6.2f %11.6f %11ld %9d %9.9s %s\n",
+			fprintf(outf, "%6.2f %11.6f %11ld %11.6f %11.6f "
+				"%9d %9.9s %s\n",
 				percent, tv_float(&counts[j].time),
 				(long) 1000000 * dtv.tv_sec + dtv.tv_usec,
+				tv_float(&counts[j].min),
+				tv_float(&counts[j].max),
 				counts[j].calls,
 				error_str, sysent[j].sys_name);
 		}
 	}
 	free(sorted_count);
 
-	fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
-		dashes, dashes, dashes, dashes, dashes, dashes);
+	fprintf(outf,
+		"%6.6s %11.11s %11.11s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
+		dashes, dashes, dashes, dashes, dashes, dashes, dashes, dashes);
 	if (error_cum)
 		sprintf(error_str, "%d", error_cum);
 	else
 		error_str[0] = '\0';
-	fprintf(outf, "%6.6s %11.6f %11.11s %9d %9.9s %s\n",
+	fprintf(outf, "%6.6s %11.6f %11.11s %11.6f %11.6f %9d %9.9s %s\n",
 		"100.00", tv_float(&tv_cum), "",
+		tv_float(&min_cum), tv_float(&max_cum),
 		call_cum, error_str, "total");
 }
 
-- 
1.5.4.3

Attachment: signature.asc
Description: Digital signature

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to