4 * $Log: aggregateSample.C,v $
5 * Revision 1.7 1994/07/02 01:47:31 markc
6 * Rename aggregation operator defines.
7 * Rename aggregation operator defines.
9 * Revision 1.6 1994/06/14 15:36:49 markc
10 * Added support for different types of aggregation (max, min, sum, avg).
11 * Previously, only summation had been done.
13 * Revision 1.5 1994/06/02 23:36:10 markc
14 * Added assertion to ensure values reported are positive.
16 * Revision 1.4 1994/05/17 00:14:44 hollings
17 * added rcs log entry.
23 #include "util/h/aggregateSample.h"
25 struct sampleInterval sampleInfo::newValue(timeStamp sampleTime,
28 struct sampleInterval ret;
30 // use the first sample to define a baseline in time and value.
31 if (!firstSampleReceived) {
32 firstSampleReceived = True;
33 lastSampleStart = sampleTime;
34 lastSampleEnd = sampleTime;
42 ret.start = lastSampleEnd;
46 // used when it's a component of an aggregate.
48 lastSampleEnd = sampleTime;
53 struct sampleInterval sampleInfo::newValue(List<sampleInfo *> parts,
60 sampleValue component;
61 timeStamp earlyestTime;
62 struct sampleInterval ret;
63 sampleValue aggregateVal;
66 assert((aggOp == aggSum) || (aggOp == aggAvg) ||
67 (aggOp == aggMin) || (aggOp == aggMax));
69 if (parts.count() <= 1) {
71 return(newValue(sampleTime, newVal));
73 earlyestTime = (*parts)->lastSampleEnd;
74 for (cp=parts; curr = *cp; cp++) {
76 if (curr->lastSampleEnd < earlyestTime) {
77 earlyestTime = curr->lastSampleEnd;
82 if (earlyestTime > lastSampleEnd + 0.0001) {
83 /* eat the first one to get a good interval basis */
84 if (!firstSampleReceived) {
85 firstSampleReceived = True;
87 lastSampleEnd = earlyestTime;
89 // this gives all of the samples the same initial starting
91 // It is very important for them to have the same time
92 // if this is not done, fract that is calculated below
93 // will fail the assertions
94 // You may want to zero the lastSample values here too
96 for (cp=parts; curr=*cp; cp++)
97 curr->lastSampleStart = earlyestTime;
106 for (cp=parts; curr=*cp; cp++) {
107 // assert(earlyestTime >= curr->lastSampleStart);
109 fract = (earlyestTime - lastSampleEnd)/
110 (curr->lastSampleEnd - curr->lastSampleStart);
111 component = (curr->lastSample) * fract;
114 assert(fract <= 1.0);
115 assert(component >= -0.01);
117 curr->lastSample -= component;
119 // each list entry comes from a separate reporter
124 aggregateVal += component;
128 aggregateVal = component;
130 } else if (component < aggregateVal)
131 aggregateVal = component;
134 if (component > aggregateVal)
135 aggregateVal = component;
139 /* move forward our time of our earliest sample */
140 curr->lastSampleStart = earlyestTime;
143 // len is the number of samples on the list
148 ret.start = lastSampleEnd;
149 ret.end = earlyestTime;
150 ret.value = aggregateVal;
151 assert(ret.value >= 0.0);
153 lastSampleStart = lastSampleEnd;
154 lastSampleEnd = earlyestTime;