New test.
[mono.git] / mcs / class / System / System.Diagnostics / PerformanceCounter.cs
1 //
2 // System.Diagnostics.PerformanceCounter.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 using System;
34 using System.ComponentModel;
35 using System.ComponentModel.Design;
36 using System.Diagnostics;
37
38 namespace System.Diagnostics {
39
40         // must be safe for multithreaded operations
41         [Designer ("Microsoft.VisualStudio.Install.PerformanceCounterDesigner, " + Consts.AssemblyMicrosoft_VisualStudio)]
42         [InstallerType (typeof (PerformanceCounterInstaller))]
43         public sealed class PerformanceCounter : Component, ISupportInitialize 
44         {
45
46                 private string categoryName;
47                 private string counterName;
48                 private string instanceName;
49                 private string machineName;
50                 private bool readOnly;
51
52                 public static int DefaultFileMappingSize = 524288;
53
54                 // set catname, countname, instname to "", machname to "."
55                 public PerformanceCounter ()
56                 {
57                         categoryName = counterName = instanceName = "";
58                         machineName = ".";
59                 }
60
61                 // throws: InvalidOperationException (if catName or countName
62                 // is ""); ArgumentNullException if either is null
63                 // sets instName to "", machname to "."
64                 public PerformanceCounter (String categoryName, 
65                         string counterName)
66                         : this (categoryName, counterName, false)
67                 {
68                 }
69
70                 public PerformanceCounter (string categoryName, 
71                         string counterName,
72                         bool readOnly)
73                         : this (categoryName, counterName, "", readOnly)
74                 {
75                 }
76
77                 public PerformanceCounter (string categoryName,
78                         string counterName,
79                         string instanceName)
80                         : this (categoryName, counterName, instanceName, false)
81                 {
82                 }
83
84                 public PerformanceCounter (string categoryName,
85                         string counterName,
86                         string instanceName,
87                         bool readOnly)
88                 {
89
90                         CategoryName = categoryName;
91                         CounterName = counterName;
92
93                         if (categoryName == "" || counterName == "")
94                                 throw new InvalidOperationException ();
95
96                         InstanceName = instanceName;
97                         this.instanceName = instanceName;
98                         this.machineName = ".";
99                         this.readOnly = readOnly;
100                 }
101
102                 public PerformanceCounter (string categoryName,
103                         string counterName,
104                         string instanceName,
105                         string machineName)
106                         : this (categoryName, counterName, instanceName, false)
107                 {
108                         this.machineName = machineName;
109                 }
110
111                 // may throw ArgumentNullException
112                 [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
113                 [TypeConverter ("System.Diagnostics.Design.CategoryValueConverter, " + Consts.AssemblySystem_Design)]
114                 [SRDescription ("The category name for this performance counter.")]
115                 public string CategoryName {
116                         get {return categoryName;}
117                         set {
118                                 if (value == null)
119                                         throw new ArgumentNullException ("categoryName");
120                                 categoryName = value;
121                         }
122                 }
123
124                 // may throw InvalidOperationException
125                 [MonoTODO]
126                 [ReadOnly (true), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
127                 [MonitoringDescription ("A description describing the counter.")]
128                 public string CounterHelp {
129                         get {return "";}
130                 }
131
132                 // may throw ArgumentNullException
133                 [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
134                 [TypeConverter ("System.Diagnostics.Design.CounterNameConverter, " + Consts.AssemblySystem_Design)]
135                 [SRDescription ("The name of this performance counter.")]
136                 public string CounterName 
137                         {
138                         get {return counterName;}
139                         set {
140                                 if (value == null)
141                                         throw new ArgumentNullException ("counterName");
142                                 counterName = value;
143                         }
144                 }
145
146                 // may throw InvalidOperationException
147                 [MonoTODO]
148                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
149                 [MonitoringDescription ("The type of the counter.")]
150                 public PerformanceCounterType CounterType {
151                         get {return 0;}
152                 }
153
154                 [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
155                 [TypeConverter ("System.Diagnostics.Design.InstanceNameConverter, " + Consts.AssemblySystem_Design)]
156                 [SRDescription ("The instance name for this performance counter.")]
157                 public string InstanceName 
158                         {
159                         get {return instanceName;}
160                         set {instanceName = value;}
161                 }
162
163                 // may throw ArgumentException if machine name format is wrong
164                 [MonoTODO("What's the machine name format?")]
165                 [DefaultValue ("."), Browsable (false), RecommendedAsConfigurable (true)]
166                 [SRDescription ("The machine where this performance counter resides.")]
167                 public string MachineName {
168                         get {return machineName;}
169                         set {machineName = value;}
170                 }
171
172                 // may throw InvalidOperationException, Win32Exception
173                 [MonoTODO]
174                 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
175                 [MonitoringDescription ("The raw value of the counter.")]
176                 public long RawValue {
177                         get {return 0;}
178                         set {
179                                 throw new NotImplementedException ();
180                         }
181                 }
182
183                 [Browsable (false), DefaultValue (true)]
184                 [MonitoringDescription ("The accessability level of the counter.")]
185                 public bool ReadOnly {
186                         get {return readOnly;}
187                         set {readOnly = value;}
188                 }
189
190                 [MonoTODO]
191                 public void BeginInit ()
192                 {
193                         throw new NotImplementedException ();
194                 }
195
196                 [MonoTODO]
197                 public void Close ()
198                 {
199                         throw new NotImplementedException ();
200                 }
201
202                 [MonoTODO]
203                 public static void CloseSharedResources ()
204                 {
205                         throw new NotImplementedException ();
206                 }
207
208                 // may throw InvalidOperationException, Win32Exception
209                 [MonoTODO]
210                 public long Decrement ()
211                 {
212                         throw new NotImplementedException ();
213                 }
214
215                 [MonoTODO]
216                 protected override void Dispose (bool disposing)
217                 {
218                         throw new NotImplementedException ();
219                 }
220
221                 [MonoTODO]
222                 public void EndInit ()
223                 {
224                         throw new NotImplementedException ();
225                 }
226
227                 // may throw InvalidOperationException, Win32Exception
228                 [MonoTODO]
229                 public long Increment ()
230                 {
231                         throw new NotImplementedException ();
232                 }
233
234                 // may throw InvalidOperationException, Win32Exception
235                 [MonoTODO]
236                 public long IncrementBy (long value)
237                 {
238                         throw new NotImplementedException ();
239                 }
240
241                 // may throw InvalidOperationException, Win32Exception
242                 [MonoTODO]
243                 public CounterSample NextSample ()
244                 {
245                         throw new NotImplementedException ();
246                 }
247
248                 // may throw InvalidOperationException, Win32Exception
249                 [MonoTODO]
250                 public float NextValue ()
251                 {
252                         throw new NotImplementedException ();
253                 }
254
255                 // may throw InvalidOperationException, Win32Exception
256                 [MonoTODO]
257                 public void RemoveInstance ()
258                 {
259                         throw new NotImplementedException ();
260                 }
261         }
262 }
263