PerformanceCounter.cs 6.2 KB

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