From f7a943baeab100528b6989bc705748e374444044 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Sat, 11 Nov 2006 07:14:30 +0000 Subject: [PATCH] Add new duration recording method git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@24073 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ GSThroughput.h | 12 ++++++++++++ GSThroughput.m | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/ChangeLog b/ChangeLog index 78d8249..283ed96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-11-11 Richard Frith-Macdonald + + * GSThroughput.h: New ([add:duration:]) method. + * GSThroughput.m: Method to add multiple events with a total + duration (eg where recording individual event times has too + high an overhead). + 2006-11-09 Richard Frith-Macdonald * GNUmakefile: update version diff --git a/GSThroughput.h b/GSThroughput.h index c1ea919..772662b 100644 --- a/GSThroughput.h +++ b/GSThroughput.h @@ -99,6 +99,18 @@ */ - (void) add: (unsigned)count; +/** + * Adds a record for multiple events of the specified + * total duration.
+ * This is useful where you know a lot of similar events have completed + * in a particular period of time, but can't afford to measure the + * duration of the individual events because the timing overheads + * would be too great.
+ * You may use this method only if the receiver was initialised with + * duration logging turned on. + */ +- (void) add: (unsigned)count duration: (NSTimeInterval)length; + /** * Adds a record for a single event of the specified duration.
* You may use this method only if the receiver was initialised with diff --git a/GSThroughput.m b/GSThroughput.m index eea6b00..f37f429 100644 --- a/GSThroughput.m +++ b/GSThroughput.m @@ -381,6 +381,40 @@ typedef struct { cseconds[my->second].cnt += count; } +- (void) add: (unsigned)count duration: (NSTimeInterval)length +{ + NSAssert(my->supportDurations == YES, @"not configured for durations"); + + if (count > 0) + { + NSTimeInterval total = length; + DInfo *info; + + info = &dseconds[my->second]; + length /= count; + if (info->cnt == 0) + { + info->cnt = count; + info->min = length; + info->max = length; + info->sum = total; + } + else + { + info->cnt += count; + info->sum += total; + if (length > info->max) + { + info->max = length; + } + if (length < info->min) + { + info->min = length; + } + } + } +} + - (void) addDuration: (NSTimeInterval)length { DInfo *info;