2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System / System.Diagnostics / CounterSample.cs
blobb357c17c8c2969844a644d3e7b250b8ef2babdc3
1 //
2 // System.Diagnostics.CounterSample.cs
3 //
4 // Authors:
5 // Jonathan Pryor (jonpryor@vt.edu)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) 2002
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:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
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,
49 long baseValue,
50 long counterFrequency,
51 long systemFrequency,
52 long timeStamp,
53 long timeStamp100nSec,
54 PerformanceCounterType counterType)
55 : this (rawValue, baseValue, counterFrequency,
56 systemFrequency, timeStamp, timeStamp100nSec,
57 counterType, 0)
61 public CounterSample (long rawValue,
62 long baseValue,
63 long counterFrequency,
64 long systemFrequency,
65 long timeStamp,
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 (
81 0, 0, 0, 0, 0, 0,
82 PerformanceCounterType.NumberOfItems32,
83 0);
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 #if NET_2_0
129 public override bool Equals (object obj)
131 if (!(obj is CounterSample))
132 return false;
133 return Equals ((CounterSample) obj);
136 public bool Equals (CounterSample other)
138 return
139 rawValue == other.rawValue &&
140 baseValue == other.counterFrequency &&
141 counterFrequency == other.counterFrequency &&
142 systemFrequency == other.systemFrequency &&
143 timeStamp == other.timeStamp &&
144 timeStamp100nSec == other.timeStamp100nSec &&
145 counterTimeStamp == other.counterTimeStamp &&
146 counterType == other.counterType;
149 public static bool operator == (CounterSample obj1, CounterSample obj2)
151 return obj1.Equals (obj2);
154 public static bool operator != (CounterSample obj1, CounterSample obj2)
156 return !obj1.Equals (obj2);
159 public override int GetHashCode ()
161 return (int) (rawValue << 28 ^
162 (baseValue << 24 ^
163 (counterFrequency << 20 ^
164 (systemFrequency << 16 ^
165 (timeStamp << 8 ^
166 (timeStamp100nSec << 4 ^
167 (counterTimeStamp ^
168 (int) counterType)))))));
170 #endif