2 // System.Diagnostics.PerformanceCounter.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.
34 using System
.ComponentModel
;
35 using System
.ComponentModel
.Design
;
36 using System
.Diagnostics
;
38 namespace System
.Diagnostics
{
40 // must be safe for multithreaded operations
41 [Designer ("Microsoft.VisualStudio.Install.PerformanceCounterDesigner, Microsoft.VisualStudio, " + Consts
.AssemblyMicrosoft_VisualStudio
, typeof (IDesigner
))]
42 [InstallerType (typeof (PerformanceCounterInstaller
))]
43 public sealed class PerformanceCounter
: Component
, ISupportInitialize
46 private string categoryName
;
47 private string counterName
;
48 private string instanceName
;
49 private string machineName
;
50 private bool readOnly
;
52 public static int DefaultFileMappingSize
= 524288;
54 // set catname, countname, instname to "", machname to "."
55 public PerformanceCounter ()
57 categoryName
= counterName
= instanceName
= "";
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
,
66 : this (categoryName
, counterName
, false)
70 public PerformanceCounter (string categoryName
,
73 : this (categoryName
, counterName
, "", readOnly
)
77 public PerformanceCounter (string categoryName
,
80 : this (categoryName
, counterName
, instanceName
, false)
84 public PerformanceCounter (string categoryName
,
90 CategoryName
= categoryName
;
91 CounterName
= counterName
;
93 if (categoryName
== "" || counterName
== "")
94 throw new InvalidOperationException ();
96 InstanceName
= instanceName
;
97 this.instanceName
= instanceName
;
98 this.machineName
= ".";
99 this.readOnly
= readOnly
;
102 public PerformanceCounter (string categoryName
,
106 : this (categoryName
, counterName
, instanceName
, false)
108 this.machineName
= machineName
;
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;}
119 throw new ArgumentNullException ("categoryName");
120 categoryName
= value;
124 // may throw InvalidOperationException
126 [ReadOnly (true), DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
127 [MonitoringDescription ("A description describing the counter.")]
128 public string CounterHelp
{
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
138 get {return counterName;}
141 throw new ArgumentNullException ("counterName");
146 // may throw InvalidOperationException
148 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
149 [MonitoringDescription ("The type of the counter.")]
150 public PerformanceCounterType CounterType
{
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
159 get {return instanceName;}
160 set {instanceName = value;}
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;}
172 // may throw InvalidOperationException, Win32Exception
174 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
175 [MonitoringDescription ("The raw value of the counter.")]
176 public long RawValue
{
179 throw new NotImplementedException ();
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;}
191 public void BeginInit ()
193 throw new NotImplementedException ();
199 throw new NotImplementedException ();
203 public static void CloseSharedResources ()
205 throw new NotImplementedException ();
208 // may throw InvalidOperationException, Win32Exception
210 public long Decrement ()
212 throw new NotImplementedException ();
216 protected override void Dispose (bool disposing
)
218 throw new NotImplementedException ();
222 public void EndInit ()
224 throw new NotImplementedException ();
227 // may throw InvalidOperationException, Win32Exception
229 public long Increment ()
231 throw new NotImplementedException ();
234 // may throw InvalidOperationException, Win32Exception
236 public long IncrementBy (long value)
238 throw new NotImplementedException ();
241 // may throw InvalidOperationException, Win32Exception
243 public CounterSample
NextSample ()
245 throw new NotImplementedException ();
248 // may throw InvalidOperationException, Win32Exception
250 public float NextValue ()
252 throw new NotImplementedException ();
255 // may throw InvalidOperationException, Win32Exception
257 public void RemoveInstance ()
259 throw new NotImplementedException ();