mscorlib(4.0.0.0) API with additions
CounterSample.cs
1 namespace System.Diagnostics
2 {
4  public struct CounterSample
5  {
6  private long rawValue;
7 
8  private long baseValue;
9 
10  private long timeStamp;
11 
12  private long counterFrequency;
13 
14  private PerformanceCounterType counterType;
15 
16  private long timeStamp100nSec;
17 
18  private long systemFrequency;
19 
20  private long counterTimeStamp;
21 
23  public static CounterSample Empty = new CounterSample(0L, 0L, 0L, 0L, 0L, 0L, PerformanceCounterType.NumberOfItems32);
24 
27  public long RawValue => rawValue;
28 
29  internal ulong UnsignedRawValue => (ulong)rawValue;
30 
33  public long BaseValue => baseValue;
34 
37  public long SystemFrequency => systemFrequency;
38 
41  public long CounterFrequency => counterFrequency;
42 
45  public long CounterTimeStamp => counterTimeStamp;
46 
49  public long TimeStamp => timeStamp;
50 
53  public long TimeStamp100nSec => timeStamp100nSec;
54 
57  public PerformanceCounterType CounterType => counterType;
58 
67  public CounterSample(long rawValue, long baseValue, long counterFrequency, long systemFrequency, long timeStamp, long timeStamp100nSec, PerformanceCounterType counterType)
68  {
69  this.rawValue = rawValue;
70  this.baseValue = baseValue;
71  this.timeStamp = timeStamp;
72  this.counterFrequency = counterFrequency;
73  this.counterType = counterType;
74  this.timeStamp100nSec = timeStamp100nSec;
75  this.systemFrequency = systemFrequency;
76  counterTimeStamp = 0L;
77  }
78 
88  public CounterSample(long rawValue, long baseValue, long counterFrequency, long systemFrequency, long timeStamp, long timeStamp100nSec, PerformanceCounterType counterType, long counterTimeStamp)
89  {
90  this.rawValue = rawValue;
91  this.baseValue = baseValue;
92  this.timeStamp = timeStamp;
93  this.counterFrequency = counterFrequency;
94  this.counterType = counterType;
95  this.timeStamp100nSec = timeStamp100nSec;
96  this.systemFrequency = systemFrequency;
97  this.counterTimeStamp = counterTimeStamp;
98  }
99 
103  public static float Calculate(CounterSample counterSample)
104  {
105  return CounterSampleCalculator.ComputeCounterValue(counterSample);
106  }
107 
112  public static float Calculate(CounterSample counterSample, CounterSample nextCounterSample)
113  {
114  return CounterSampleCalculator.ComputeCounterValue(counterSample, nextCounterSample);
115  }
116 
121  public override bool Equals(object o)
122  {
123  if (o is CounterSample)
124  {
125  return Equals((CounterSample)o);
126  }
127  return false;
128  }
129 
134  public bool Equals(CounterSample sample)
135  {
136  if (rawValue == sample.rawValue && baseValue == sample.baseValue && timeStamp == sample.timeStamp && counterFrequency == sample.counterFrequency && counterType == sample.counterType && timeStamp100nSec == sample.timeStamp100nSec && systemFrequency == sample.systemFrequency)
137  {
138  return counterTimeStamp == sample.counterTimeStamp;
139  }
140  return false;
141  }
142 
145  public override int GetHashCode()
146  {
147  return rawValue.GetHashCode();
148  }
149 
155  public static bool operator ==(CounterSample a, CounterSample b)
156  {
157  return a.Equals(b);
158  }
159 
165  public static bool operator !=(CounterSample a, CounterSample b)
166  {
167  return !a.Equals(b);
168  }
169  }
170 }
long BaseValue
Gets an optional, base raw value for the counter.
long TimeStamp
Gets the raw time stamp.
long RawValue
Gets the raw value of the counter.
long CounterTimeStamp
Gets the counter's time stamp.
static bool operator==(CounterSample a, CounterSample b)
Returns a value that indicates whether two T:System.Diagnostics.CounterSample structures are equal.
static float ComputeCounterValue(CounterSample newSample)
Computes the calculated value of a single raw counter sample.
PerformanceCounterType
Specifies the formula used to calculate the M:System.Diagnostics.PerformanceCounter....
CounterSample(long rawValue, long baseValue, long counterFrequency, long systemFrequency, long timeStamp, long timeStamp100nSec, PerformanceCounterType counterType)
Initializes a new instance of the T:System.Diagnostics.CounterSample structure and sets the P:System....
override int GetHashCode()
Gets a hash code for the current counter sample.
Provides a set of utility functions for interpreting performance counter data.
override bool Equals(object o)
Indicates whether the specified structure is a T:System.Diagnostics.CounterSample structure and is id...
Defines a structure that holds the raw data for a performance counter.
Definition: CounterSample.cs:4
PerformanceCounterType CounterType
Gets the performance counter type.
static CounterSample Empty
Defines an empty, uninitialized performance counter sample of type NumberOfItems32.
long TimeStamp100nSec
Gets the raw, high-fidelity time stamp.
long CounterFrequency
Gets the raw counter frequency.
bool Equals(CounterSample sample)
Indicates whether the specified T:System.Diagnostics.CounterSample structure is equal to the current ...
CounterSample(long rawValue, long baseValue, long counterFrequency, long systemFrequency, long timeStamp, long timeStamp100nSec, PerformanceCounterType counterType, long counterTimeStamp)
Initializes a new instance of the T:System.Diagnostics.CounterSample structure and sets the P:System....
static float Calculate(CounterSample counterSample)
Calculates the performance data of the counter, using a single sample point. This method is generally...
static bool operator !=(CounterSample a, CounterSample b)
Returns a value that indicates whether two T:System.Diagnostics.CounterSample structures are not equa...
long SystemFrequency
Gets the raw system frequency.
static float Calculate(CounterSample counterSample, CounterSample nextCounterSample)
Calculates the performance data of the counter, using two sample points. This method is generally use...