PerformanceCounter.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. using System;
  12. using System.ComponentModel;
  13. using System.ComponentModel.Design;
  14. using System.Diagnostics;
  15. namespace System.Diagnostics {
  16. // must be safe for multithreaded operations
  17. #if (NET_1_0)
  18. [Designer ("Microsoft.VisualStudio.Install.PerformanceCounterDesigner, Microsoft.VisualStudio, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (IDesigner))]
  19. #endif
  20. #if (NET_1_1)
  21. [Designer ("Microsoft.VisualStudio.Install.PerformanceCounterDesigner, Microsoft.VisualStudio, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (IDesigner))]
  22. #endif
  23. [InstallerType (typeof (PerformanceCounterInstaller))]
  24. public sealed class PerformanceCounter : Component, ISupportInitialize
  25. {
  26. private string categoryName;
  27. private string counterName;
  28. private string instanceName;
  29. private string machineName;
  30. private bool readOnly;
  31. public static int DefaultFileMappingSize = 524288;
  32. // set catname, countname, instname to "", machname to "."
  33. public PerformanceCounter ()
  34. {
  35. categoryName = counterName = instanceName = "";
  36. machineName = ".";
  37. }
  38. // throws: InvalidOperationException (if catName or countName
  39. // is ""); ArgumentNullException if either is null
  40. // sets instName to "", machname to "."
  41. public PerformanceCounter (String categoryName,
  42. string counterName)
  43. : this (categoryName, counterName, false)
  44. {
  45. }
  46. public PerformanceCounter (string categoryName,
  47. string counterName,
  48. bool readOnly)
  49. : this (categoryName, counterName, "", readOnly)
  50. {
  51. }
  52. public PerformanceCounter (string categoryName,
  53. string counterName,
  54. string instanceName)
  55. : this (categoryName, counterName, instanceName, false)
  56. {
  57. }
  58. public PerformanceCounter (string categoryName,
  59. string counterName,
  60. string instanceName,
  61. bool readOnly)
  62. {
  63. CategoryName = categoryName;
  64. CounterName = counterName;
  65. if (categoryName == "" || counterName == "")
  66. throw new InvalidOperationException ();
  67. InstanceName = instanceName;
  68. this.instanceName = instanceName;
  69. this.machineName = ".";
  70. this.readOnly = readOnly;
  71. }
  72. public PerformanceCounter (string categoryName,
  73. string counterName,
  74. string instanceName,
  75. string machineName)
  76. : this (categoryName, counterName, instanceName, false)
  77. {
  78. this.machineName = machineName;
  79. }
  80. // may throw ArgumentNullException
  81. [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
  82. #if (NET_1_0)
  83. [TypeConverter ("System.Diagnostics.Design.CategoryValueConverter, System.Design, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  84. #endif
  85. #if (NET_1_1)
  86. [TypeConverter ("System.Diagnostics.Design.CategoryValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  87. #endif
  88. public string CategoryName {
  89. get {return categoryName;}
  90. set {
  91. if (value == null)
  92. throw new ArgumentNullException ("categoryName");
  93. categoryName = value;
  94. }
  95. }
  96. // may throw InvalidOperationException
  97. [MonoTODO]
  98. [ReadOnly (true), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  99. [MonitoringDescription ("A description describing the counter.")]
  100. public string CounterHelp {
  101. get {return "";}
  102. }
  103. // may throw ArgumentNullException
  104. [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
  105. #if (NET_1_0)
  106. [TypeConverter ("System.Diagnostics.Design.CounterNameConverter, System.Design, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  107. #endif
  108. #if (NET_1_1)
  109. [TypeConverter ("System.Diagnostics.Design.CounterNameConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  110. #endif
  111. public string CounterName
  112. {
  113. get {return counterName;}
  114. set {
  115. if (value == null)
  116. throw new ArgumentNullException ("counterName");
  117. counterName = value;
  118. }
  119. }
  120. // may throw InvalidOperationException
  121. [MonoTODO]
  122. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  123. [MonitoringDescription ("The type of the counter.")]
  124. public PerformanceCounterType CounterType {
  125. get {return 0;}
  126. }
  127. [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
  128. #if (NET_1_0)
  129. [TypeConverter ("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  130. #endif
  131. #if (NET_1_1)
  132. [TypeConverter ("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  133. #endif
  134. public string InstanceName
  135. {
  136. get {return instanceName;}
  137. set {instanceName = value;}
  138. }
  139. // may throw ArgumentException if machine name format is wrong
  140. [MonoTODO("What's the machine name format?")]
  141. [DefaultValue ("."), Browsable (false), RecommendedAsConfigurable (true)]
  142. public string MachineName {
  143. get {return machineName;}
  144. set {machineName = value;}
  145. }
  146. // may throw InvalidOperationException, Win32Exception
  147. [MonoTODO]
  148. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  149. [MonitoringDescription ("The raw value of the counter.")]
  150. public long RawValue {
  151. get {return 0;}
  152. set {
  153. throw new NotImplementedException ();
  154. }
  155. }
  156. [Browsable (false), DefaultValue (true)]
  157. [MonitoringDescription ("The accessability level of the counter.")]
  158. public bool ReadOnly {
  159. get {return readOnly;}
  160. set {readOnly = value;}
  161. }
  162. [MonoTODO]
  163. public void BeginInit ()
  164. {
  165. throw new NotImplementedException ();
  166. }
  167. [MonoTODO]
  168. public void Close ()
  169. {
  170. throw new NotImplementedException ();
  171. }
  172. [MonoTODO]
  173. public static void CloseSharedResources ()
  174. {
  175. throw new NotImplementedException ();
  176. }
  177. // may throw InvalidOperationException, Win32Exception
  178. [MonoTODO]
  179. public long Decrement ()
  180. {
  181. throw new NotImplementedException ();
  182. }
  183. [MonoTODO]
  184. protected override void Dispose (bool disposing)
  185. {
  186. throw new NotImplementedException ();
  187. }
  188. [MonoTODO]
  189. public void EndInit ()
  190. {
  191. throw new NotImplementedException ();
  192. }
  193. // may throw InvalidOperationException, Win32Exception
  194. [MonoTODO]
  195. public long Increment ()
  196. {
  197. throw new NotImplementedException ();
  198. }
  199. // may throw InvalidOperationException, Win32Exception
  200. [MonoTODO]
  201. public long IncrementBy (long value)
  202. {
  203. throw new NotImplementedException ();
  204. }
  205. // may throw InvalidOperationException, Win32Exception
  206. [MonoTODO]
  207. public CounterSample NextSample ()
  208. {
  209. throw new NotImplementedException ();
  210. }
  211. // may throw InvalidOperationException, Win32Exception
  212. [MonoTODO]
  213. public float NextValue ()
  214. {
  215. throw new NotImplementedException ();
  216. }
  217. // may throw InvalidOperationException, Win32Exception
  218. [MonoTODO]
  219. public void RemoveInstance ()
  220. {
  221. throw new NotImplementedException ();
  222. }
  223. }
  224. }