PerformanceCounter.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //
  2. // System.Diagnostics.PerformanceCounter.cs
  3. //
  4. // Authors:
  5. // Jonathan Pryor ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) 2002
  9. // (C) 2003 Andreas Nahr
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.ComponentModel;
  33. using System.ComponentModel.Design;
  34. using System.Diagnostics;
  35. namespace System.Diagnostics {
  36. // must be safe for multithreaded operations
  37. [Designer ("Microsoft.VisualStudio.Install.PerformanceCounterDesigner, Microsoft.VisualStudio, " + Consts.AssemblyMicrosoft_VisualStudio, typeof (IDesigner))]
  38. [InstallerType (typeof (PerformanceCounterInstaller))]
  39. public sealed class PerformanceCounter : Component, ISupportInitialize
  40. {
  41. private string categoryName;
  42. private string counterName;
  43. private string instanceName;
  44. private string machineName;
  45. private bool readOnly;
  46. public static int DefaultFileMappingSize = 524288;
  47. // set catname, countname, instname to "", machname to "."
  48. public PerformanceCounter ()
  49. {
  50. categoryName = counterName = instanceName = "";
  51. machineName = ".";
  52. }
  53. // throws: InvalidOperationException (if catName or countName
  54. // is ""); ArgumentNullException if either is null
  55. // sets instName to "", machname to "."
  56. public PerformanceCounter (String categoryName,
  57. string counterName)
  58. : this (categoryName, counterName, false)
  59. {
  60. }
  61. public PerformanceCounter (string categoryName,
  62. string counterName,
  63. bool readOnly)
  64. : this (categoryName, counterName, "", readOnly)
  65. {
  66. }
  67. public PerformanceCounter (string categoryName,
  68. string counterName,
  69. string instanceName)
  70. : this (categoryName, counterName, instanceName, false)
  71. {
  72. }
  73. public PerformanceCounter (string categoryName,
  74. string counterName,
  75. string instanceName,
  76. bool readOnly)
  77. {
  78. CategoryName = categoryName;
  79. CounterName = counterName;
  80. if (categoryName == "" || counterName == "")
  81. throw new InvalidOperationException ();
  82. InstanceName = instanceName;
  83. this.instanceName = instanceName;
  84. this.machineName = ".";
  85. this.readOnly = readOnly;
  86. }
  87. public PerformanceCounter (string categoryName,
  88. string counterName,
  89. string instanceName,
  90. string machineName)
  91. : this (categoryName, counterName, instanceName, false)
  92. {
  93. this.machineName = machineName;
  94. }
  95. // may throw ArgumentNullException
  96. [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
  97. [TypeConverter ("System.Diagnostics.Design.CategoryValueConverter, " + Consts.AssemblySystem_Design)]
  98. [SRDescription ("The category name for this performance counter.")]
  99. public string CategoryName {
  100. get {return categoryName;}
  101. set {
  102. if (value == null)
  103. throw new ArgumentNullException ("categoryName");
  104. categoryName = value;
  105. }
  106. }
  107. // may throw InvalidOperationException
  108. [MonoTODO]
  109. [ReadOnly (true), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  110. [MonitoringDescription ("A description describing the counter.")]
  111. public string CounterHelp {
  112. get {return "";}
  113. }
  114. // may throw ArgumentNullException
  115. [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
  116. [TypeConverter ("System.Diagnostics.Design.CounterNameConverter, " + Consts.AssemblySystem_Design)]
  117. [SRDescription ("The name of this performance counter.")]
  118. public string CounterName
  119. {
  120. get {return counterName;}
  121. set {
  122. if (value == null)
  123. throw new ArgumentNullException ("counterName");
  124. counterName = value;
  125. }
  126. }
  127. // may throw InvalidOperationException
  128. [MonoTODO]
  129. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  130. [MonitoringDescription ("The type of the counter.")]
  131. public PerformanceCounterType CounterType {
  132. get {return 0;}
  133. }
  134. [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
  135. [TypeConverter ("System.Diagnostics.Design.InstanceNameConverter, " + Consts.AssemblySystem_Design)]
  136. [SRDescription ("The instance name for this performance counter.")]
  137. public string InstanceName
  138. {
  139. get {return instanceName;}
  140. set {instanceName = value;}
  141. }
  142. // may throw ArgumentException if machine name format is wrong
  143. [MonoTODO("What's the machine name format?")]
  144. [DefaultValue ("."), Browsable (false), RecommendedAsConfigurable (true)]
  145. [SRDescription ("The machine where this performance counter resides.")]
  146. public string MachineName {
  147. get {return machineName;}
  148. set {machineName = value;}
  149. }
  150. // may throw InvalidOperationException, Win32Exception
  151. [MonoTODO]
  152. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  153. [MonitoringDescription ("The raw value of the counter.")]
  154. public long RawValue {
  155. get {return 0;}
  156. set {
  157. throw new NotImplementedException ();
  158. }
  159. }
  160. [Browsable (false), DefaultValue (true)]
  161. [MonitoringDescription ("The accessability level of the counter.")]
  162. public bool ReadOnly {
  163. get {return readOnly;}
  164. set {readOnly = value;}
  165. }
  166. [MonoTODO]
  167. public void BeginInit ()
  168. {
  169. throw new NotImplementedException ();
  170. }
  171. [MonoTODO]
  172. public void Close ()
  173. {
  174. throw new NotImplementedException ();
  175. }
  176. [MonoTODO]
  177. public static void CloseSharedResources ()
  178. {
  179. throw new NotImplementedException ();
  180. }
  181. // may throw InvalidOperationException, Win32Exception
  182. [MonoTODO]
  183. public long Decrement ()
  184. {
  185. throw new NotImplementedException ();
  186. }
  187. [MonoTODO]
  188. protected override void Dispose (bool disposing)
  189. {
  190. throw new NotImplementedException ();
  191. }
  192. [MonoTODO]
  193. public void EndInit ()
  194. {
  195. throw new NotImplementedException ();
  196. }
  197. // may throw InvalidOperationException, Win32Exception
  198. [MonoTODO]
  199. public long Increment ()
  200. {
  201. throw new NotImplementedException ();
  202. }
  203. // may throw InvalidOperationException, Win32Exception
  204. [MonoTODO]
  205. public long IncrementBy (long value)
  206. {
  207. throw new NotImplementedException ();
  208. }
  209. // may throw InvalidOperationException, Win32Exception
  210. [MonoTODO]
  211. public CounterSample NextSample ()
  212. {
  213. throw new NotImplementedException ();
  214. }
  215. // may throw InvalidOperationException, Win32Exception
  216. [MonoTODO]
  217. public float NextValue ()
  218. {
  219. throw new NotImplementedException ();
  220. }
  221. // may throw InvalidOperationException, Win32Exception
  222. [MonoTODO]
  223. public void RemoveInstance ()
  224. {
  225. throw new NotImplementedException ();
  226. }
  227. }
  228. }