@@ -37,6 +37,13 @@ public sealed class SampleMonitor : ISampleMonitor {
37
37
/// </summary>
38
38
public bool Collect { get ; }
39
39
40
+ /// <summary>
41
+ /// The monitor can be set to suppress updates. When it is set
42
+ /// to false, the statistics will not be updated and new samples
43
+ /// are ignored.
44
+ /// </summary>
45
+ public bool Active { get ; set ; }
46
+
40
47
/// <summary>
41
48
/// The name of the variable that is being monitored.
42
49
/// Used for output in <see cref="Summarize(bool, int, double?, double?)"/>.
@@ -48,7 +55,7 @@ public sealed class SampleMonitor : ISampleMonitor {
48
55
public double Min { get ; private set ; }
49
56
public double Max { get ; private set ; }
50
57
public double Total { get ; private set ; }
51
- double IMonitor . Sum { get { return Total ; } }
58
+ double INumericMonitor . Sum { get { return Total ; } }
52
59
public double Mean { get ; private set ; }
53
60
public double StdDev { get { return Math . Sqrt ( Variance ) ; } }
54
61
public double Variance { get { return ( Count > 0 ) ? variance / Count : 0.0 ; } }
@@ -104,6 +111,7 @@ private static double GetPercentile(IList<double> s, double p) {
104
111
}
105
112
106
113
public SampleMonitor ( string name = null , bool collect = false ) {
114
+ Active = true ;
107
115
Name = name ;
108
116
Collect = collect ;
109
117
if ( collect ) samples = new List < double > ( 64 ) ;
@@ -118,6 +126,8 @@ public void Reset() {
118
126
}
119
127
120
128
public void Add ( double value ) {
129
+ if ( ! Active ) return ;
130
+
121
131
if ( double . IsNaN ( value ) || double . IsInfinity ( value ) )
122
132
throw new ArgumentException ( "Not a valid double" , "value" ) ;
123
133
Count ++ ;
@@ -157,7 +167,7 @@ string IMonitor.Summarize() {
157
167
/// the data to produce the histogram is not available in the first place.</param>
158
168
/// <param name="maxBins">The maximum number of bins that should be used.
159
169
/// Note that the bin width and thus the number of bins is also governed by
160
- /// <paramref name="histInterval "/> if it is defined.
170
+ /// <paramref name="binWidth "/> if it is defined.
161
171
/// This is only effective if <see cref="Collect"/> and <paramref name="withHistogram"/>
162
172
/// was set to true, otherwise the data to produce the histogram is not available
163
173
/// in the first place.</param>
@@ -166,14 +176,14 @@ string IMonitor.Summarize() {
166
176
/// This is only effective if <see cref="Collect"/> and <paramref name="withHistogram"/>
167
177
/// was set to true, otherwise the data to produce the histogram is not available
168
178
/// in the first place.</param>
169
- /// <param name="histInterval ">The interval for the bins of the histogram or the
179
+ /// <param name="binWidth ">The interval for the bins of the histogram or the
170
180
/// range (<see cref="Max"/> - <see cref="Min"/>) divided by the number of bins
171
181
/// (<paramref name="maxBins"/>) in case the default value (null) is given.
172
182
/// This is only effective if <see cref="Collect"/> and <paramref name="withHistogram"/>
173
183
/// was set to true, otherwise the data to produce the histogram is not available
174
184
/// in the first place.</param>
175
185
/// <returns>A formatted string that provides a summary of the statistics.</returns>
176
- public string Summarize ( bool withHistogram = true , int maxBins = 20 , double ? histMin = null , double ? histInterval = null ) {
186
+ public string Summarize ( bool withHistogram = true , int maxBins = 20 , double ? histMin = null , double ? binWidth = null ) {
177
187
var nozero = Collect ? samples . Where ( x => x != 0 ) . ToList ( ) : new List < double > ( ) ;
178
188
var nozeromin = nozero . Count > 0 ? nozero . Min ( ) : double . NaN ;
179
189
var nozeromax = nozero . Count > 0 ? nozero . Max ( ) : double . NaN ;
@@ -200,7 +210,7 @@ public string Summarize(bool withHistogram = true, int maxBins = 20, double? his
200
210
201
211
if ( Collect && withHistogram ) {
202
212
var min = histMin ?? Min ;
203
- var interval = histInterval ?? ( Max - Min ) / maxBins ;
213
+ var interval = binWidth ?? ( Max - Min ) / maxBins ;
204
214
var histData = samples . GroupBy ( x => x <= min ? 0 : ( int ) Math . Floor ( Math . Min ( ( x - min + interval ) / interval , maxBins ) ) )
205
215
. Select ( x => new { Key = x . Key , Value = x . Count ( ) } )
206
216
. OrderBy ( x => x . Key ) ;
0 commit comments