System.Drawing: added email to icon and test file headers
[mono.git] / mcs / class / System / System.Diagnostics / CounterSample.cs
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
10 //
11
12 //
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.
31 //
32
33 namespace System.Diagnostics {
34
35         public struct CounterSample {
36                 
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;
47
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)
58                 {
59                 }
60
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)
69                 {
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;
78                 }
79
80                 public static CounterSample Empty = new CounterSample (
81                         0, 0, 0, 0, 0, 0, 
82                         PerformanceCounterType.NumberOfItems32, 
83                         0);
84
85                 public long BaseValue {
86                         get {return baseValue;}
87                 }
88
89                 public long CounterFrequency {
90                         get {return counterFrequency;}
91                 }
92
93                 public long CounterTimeStamp {
94                         get {return counterTimeStamp;}
95                 }
96
97                 public PerformanceCounterType CounterType {
98                         get {return counterType;}
99                 }
100
101                 public long RawValue {
102                         get {return rawValue;}
103                 }
104
105                 public long SystemFrequency {
106                         get {return systemFrequency;}
107                 }
108
109                 public long TimeStamp {
110                         get {return timeStamp;}
111                 }
112
113                 public long TimeStamp100nSec {
114                         get {return timeStamp100nSec;}
115                 }
116
117                 public static float Calculate (CounterSample counterSample)
118                 {
119                         return CounterSampleCalculator.ComputeCounterValue (counterSample);
120                 }
121
122                 public static float Calculate (CounterSample counterSample,
123                         CounterSample nextCounterSample)
124                 {
125                         return CounterSampleCalculator.ComputeCounterValue (counterSample, nextCounterSample);
126                 }
127
128 #if NET_2_0
129                 public override bool Equals (object obj)
130                 {
131                         if (!(obj is CounterSample))
132                                 return false;
133                         return Equals ((CounterSample) obj);
134                 }
135
136                 public bool Equals (CounterSample other)
137                 {
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;
147                 }
148
149                 public static bool operator == (CounterSample obj1, CounterSample obj2)
150                 {
151                         return obj1.Equals (obj2);
152                 }
153
154                 public static bool operator != (CounterSample obj1, CounterSample obj2)
155                 {
156                         return !obj1.Equals (obj2);
157                 }
158
159                 public override int GetHashCode ()
160                 {
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)))))));
169                 }
170 #endif
171         }
172 }
173