Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Molaro <lupus@oddwiz.org>2008-02-27 21:14:57 +0300
committerPaolo Molaro <lupus@oddwiz.org>2008-02-27 21:14:57 +0300
commitd133be3585440eb44d6352518c6a12bd4d944d1b (patch)
tree41053546198e4643ca50a677ff051637a4a9474c /mcs/class/System/System.Diagnostics/CounterSampleCalculator.cs
parent92b216396758427849cd09d0098cc2c41fd23b2a (diff)
Wed Feb 27 20:00:04 CET 2008 Paolo Molaro <lupus@ximian.com>
* CounterSample.cs, CounterSampleCalculator.cs, PerformanceCounter.cs, PerformanceCounterCategory.cs, PerformanceCounterCategoryType.cs: beginning of the performance counter implementation. svn path=/trunk/mcs/; revision=96810
Diffstat (limited to 'mcs/class/System/System.Diagnostics/CounterSampleCalculator.cs')
-rw-r--r--mcs/class/System/System.Diagnostics/CounterSampleCalculator.cs53
1 files changed, 51 insertions, 2 deletions
diff --git a/mcs/class/System/System.Diagnostics/CounterSampleCalculator.cs b/mcs/class/System/System.Diagnostics/CounterSampleCalculator.cs
index 7116ac4ee5f..45b39d9dbfb 100644
--- a/mcs/class/System/System.Diagnostics/CounterSampleCalculator.cs
+++ b/mcs/class/System/System.Diagnostics/CounterSampleCalculator.cs
@@ -46,14 +46,63 @@ namespace System.Diagnostics {
public static float ComputeCounterValue (CounterSample newSample)
{
- return ComputeCounterValue (CounterSample.Empty, newSample);
+ switch (newSample.CounterType) {
+ case PerformanceCounterType.RawFraction:
+ case PerformanceCounterType.NumberOfItems32:
+ case PerformanceCounterType.NumberOfItemsHEX32:
+ case PerformanceCounterType.NumberOfItems64:
+ case PerformanceCounterType.NumberOfItemsHEX64:
+ return (float)newSample.RawValue;
+ default:
+ return 0;
+ }
}
[MonoTODO("What's the algorithm?")]
public static float ComputeCounterValue (CounterSample oldSample,
CounterSample newSample)
{
- throw new NotImplementedException ();
+ if (newSample.CounterType != oldSample.CounterType)
+ throw new Exception ("The counter samples must be of the same type");
+ switch (newSample.CounterType) {
+ case PerformanceCounterType.RawFraction:
+ case PerformanceCounterType.NumberOfItems32:
+ case PerformanceCounterType.NumberOfItemsHEX32:
+ case PerformanceCounterType.NumberOfItems64:
+ case PerformanceCounterType.NumberOfItemsHEX64:
+ return (float)newSample.RawValue;
+ case PerformanceCounterType.AverageCount64:
+ return (float)(newSample.RawValue - oldSample.RawValue)/(float)(newSample.BaseValue - oldSample.BaseValue);
+ case PerformanceCounterType.AverageTimer32:
+ return (((float)(newSample.RawValue - oldSample.RawValue))/newSample.SystemFrequency)/(float)(newSample.BaseValue - oldSample.BaseValue);
+ case PerformanceCounterType.CounterDelta32:
+ case PerformanceCounterType.CounterDelta64:
+ return (float)(newSample.RawValue - oldSample.RawValue);
+ case PerformanceCounterType.CounterMultiTimer:
+ return ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp - oldSample.TimeStamp) * 100.0f/newSample.BaseValue;
+ case PerformanceCounterType.CounterMultiTimer100Ns:
+ return ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec) * 100.0f/newSample.BaseValue;
+ case PerformanceCounterType.CounterMultiTimerInverse:
+ return (newSample.BaseValue - ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp - oldSample.TimeStamp)) * 100.0f;
+ case PerformanceCounterType.CounterMultiTimer100NsInverse:
+ return (newSample.BaseValue - ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec)) * 100.0f;
+ case PerformanceCounterType.CounterTimer:
+ case PerformanceCounterType.CountPerTimeInterval32:
+ case PerformanceCounterType.CountPerTimeInterval64:
+ return ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp - oldSample.TimeStamp);
+ case PerformanceCounterType.CounterTimerInverse:
+ return (1.0f - ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec)) * 100.0f;
+ case PerformanceCounterType.ElapsedTime:
+ // FIXME
+ return 0;
+ case PerformanceCounterType.Timer100Ns:
+ return ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp - oldSample.TimeStamp) * 100.0f;
+ case PerformanceCounterType.Timer100NsInverse:
+ return (1f - ((float)(newSample.RawValue - oldSample.RawValue))/(float)(newSample.TimeStamp - oldSample.TimeStamp)) * 100.0f;
+ default:
+ Console.WriteLine ("Counter type {0} not handled", newSample.CounterType);
+ return 0;
+ }
}
}
}