aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /ThirdParty/SmartThreadPool/STPPerformanceCounter.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'ThirdParty/SmartThreadPool/STPPerformanceCounter.cs')
-rw-r--r--ThirdParty/SmartThreadPool/STPPerformanceCounter.cs648
1 files changed, 371 insertions, 277 deletions
diff --git a/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs b/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs
index 077cf17..0663d1d 100644
--- a/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs
+++ b/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs
@@ -1,354 +1,448 @@
1using System; 1using System;
2using System.Diagnostics; 2using System.Diagnostics;
3using System.Threading;
4
5namespace Amib.Threading
6{
7 public interface ISTPPerformanceCountersReader
8 {
9 long InUseThreads { get; }
10 long ActiveThreads { get; }
11 long WorkItemsQueued { get; }
12 long WorkItemsProcessed { get; }
13 }
14}
3 15
4namespace Amib.Threading.Internal 16namespace Amib.Threading.Internal
5{ 17{
6 internal enum STPPerformanceCounterType 18 internal interface ISTPInstancePerformanceCounters : IDisposable
7 { 19 {
8 // Fields 20 void Close();
9 ActiveThreads = 0, 21 void SampleThreads(long activeThreads, long inUseThreads);
10 InUseThreads = 1, 22 void SampleWorkItems(long workItemsQueued, long workItemsProcessed);
11 OverheadThreads = 2, 23 void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime);
12 OverheadThreadsPercent = 3, 24 void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime);
13 OverheadThreadsPercentBase = 4, 25 }
26#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE)
14 27
15 WorkItems = 5, 28 internal enum STPPerformanceCounterType
16 WorkItemsInQueue = 6, 29 {
17 WorkItemsProcessed = 7, 30 // Fields
31 ActiveThreads = 0,
32 InUseThreads = 1,
33 OverheadThreads = 2,
34 OverheadThreadsPercent = 3,
35 OverheadThreadsPercentBase = 4,
18 36
19 WorkItemsQueuedPerSecond = 8, 37 WorkItems = 5,
20 WorkItemsProcessedPerSecond = 9, 38 WorkItemsInQueue = 6,
39 WorkItemsProcessed = 7,
21 40
22 AvgWorkItemWaitTime = 10, 41 WorkItemsQueuedPerSecond = 8,
23 AvgWorkItemWaitTimeBase = 11, 42 WorkItemsProcessedPerSecond = 9,
24 43
25 AvgWorkItemProcessTime = 12, 44 AvgWorkItemWaitTime = 10,
26 AvgWorkItemProcessTimeBase = 13, 45 AvgWorkItemWaitTimeBase = 11,
27 46
28 WorkItemsGroups = 14, 47 AvgWorkItemProcessTime = 12,
48 AvgWorkItemProcessTimeBase = 13,
29 49
30 LastCounter = 14, 50 WorkItemsGroups = 14,
31 }
32
33 51
34 /// <summary> 52 LastCounter = 14,
35 /// Summary description for STPPerformanceCounter. 53 }
36 /// </summary> 54
37 internal class STPPerformanceCounter
38 {
39 // Fields
40 private PerformanceCounterType _pcType;
41 protected string _counterHelp;
42 protected string _counterName;
43
44 // Methods
45 public STPPerformanceCounter(
46 string counterName,
47 string counterHelp,
48 PerformanceCounterType pcType)
49 {
50 this._counterName = counterName;
51 this._counterHelp = counterHelp;
52 this._pcType = pcType;
53 }
54
55 public void AddCounterToCollection(CounterCreationDataCollection counterData)
56 {
57 CounterCreationData counterCreationData = new CounterCreationData(
58 _counterName,
59 _counterHelp,
60 _pcType);
61 55
62 counterData.Add(counterCreationData); 56 /// <summary>
63 } 57 /// Summary description for STPPerformanceCounter.
58 /// </summary>
59 internal class STPPerformanceCounter
60 {
61 // Fields
62 private readonly PerformanceCounterType _pcType;
63 protected string _counterHelp;
64 protected string _counterName;
65
66 // Methods
67 public STPPerformanceCounter(
68 string counterName,
69 string counterHelp,
70 PerformanceCounterType pcType)
71 {
72 _counterName = counterName;
73 _counterHelp = counterHelp;
74 _pcType = pcType;
75 }
76
77 public void AddCounterToCollection(CounterCreationDataCollection counterData)
78 {
79 CounterCreationData counterCreationData = new CounterCreationData(
80 _counterName,
81 _counterHelp,
82 _pcType);
83
84 counterData.Add(counterCreationData);
85 }
86
87 // Properties
88 public string Name
89 {
90 get
91 {
92 return _counterName;
93 }
94 }
95 }
96
97 internal class STPPerformanceCounters
98 {
99 // Fields
100 internal STPPerformanceCounter[] _stpPerformanceCounters;
101 private static readonly STPPerformanceCounters _instance;
102 internal const string _stpCategoryHelp = "SmartThreadPool performance counters";
103 internal const string _stpCategoryName = "SmartThreadPool";
104
105 // Methods
106 static STPPerformanceCounters()
107 {
108 _instance = new STPPerformanceCounters();
109 }
110
111 private STPPerformanceCounters()
112 {
113 STPPerformanceCounter[] stpPerformanceCounters = new STPPerformanceCounter[]
114 {
115 new STPPerformanceCounter("Active threads", "The current number of available in the thread pool.", PerformanceCounterType.NumberOfItems32),
116 new STPPerformanceCounter("In use threads", "The current number of threads that execute a work item.", PerformanceCounterType.NumberOfItems32),
117 new STPPerformanceCounter("Overhead threads", "The current number of threads that are active, but are not in use.", PerformanceCounterType.NumberOfItems32),
118 new STPPerformanceCounter("% overhead threads", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawFraction),
119 new STPPerformanceCounter("% overhead threads base", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawBase),
120
121 new STPPerformanceCounter("Work Items", "The number of work items in the Smart Thread Pool. Both queued and processed.", PerformanceCounterType.NumberOfItems32),
122 new STPPerformanceCounter("Work Items in queue", "The current number of work items in the queue", PerformanceCounterType.NumberOfItems32),
123 new STPPerformanceCounter("Work Items processed", "The number of work items already processed", PerformanceCounterType.NumberOfItems32),
124
125 new STPPerformanceCounter("Work Items queued/sec", "The number of work items queued per second", PerformanceCounterType.RateOfCountsPerSecond32),
126 new STPPerformanceCounter("Work Items processed/sec", "The number of work items processed per second", PerformanceCounterType.RateOfCountsPerSecond32),
127
128 new STPPerformanceCounter("Avg. Work Item wait time/sec", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageCount64),
129 new STPPerformanceCounter("Avg. Work Item wait time base", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageBase),
130
131 new STPPerformanceCounter("Avg. Work Item process time/sec", "The average time it takes to process a work item.", PerformanceCounterType.AverageCount64),
132 new STPPerformanceCounter("Avg. Work Item process time base", "The average time it takes to process a work item.", PerformanceCounterType.AverageBase),
133
134 new STPPerformanceCounter("Work Items Groups", "The current number of work item groups associated with the Smart Thread Pool.", PerformanceCounterType.NumberOfItems32),
135 };
136
137 _stpPerformanceCounters = stpPerformanceCounters;
138 SetupCategory();
139 }
140
141 private void SetupCategory()
142 {
143 if (!PerformanceCounterCategory.Exists(_stpCategoryName))
144 {
145 CounterCreationDataCollection counters = new CounterCreationDataCollection();
146
147 for (int i = 0; i < _stpPerformanceCounters.Length; i++)
148 {
149 _stpPerformanceCounters[i].AddCounterToCollection(counters);
150 }
151
152 PerformanceCounterCategory.Create(
153 _stpCategoryName,
154 _stpCategoryHelp,
155 PerformanceCounterCategoryType.MultiInstance,
156 counters);
157
158 }
159 }
64 160
65 // Properties 161 // Properties
66 public string Name 162 public static STPPerformanceCounters Instance
163 {
164 get
165 {
166 return _instance;
167 }
168 }
169 }
170
171 internal class STPInstancePerformanceCounter : IDisposable
172 {
173 // Fields
174 private bool _isDisposed;
175 private PerformanceCounter _pcs;
176
177 // Methods
178 protected STPInstancePerformanceCounter()
179 {
180 _isDisposed = false;
181 }
182
183 public STPInstancePerformanceCounter(
184 string instance,
185 STPPerformanceCounterType spcType) : this()
186 {
187 STPPerformanceCounters counters = STPPerformanceCounters.Instance;
188 _pcs = new PerformanceCounter(
189 STPPerformanceCounters._stpCategoryName,
190 counters._stpPerformanceCounters[(int) spcType].Name,
191 instance,
192 false);
193 _pcs.RawValue = _pcs.RawValue;
194 }
195
196
197 public void Close()
198 {
199 if (_pcs != null)
200 {
201 _pcs.RemoveInstance();
202 _pcs.Close();
203 _pcs = null;
204 }
205 }
206
207 public void Dispose()
208 {
209 Dispose(true);
210 }
211
212 public virtual void Dispose(bool disposing)
67 { 213 {
68 get 214 if (!_isDisposed)
69 { 215 {
70 return _counterName; 216 if (disposing)
217 {
218 Close();
219 }
71 } 220 }
72 } 221 _isDisposed = true;
73 }
74
75 internal class STPPerformanceCounters
76 {
77 // Fields
78 internal STPPerformanceCounter[] _stpPerformanceCounters;
79 private static STPPerformanceCounters _instance;
80 internal const string _stpCategoryHelp = "SmartThreadPool performance counters";
81 internal const string _stpCategoryName = "SmartThreadPool";
82
83 // Methods
84 static STPPerformanceCounters()
85 {
86 _instance = new STPPerformanceCounters();
87 } 222 }
88 223
89 private STPPerformanceCounters() 224 public virtual void Increment()
90 { 225 {
91 STPPerformanceCounter[] stpPerformanceCounters = new STPPerformanceCounter[] 226 _pcs.Increment();
92 { 227 }
93 new STPPerformanceCounter("Active threads", "The current number of available in the thread pool.", PerformanceCounterType.NumberOfItems32), 228
94 new STPPerformanceCounter("In use threads", "The current number of threads that execute a work item.", PerformanceCounterType.NumberOfItems32), 229 public virtual void IncrementBy(long val)
95 new STPPerformanceCounter("Overhead threads", "The current number of threads that are active, but are not in use.", PerformanceCounterType.NumberOfItems32), 230 {
96 new STPPerformanceCounter("% overhead threads", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawFraction), 231 _pcs.IncrementBy(val);
97 new STPPerformanceCounter("% overhead threads base", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawBase), 232 }
98 233
99 new STPPerformanceCounter("Work Items", "The number of work items in the Smart Thread Pool. Both queued and processed.", PerformanceCounterType.NumberOfItems32), 234 public virtual void Set(long val)
100 new STPPerformanceCounter("Work Items in queue", "The current number of work items in the queue", PerformanceCounterType.NumberOfItems32), 235 {
101 new STPPerformanceCounter("Work Items processed", "The number of work items already processed", PerformanceCounterType.NumberOfItems32), 236 _pcs.RawValue = val;
102 237 }
103 new STPPerformanceCounter("Work Items queued/sec", "The number of work items queued per second", PerformanceCounterType.RateOfCountsPerSecond32), 238 }
104 new STPPerformanceCounter("Work Items processed/sec", "The number of work items processed per second", PerformanceCounterType.RateOfCountsPerSecond32), 239
105 240 internal class STPInstanceNullPerformanceCounter : STPInstancePerformanceCounter
106 new STPPerformanceCounter("Avg. Work Item wait time/sec", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageCount64), 241 {
107 new STPPerformanceCounter("Avg. Work Item wait time base", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageBase), 242 // Methods
243 public override void Increment() {}
244 public override void IncrementBy(long value) {}
245 public override void Set(long val) {}
246 }
247
248
249
250 internal class STPInstancePerformanceCounters : ISTPInstancePerformanceCounters
251 {
252 private bool _isDisposed;
253 // Fields
254 private STPInstancePerformanceCounter[] _pcs;
255 private static readonly STPInstancePerformanceCounter _stpInstanceNullPerformanceCounter;
256
257 // Methods
258 static STPInstancePerformanceCounters()
259 {
260 _stpInstanceNullPerformanceCounter = new STPInstanceNullPerformanceCounter();
261 }
262
263 public STPInstancePerformanceCounters(string instance)
264 {
265 _isDisposed = false;
266 _pcs = new STPInstancePerformanceCounter[(int)STPPerformanceCounterType.LastCounter];
267
268 // Call the STPPerformanceCounters.Instance so the static constructor will
269 // intialize the STPPerformanceCounters singleton.
270 STPPerformanceCounters.Instance.GetHashCode();
271
272 for (int i = 0; i < _pcs.Length; i++)
273 {
274 if (instance != null)
275 {
276 _pcs[i] = new STPInstancePerformanceCounter(
277 instance,
278 (STPPerformanceCounterType) i);
279 }
280 else
281 {
282 _pcs[i] = _stpInstanceNullPerformanceCounter;
283 }
284 }
285 }
286
108 287
109 new STPPerformanceCounter("Avg. Work Item process time/sec", "The average time it takes to process a work item.", PerformanceCounterType.AverageCount64), 288 public void Close()
110 new STPPerformanceCounter("Avg. Work Item process time base", "The average time it takes to process a work item.", PerformanceCounterType.AverageBase), 289 {
290 if (null != _pcs)
291 {
292 for (int i = 0; i < _pcs.Length; i++)
293 {
294 if (null != _pcs[i])
295 {
296 _pcs[i].Dispose();
297 }
298 }
299 _pcs = null;
300 }
301 }
111 302
112 new STPPerformanceCounter("Work Items Groups", "The current number of work item groups associated with the Smart Thread Pool.", PerformanceCounterType.NumberOfItems32), 303 public void Dispose()
113 }; 304 {
305 Dispose(true);
306 }
114 307
115 _stpPerformanceCounters = stpPerformanceCounters; 308 public virtual void Dispose(bool disposing)
116 SetupCategory();
117 }
118
119 private void SetupCategory()
120 { 309 {
121 if (!PerformanceCounterCategory.Exists(_stpCategoryName)) 310 if (!_isDisposed)
122 { 311 {
123 CounterCreationDataCollection counters = new CounterCreationDataCollection(); 312 if (disposing)
124
125 for (int i = 0; i < _stpPerformanceCounters.Length; i++)
126 { 313 {
127 _stpPerformanceCounters[i].AddCounterToCollection(counters); 314 Close();
128 } 315 }
129
130
131 // *********** Remark for .NET 2.0 ***********
132 // If you are here, it means you got the warning that this overload
133 // of the method is deprecated in .NET 2.0. To use the correct
134 // method overload, uncomment the third argument of
135 // the method.
136 #pragma warning disable 0618
137 PerformanceCounterCategory.Create(
138 _stpCategoryName,
139 _stpCategoryHelp,
140 //PerformanceCounterCategoryType.MultiInstance,
141 counters);
142 #pragma warning restore 0618
143 } 316 }
317 _isDisposed = true;
144 } 318 }
145 319
146 // Properties 320 private STPInstancePerformanceCounter GetCounter(STPPerformanceCounterType spcType)
147 public static STPPerformanceCounters Instance 321 {
148 { 322 return _pcs[(int) spcType];
149 get 323 }
150 { 324
151 return _instance; 325 public void SampleThreads(long activeThreads, long inUseThreads)
152 } 326 {
153 } 327 GetCounter(STPPerformanceCounterType.ActiveThreads).Set(activeThreads);
154 } 328 GetCounter(STPPerformanceCounterType.InUseThreads).Set(inUseThreads);
329 GetCounter(STPPerformanceCounterType.OverheadThreads).Set(activeThreads-inUseThreads);
330
331 GetCounter(STPPerformanceCounterType.OverheadThreadsPercentBase).Set(activeThreads-inUseThreads);
332 GetCounter(STPPerformanceCounterType.OverheadThreadsPercent).Set(inUseThreads);
333 }
334
335 public void SampleWorkItems(long workItemsQueued, long workItemsProcessed)
336 {
337 GetCounter(STPPerformanceCounterType.WorkItems).Set(workItemsQueued+workItemsProcessed);
338 GetCounter(STPPerformanceCounterType.WorkItemsInQueue).Set(workItemsQueued);
339 GetCounter(STPPerformanceCounterType.WorkItemsProcessed).Set(workItemsProcessed);
340
341 GetCounter(STPPerformanceCounterType.WorkItemsQueuedPerSecond).Set(workItemsQueued);
342 GetCounter(STPPerformanceCounterType.WorkItemsProcessedPerSecond).Set(workItemsProcessed);
343 }
344
345 public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime)
346 {
347 GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTime).IncrementBy((long)workItemWaitTime.TotalMilliseconds);
348 GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTimeBase).Increment();
349 }
350
351 public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime)
352 {
353 GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTime).IncrementBy((long)workItemProcessTime.TotalMilliseconds);
354 GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTimeBase).Increment();
355 }
356 }
357#endif
155 358
156 internal class STPInstancePerformanceCounter : IDisposable 359 internal class NullSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader
157 { 360 {
158 // Fields 361 private static readonly NullSTPInstancePerformanceCounters _instance = new NullSTPInstancePerformanceCounters();
159 private PerformanceCounter _pcs;
160 362
161 // Methods 363 public static NullSTPInstancePerformanceCounters Instance
162 protected STPInstancePerformanceCounter() 364 {
163 { 365 get { return _instance; }
164 } 366 }
165 367
166 public STPInstancePerformanceCounter( 368 public void Close() {}
167 string instance, 369 public void Dispose() {}
168 STPPerformanceCounterType spcType) 370
371 public void SampleThreads(long activeThreads, long inUseThreads) {}
372 public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) {}
373 public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) {}
374 public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) {}
375 public long InUseThreads
169 { 376 {
170 STPPerformanceCounters counters = STPPerformanceCounters.Instance; 377 get { return 0; }
171 _pcs = new PerformanceCounter(
172 STPPerformanceCounters._stpCategoryName,
173 counters._stpPerformanceCounters[(int) spcType].Name,
174 instance,
175 false);
176 _pcs.RawValue = _pcs.RawValue;
177 } 378 }
178 379
179 ~STPInstancePerformanceCounter() 380 public long ActiveThreads
180 { 381 {
181 Close(); 382 get { return 0; }
182 } 383 }
183 384
184 public void Close() 385 public long WorkItemsQueued
185 {
186 if (_pcs != null)
187 {
188 _pcs.RemoveInstance();
189 _pcs.Close();
190 _pcs = null;
191 }
192 }
193
194 public void Dispose()
195 { 386 {
196 Close(); 387 get { return 0; }
197 GC.SuppressFinalize(this);
198 }
199
200 public virtual void Increment()
201 {
202 _pcs.Increment();
203 }
204
205 public virtual void IncrementBy(long val)
206 {
207 _pcs.IncrementBy(val);
208 } 388 }
209 389
210 public virtual void Set(long val) 390 public long WorkItemsProcessed
211 { 391 {
212 _pcs.RawValue = val; 392 get { return 0; }
213 } 393 }
214 } 394 }
215 395
216 internal class STPInstanceNullPerformanceCounter : STPInstancePerformanceCounter 396 internal class LocalSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader
217 { 397 {
218 // Methods 398 public void Close() { }
219 public STPInstanceNullPerformanceCounter() {} 399 public void Dispose() { }
220 public override void Increment() {}
221 public override void IncrementBy(long value) {}
222 public override void Set(long val) {}
223 }
224
225 internal interface ISTPInstancePerformanceCounters : IDisposable
226 {
227 void Close();
228 void SampleThreads(long activeThreads, long inUseThreads);
229 void SampleWorkItems(long workItemsQueued, long workItemsProcessed);
230 void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime);
231 void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime);
232 }
233 400
401 private long _activeThreads;
402 private long _inUseThreads;
403 private long _workItemsQueued;
404 private long _workItemsProcessed;
234 405
235 internal class STPInstancePerformanceCounters : ISTPInstancePerformanceCounters, IDisposable 406 public long InUseThreads
236 {
237 // Fields
238 private STPInstancePerformanceCounter[] _pcs;
239 private static STPInstancePerformanceCounter _stpInstanceNullPerformanceCounter;
240
241 // Methods
242 static STPInstancePerformanceCounters()
243 { 407 {
244 _stpInstanceNullPerformanceCounter = new STPInstanceNullPerformanceCounter(); 408 get { return _inUseThreads; }
245 }
246
247 public STPInstancePerformanceCounters(string instance)
248 {
249 _pcs = new STPInstancePerformanceCounter[(int)STPPerformanceCounterType.LastCounter];
250 // STPPerformanceCounters counters = STPPerformanceCounters.Instance;
251 for (int i = 0; i < _pcs.Length; i++)
252 {
253 if (instance != null)
254 {
255 _pcs[i] = new STPInstancePerformanceCounter(
256 instance,
257 (STPPerformanceCounterType) i);
258 }
259 else
260 {
261 _pcs[i] = _stpInstanceNullPerformanceCounter;
262 }
263 }
264 } 409 }
265
266 410
267 public void Close() 411 public long ActiveThreads
268 { 412 {
269 if (null != _pcs) 413 get { return _activeThreads; }
270 {
271 for (int i = 0; i < _pcs.Length; i++)
272 {
273 if (null != _pcs[i])
274 {
275 _pcs[i].Close();
276 }
277 }
278 _pcs = null;
279 }
280 } 414 }
281 415
282 ~STPInstancePerformanceCounters() 416 public long WorkItemsQueued
283 { 417 {
284 Close(); 418 get { return _workItemsQueued; }
285 } 419 }
286 420
287 public void Dispose() 421 public long WorkItemsProcessed
288 {
289 Close();
290 GC.SuppressFinalize(this);
291 }
292
293 private STPInstancePerformanceCounter GetCounter(STPPerformanceCounterType spcType)
294 { 422 {
295 return _pcs[(int) spcType]; 423 get { return _workItemsProcessed; }
296 } 424 }
297 425
298 public void SampleThreads(long activeThreads, long inUseThreads) 426 public void SampleThreads(long activeThreads, long inUseThreads)
299 { 427 {
300 GetCounter(STPPerformanceCounterType.ActiveThreads).Set(activeThreads); 428 _activeThreads = activeThreads;
301 GetCounter(STPPerformanceCounterType.InUseThreads).Set(inUseThreads); 429 _inUseThreads = inUseThreads;
302 GetCounter(STPPerformanceCounterType.OverheadThreads).Set(activeThreads-inUseThreads);
303
304 GetCounter(STPPerformanceCounterType.OverheadThreadsPercentBase).Set(activeThreads-inUseThreads);
305 GetCounter(STPPerformanceCounterType.OverheadThreadsPercent).Set(inUseThreads);
306 } 430 }
307 431
308 public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) 432 public void SampleWorkItems(long workItemsQueued, long workItemsProcessed)
309 { 433 {
310 GetCounter(STPPerformanceCounterType.WorkItems).Set(workItemsQueued+workItemsProcessed); 434 _workItemsQueued = workItemsQueued;
311 GetCounter(STPPerformanceCounterType.WorkItemsInQueue).Set(workItemsQueued); 435 _workItemsProcessed = workItemsProcessed;
312 GetCounter(STPPerformanceCounterType.WorkItemsProcessed).Set(workItemsProcessed);
313
314 GetCounter(STPPerformanceCounterType.WorkItemsQueuedPerSecond).Set(workItemsQueued);
315 GetCounter(STPPerformanceCounterType.WorkItemsProcessedPerSecond).Set(workItemsProcessed);
316 } 436 }
317 437
318 public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) 438 public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime)
319 { 439 {
320 GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTime).IncrementBy((long)workItemWaitTime.TotalMilliseconds); 440 // Not supported
321 GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTimeBase).Increment();
322 } 441 }
323 442
324 public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) 443 public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime)
325 { 444 {
326 GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTime).IncrementBy((long)workItemProcessTime.TotalMilliseconds); 445 // Not supported
327 GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTimeBase).Increment();
328 }
329 }
330
331 internal class NullSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, IDisposable
332 {
333 static NullSTPInstancePerformanceCounters()
334 {
335 } 446 }
336
337 private static NullSTPInstancePerformanceCounters _instance = new NullSTPInstancePerformanceCounters(null);
338
339 public static NullSTPInstancePerformanceCounters Instance
340 {
341 get { return _instance; }
342 }
343
344 public NullSTPInstancePerformanceCounters(string instance) {}
345 public void Close() {}
346 public void Dispose() {}
347
348 public void SampleThreads(long activeThreads, long inUseThreads) {}
349 public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) {}
350 public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) {}
351 public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) {}
352 } 447 }
353
354} 448}