// Will cause an update, raw value /// <include file='doc\PerformanceCounter.uex' path='docs/doc[@for="PerformanceCounter.NextSample"]/*' /> /// <devdoc> /// Obtains a counter sample and returns the raw value for it. /// </devdoc> public CounterSample NextSample() { Initialize(); CategorySample categorySample = PerformanceCounterLib.GetCategorySample(this.machineName, this.categoryName); try { CounterDefinitionSample counterSample = categorySample.GetCounterDefinitionSample(this.counterName); this.counterType = counterSample.CounterType; if (counterSample.IsSingleInstance) { if (instanceName != null && instanceName.Length != 0) { throw new InvalidOperationException(SR.GetString(SR.InstanceNameProhibited, this.instanceName)); } return(counterSample.GetSingleValue()); } else { if (instanceName == null || instanceName.Length == 0) { throw new InvalidOperationException(SR.GetString(SR.InstanceNameRequired)); } return(counterSample.GetInstanceValue(this.instanceName)); } } finally { categorySample.Dispose(); } }
/// <include file='doc\PerformanceCounterCategory.uex' path='docs/doc[@for="PerformanceCounterCategory.ReadCategory"]/*' /> /// <devdoc> /// Reads all the counter and instance data of this performance category. Note that reading the entire category /// at once can be as efficient as reading a single counter because of the way the system provides the data. /// </devdoc> public InstanceDataCollectionCollection ReadCategory() { if (this.categoryName == null) { throw new InvalidOperationException(SR.GetString(SR.CategoryNameNotSet)); } CategorySample categorySample = PerformanceCounterLib.GetCategorySample(this.machineName, this.categoryName); try { return(categorySample.ReadCategory()); } finally { categorySample.Dispose(); } }
/// <include file='doc\PerformanceCounterCategory.uex' path='docs/doc[@for="PerformanceCounterCategory.GetCounterInstances"]/*' /> /// <devdoc> /// Returns the instance names for a given category /// </devdoc> /// <internalonly/> internal static string[] GetCounterInstances(string categoryName, string machineName) { if (categoryName == null) { throw new ArgumentNullException("categoryName"); } if (categoryName.Length == 0) { throw new ArgumentException(SR.GetString(SR.InvalidParameter, "categoryName", categoryName)); } if (!SyntaxCheck.CheckMachineName(machineName)) { throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName)); } PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Browse, machineName, categoryName); permission.Demand(); CategorySample categorySample = PerformanceCounterLib.GetCategorySample(machineName, categoryName); try { if (categorySample.InstanceNameTable.Count == 0) { throw new InvalidOperationException(SR.GetString(SR.NoInstanceInformation, categoryName)); } string[] instanceNames = new string[categorySample.InstanceNameTable.Count]; categorySample.InstanceNameTable.Keys.CopyTo(instanceNames, 0); if (instanceNames.Length == 1 && instanceNames[0].CompareTo(PerformanceCounterLib.SingleInstanceName) == 0) { return(new string[0]); } return(instanceNames); } finally { categorySample.Dispose(); } }
/// <include file='doc\PerformanceCounterCategory.uex' path='docs/doc[@for="PerformanceCounterCategory.InstanceExists"]/*' /> /// <devdoc> /// Returns true if the instance already exists for this category. /// </devdoc> public bool InstanceExists(string instanceName) { if (instanceName == null) { throw new ArgumentNullException("instanceName"); } if (this.categoryName == null) { throw new InvalidOperationException(SR.GetString(SR.CategoryNameNotSet)); } CategorySample categorySample = PerformanceCounterLib.GetCategorySample(machineName, categoryName); try { IEnumerator valueEnum = categorySample.CounterTable.Values.GetEnumerator(); return(categorySample.InstanceNameTable.ContainsKey(instanceName)); } finally { categorySample.Dispose(); } }