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