1 //------------------------------------------------------------------------------
2 // <copyright file="CounterSample.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace System
.Diagnostics
{
9 using System
.Diagnostics
;
14 /// A struct holding the raw data for a performance counter.
16 public struct CounterSample
{
17 private long rawValue
;
18 private long baseValue
;
19 private long timeStamp
;
20 private long counterFrequency
;
21 private PerformanceCounterType counterType
;
22 private long timeStamp100nSec
;
23 private long systemFrequency
;
24 private long counterTimeStamp
;
26 // Dummy holder for an empty sample
28 /// <para>[To be supplied.]</para>
30 public static CounterSample Empty
= new CounterSample(0, 0, 0, 0, 0, 0, PerformanceCounterType
.NumberOfItems32
);
33 /// <para>[To be supplied.]</para>
35 public CounterSample(long rawValue
, long baseValue
, long counterFrequency
, long systemFrequency
, long timeStamp
, long timeStamp100nSec
, PerformanceCounterType counterType
) {
36 this.rawValue
= rawValue
;
37 this.baseValue
= baseValue
;
38 this.timeStamp
= timeStamp
;
39 this.counterFrequency
= counterFrequency
;
40 this.counterType
= counterType
;
41 this.timeStamp100nSec
= timeStamp100nSec
;
42 this.systemFrequency
= systemFrequency
;
43 this.counterTimeStamp
= 0;
47 /// <para>[To be supplied.]</para>
49 public CounterSample(long rawValue
, long baseValue
, long counterFrequency
, long systemFrequency
, long timeStamp
, long timeStamp100nSec
, PerformanceCounterType counterType
, long counterTimeStamp
) {
50 this.rawValue
= rawValue
;
51 this.baseValue
= baseValue
;
52 this.timeStamp
= timeStamp
;
53 this.counterFrequency
= counterFrequency
;
54 this.counterType
= counterType
;
55 this.timeStamp100nSec
= timeStamp100nSec
;
56 this.systemFrequency
= systemFrequency
;
57 this.counterTimeStamp
= counterTimeStamp
;
61 /// Raw value of the counter.
63 public long RawValue
{
69 internal ulong UnsignedRawValue
{
71 return (ulong)this.rawValue
;
76 /// Optional base raw value for the counter (only used if multiple counter based).
78 public long BaseValue
{
80 return this.baseValue
;
85 /// Raw system frequency
87 public long SystemFrequency
{
89 return this.systemFrequency
;
94 /// Raw counter frequency
96 public long CounterFrequency
{
98 return this.counterFrequency
;
103 /// Raw counter frequency
105 public long CounterTimeStamp
{
107 return this.counterTimeStamp
;
114 public long TimeStamp
{
116 return this.timeStamp
;
121 /// Raw high fidelity timestamp
123 public long TimeStamp100nSec
{
125 return this.timeStamp100nSec
;
132 public PerformanceCounterType CounterType
{
134 return this.counterType
;
139 /// Static functions to calculate the performance value off the sample
141 public static float Calculate(CounterSample counterSample
) {
142 return CounterSampleCalculator
.ComputeCounterValue(counterSample
);
146 /// Static functions to calculate the performance value off the samples
148 public static float Calculate(CounterSample counterSample
, CounterSample nextCounterSample
) {
149 return CounterSampleCalculator
.ComputeCounterValue(counterSample
, nextCounterSample
);
152 public override bool Equals(Object o
) {
153 return ( o
is CounterSample
) && Equals((CounterSample
)o
);
156 public bool Equals(CounterSample sample
) {
157 return (rawValue
== sample
.rawValue
) &&
158 (baseValue
== sample
.baseValue
) &&
159 (timeStamp
== sample
.timeStamp
) &&
160 (counterFrequency
== sample
.counterFrequency
) &&
161 (counterType
== sample
.counterType
) &&
162 (timeStamp100nSec
== sample
.timeStamp100nSec
) &&
163 (systemFrequency
== sample
.systemFrequency
) &&
164 (counterTimeStamp
== sample
.counterTimeStamp
);
167 public override int GetHashCode() {
168 return rawValue
.GetHashCode();
171 public static bool operator ==(CounterSample a
, CounterSample b
) {
175 public static bool operator !=(CounterSample a
, CounterSample b
) {
176 return !(a
.Equals(b
));