2 // System.Diagnostics.CounterSample.cs
5 // Jonathan Pryor (jonpryor@vt.edu)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 namespace System.Diagnostics {
35 public struct CounterSample {
37 // do not reorder and keep in sync with the runtime
38 // in metadata/mono-perfcounters.c
39 private long rawValue;
40 private long baseValue;
41 private long counterFrequency;
42 private long systemFrequency;
43 private long timeStamp;
44 private long timeStamp100nSec;
45 private long counterTimeStamp;
46 private PerformanceCounterType counterType;
48 public CounterSample (long rawValue,
50 long counterFrequency,
53 long timeStamp100nSec,
54 PerformanceCounterType counterType)
55 : this (rawValue, baseValue, counterFrequency,
56 systemFrequency, timeStamp, timeStamp100nSec,
61 public CounterSample (long rawValue,
63 long counterFrequency,
66 long timeStamp100nSec,
67 PerformanceCounterType counterType,
68 long counterTimeStamp)
70 this.rawValue = rawValue;
71 this.baseValue = baseValue;
72 this.counterFrequency = counterFrequency;
73 this.systemFrequency = systemFrequency;
74 this.timeStamp = timeStamp;
75 this.timeStamp100nSec = timeStamp100nSec;
76 this.counterType = counterType;
77 this.counterTimeStamp = counterTimeStamp;
80 public static CounterSample Empty = new CounterSample (
82 PerformanceCounterType.NumberOfItems32,
85 public long BaseValue {
86 get {return baseValue;}
89 public long CounterFrequency {
90 get {return counterFrequency;}
93 public long CounterTimeStamp {
94 get {return counterTimeStamp;}
97 public PerformanceCounterType CounterType {
98 get {return counterType;}
101 public long RawValue {
102 get {return rawValue;}
105 public long SystemFrequency {
106 get {return systemFrequency;}
109 public long TimeStamp {
110 get {return timeStamp;}
113 public long TimeStamp100nSec {
114 get {return timeStamp100nSec;}
117 public static float Calculate (CounterSample counterSample)
119 return CounterSampleCalculator.ComputeCounterValue (counterSample);
122 public static float Calculate (CounterSample counterSample,
123 CounterSample nextCounterSample)
125 return CounterSampleCalculator.ComputeCounterValue (counterSample, nextCounterSample);
128 public override bool Equals (object obj)
130 if (!(obj is CounterSample))
132 return Equals ((CounterSample) obj);
135 public bool Equals (CounterSample other)
138 rawValue == other.rawValue &&
139 baseValue == other.counterFrequency &&
140 counterFrequency == other.counterFrequency &&
141 systemFrequency == other.systemFrequency &&
142 timeStamp == other.timeStamp &&
143 timeStamp100nSec == other.timeStamp100nSec &&
144 counterTimeStamp == other.counterTimeStamp &&
145 counterType == other.counterType;
148 public static bool operator == (CounterSample obj1, CounterSample obj2)
150 return obj1.Equals (obj2);
153 public static bool operator != (CounterSample obj1, CounterSample obj2)
155 return !obj1.Equals (obj2);
158 public override int GetHashCode ()
160 return (int) (rawValue << 28 ^
162 (counterFrequency << 20 ^
163 (systemFrequency << 16 ^
165 (timeStamp100nSec << 4 ^
167 (int) counterType)))))));