Fix infrequent hangs in test-runner. (#16793)
[mono-project.git] / mcs / class / referencesource / System / services / monitoring / system / diagnosticts / CounterSample.cs
blob080d6d6478b6d24dbeda4c71fe7a482aebbb7ef1
1 //------------------------------------------------------------------------------
2 // <copyright file="CounterSample.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
7 namespace System.Diagnostics {
9 using System.Diagnostics;
11 using System;
13 /// <devdoc>
14 /// A struct holding the raw data for a performance counter.
15 /// </devdoc>
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
27 /// <devdoc>
28 /// <para>[To be supplied.]</para>
29 /// </devdoc>
30 public static CounterSample Empty = new CounterSample(0, 0, 0, 0, 0, 0, PerformanceCounterType.NumberOfItems32);
32 /// <devdoc>
33 /// <para>[To be supplied.]</para>
34 /// </devdoc>
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;
46 /// <devdoc>
47 /// <para>[To be supplied.]</para>
48 /// </devdoc>
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;
60 /// <devdoc>
61 /// Raw value of the counter.
62 /// </devdoc>
63 public long RawValue {
64 get {
65 return this.rawValue;
69 internal ulong UnsignedRawValue {
70 get {
71 return (ulong)this.rawValue;
75 /// <devdoc>
76 /// Optional base raw value for the counter (only used if multiple counter based).
77 /// </devdoc>
78 public long BaseValue {
79 get {
80 return this.baseValue;
84 /// <devdoc>
85 /// Raw system frequency
86 /// </devdoc>
87 public long SystemFrequency {
88 get {
89 return this.systemFrequency;
93 /// <devdoc>
94 /// Raw counter frequency
95 /// </devdoc>
96 public long CounterFrequency {
97 get {
98 return this.counterFrequency;
102 /// <devdoc>
103 /// Raw counter frequency
104 /// </devdoc>
105 public long CounterTimeStamp {
106 get {
107 return this.counterTimeStamp;
111 /// <devdoc>
112 /// Raw timestamp
113 /// </devdoc>
114 public long TimeStamp {
115 get {
116 return this.timeStamp;
120 /// <devdoc>
121 /// Raw high fidelity timestamp
122 /// </devdoc>
123 public long TimeStamp100nSec {
124 get {
125 return this.timeStamp100nSec;
129 /// <devdoc>
130 /// Counter type
131 /// </devdoc>
132 public PerformanceCounterType CounterType {
133 get {
134 return this.counterType;
138 /// <devdoc>
139 /// Static functions to calculate the performance value off the sample
140 /// </devdoc>
141 public static float Calculate(CounterSample counterSample) {
142 return CounterSampleCalculator.ComputeCounterValue(counterSample);
145 /// <devdoc>
146 /// Static functions to calculate the performance value off the samples
147 /// </devdoc>
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) {
172 return a.Equals(b);
175 public static bool operator !=(CounterSample a, CounterSample b) {
176 return !(a.Equals(b));