/// <summary> /// Initializes a new instance of the <see cref="PerformanceCounterCategoryInfo"/> class. /// </summary> /// <param name="categoryName">Name of the category.</param> /// <param name="categoryType">Type of the category.</param> /// <param name="categoryHelp">The category help.</param> public PerformanceCounterCategoryInfo(string categoryName, PerformanceCounterCategoryType categoryType, string categoryHelp) { CategoryName = categoryName; CategoryType = categoryType; CategoryHelp = categoryHelp; }
protected InstrumentationManager(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType) { _categoryName = categoryName; _categoryHelp = categoryHelp; _categoryType = categoryType; _counterDefinitions = new CounterCreationDataCollection(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">category name to be shown</param> /// <param name="instanceType">category Type (single or multiIntance)</param> /// <param name="info">Information to be shown for this category</param> /// <seealso cref="PerformanceCounterCategoryType"/> public PerformanceCounterCategoryAttribute(string name, PerformanceCounterCategoryType instanceType, string info) : base() { this._name = name; this._info = info; this._instanceType = instanceType; }
public FluentCategoryConfigurator AddCategory( string name, string help = "", PerformanceCounterCategoryType type = PerformanceCounterCategoryType.SingleInstance) { return _map.GetOrAdd(name, new FluentCategoryConfigurator(name, help, type, this)); }
public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) { Contract.Ensures(0 <= categoryName.Length); Contract.Ensures(categoryName.Length <= 997); Contract.Ensures(Contract.Result<System.Diagnostics.PerformanceCounterCategory>() != null); return default(System.Diagnostics.PerformanceCounterCategory); }
public FluentCategoryConfigurator( string name, string help, PerformanceCounterCategoryType type, FluentConfigurator parent) { _name = name; _help = help; _type = type; _parent = parent; }
protected PerformanceCounterAttribute( string categoryName, string counterName, PerformanceCounterType counterType, PerformanceCounterType? baseCounterType) { this.CategoryName = categoryName; this.CounterName = counterName; this.BaseCounterName = counterName + "Base"; this.CounterType = counterType; this.BaseCounterType = baseCounterType; this.CategoryType=PerformanceCounterCategoryType.MultiInstance; this.sharedDataRef = sharedData; }
/// <summary> /// Create a Performance counter install attribute to assist in run-time perfmon counter creation /// </summary> /// <param name="type">This counters internal type. Needed base types are automagically created with the name appended with 'base'</param> /// <param name="category">This counters category. All categories are fixed at the time of creation</param> /// <param name="lifetime">This counters lifetime, by default all counters are global except for dynamically created instances</param> /// <param name="categoryType">The category type (multi or single instance)</param> /// <param name="ConnectInstancetype">The CSGO instance type </param> /// <param name="counterName">This counters name</param> /// <param name="counterHelp">This counters help string</param> public PerformanceCounterInstallAttribute( PerformanceCounterType type, PerformanceCounterCategories category, PerformanceCounterInstanceLifetime lifetime, PerformanceCounterCategoryType categoryType, CounterInstanceType counterInstancetype, string counterName, string counterHelp, string instanceType) { _type = type; _category = category; _lifeTime = lifetime; _categoryType = categoryType; _counterInstanceType = counterInstancetype; _counterName = counterName; _counterHelp = counterHelp; _instanceType = instanceType; }
/// <summary> /// Ensures that the given performance counter category name /// exists and that all counters specified are available /// within the category. /// </summary> /// <param name="categoryName">Name of the category.</param> /// <param name="categoryDescription">The category description.</param> /// <param name="instancingMode"> /// The instancing mode expected from counters. Only /// evaluated if the category gets created.. /// </param> /// <param name="data">The data.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// categoryName or data /// </exception> /// <exception cref="System.ArgumentException">data</exception> internal static bool AssertPerformanceCounterCategory( string categoryName, string categoryDescription, PerformanceCounterCategoryType instancingMode, params CounterCreationData[] data) { if (categoryName == null) throw new ArgumentNullException("categoryName"); if (data == null) throw new ArgumentNullException("data"); if (data.Length == 0) throw new ArgumentException("data"); try { if (PerformanceCounterCategory.Exists(categoryName)) { foreach (var def in data) { if (!PerformanceCounterCategory.CounterExists(def.CounterName, categoryName)) { PerformanceCounterCategory.Delete(categoryName); break; } } } if (!PerformanceCounterCategory.Exists(categoryName)) { PerformanceCounterCategory.Create(categoryName, categoryDescription, instancingMode, new CounterCreationDataCollection(data)); } return true; } catch (Exception ex) { System.Diagnostics.Trace.TraceError("Failed to initialize performance counter category. {0}", ex.ToString()); return false; } }
internal CounterSet(string setName, string machineName, PerformanceCounterCategoryType categoryType, string setHelp, ref Dictionary<string, string[]> counterInstanceMapping) { this._counterSetName = setName; if ((machineName == null) || (machineName.Length == 0)) { machineName = "."; } else { this._machineName = machineName; if (!this._machineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase)) { this._machineName = @"\\" + this._machineName; } } this._counterSetType = categoryType; this._description = setHelp; this._counterInstanceMapping = counterInstanceMapping; }
private static string[] GetProcessInstanceNames ( PerformanceCounterCategoryType categoryType, int pid ) { PerformanceCounterCategory cat = new PerformanceCounterCategory( categoryType.GetName() ); List<string> names = new List<string>(); string[] instances = cat.GetInstanceNames(); foreach ( string instance in instances ) { using ( PerformanceCounter cnt = new PerformanceCounter( categoryType.GetName(), categoryType.GetProcessIdCounterName() , instance, true ) ) { int val = (int)cnt.RawValue; if ( val == pid ) { names.Add( instance ); } } } return names.ToArray(); }
/// <summary> /// This method will create a new counter category. /// sdfsdf /// Note that only one counter is added in this code. /// If more than one counter needs to be created simply copy /// the code that creates the sampleCounter object and add it /// to the counterData array. /// Any counters added to the counterData array will be created /// when you call the Create method on the PerformanceCounterCategory /// object. /// /// Also notice the "SingleInstance" portion of the Create() call. /// This disables multiple instances for the specified counter. /// If you need multiple instances you can simply change "SingleInstance" /// to "MultiInstance" when you call the Create method. /// /// Once the Create() method is called the counter is ready for you to /// write data to it. /// </summary> /// <param name="categoryName">Category name</param> /// <param name="categoryHelp">Category help text</param> /// <param name="categoryType">Category type</param> /// <param name="counterName">Counter name</param> /// <param name="counterHelp">Counter help text</param> /// <param name="counterType">Counter type</param> public static void createCounter( string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp, PerformanceCounterType counterType ) { if (!PerformanceCounterCategory.Exists(categoryName)) { // Create the collection that will hold the data // for the counters we are creating. CounterCreationDataCollection counterData = new CounterCreationDataCollection(); // Create the CreationData object CounterCreationData counter = new CounterCreationData(); // Set the counter's type, name and help text counter.CounterType = counterType; counter.CounterName = counterName; counter.CounterHelp = counterHelp; // Add the creation data object to // our collection counterData.Add(counter); // Create the counter in the system using // the collection PerformanceCounterCategory.Create( categoryName, categoryHelp, categoryType, counterData ); } }
private static CounterCreationDataCollection GetCounterCreationDataCollection(IEnumerable<PerformanceCounterTarget> countersInCategory, out PerformanceCounterCategoryType categoryType) { categoryType = PerformanceCounterCategoryType.SingleInstance; var ccds = new CounterCreationDataCollection(); foreach (var counter in countersInCategory) { if (!string.IsNullOrEmpty(counter.InstanceName)) { categoryType = PerformanceCounterCategoryType.MultiInstance; } ccds.Add(new CounterCreationData(counter.CounterName, counter.CounterHelp, counter.CounterType)); } return ccds; }
// // ProcessListSet(). // Does the work to process ListSet parameter set. // private void ProcessListSet() { uint res = _pdhHelper.ConnectToDataSource(_resolvedPaths); if (res != 0) { ReportPdhError(res, true); return; } StringCollection machineNames = new StringCollection(); res = _pdhHelper.EnumBlgFilesMachines(ref machineNames); if (res != 0) { ReportPdhError(res, true); return; } foreach (string machine in machineNames) { StringCollection counterSets = new StringCollection(); res = _pdhHelper.EnumObjects(machine, ref counterSets); if (res != 0) { return; } StringCollection validPaths = new StringCollection(); foreach (string pattern in _listSet) { bool bMatched = false; WildcardPattern wildLogPattern = new WildcardPattern(pattern, WildcardOptions.IgnoreCase); foreach (string counterSet in counterSets) { if (!wildLogPattern.IsMatch(counterSet)) { continue; } StringCollection counterSetCounters = new StringCollection(); StringCollection counterSetInstances = new StringCollection(); res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances); if (res != 0) { ReportPdhError(res, false); continue; } string[] instanceArray = new string[counterSetInstances.Count]; int i = 0; foreach (string instance in counterSetInstances) { instanceArray[i++] = instance; } Dictionary <string, string[]> counterInstanceMapping = new Dictionary <string, string[]>(); foreach (string counter in counterSetCounters) { counterInstanceMapping.Add(counter, instanceArray); } PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.Unknown; if (counterSetInstances.Count > 1) { categoryType = PerformanceCounterCategoryType.MultiInstance; } else // if (counterSetInstances.Count == 1) //??? { categoryType = PerformanceCounterCategoryType.SingleInstance; } string setHelp = _pdhHelper.GetCounterSetHelp(machine, counterSet); CounterSet setObj = new CounterSet(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping); WriteObject(setObj); bMatched = true; } if (!bMatched) { string msg = _resourceMgr.GetString("NoMatchingCounterSetsInFile"); Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg, CommonUtilities.StringArrayToString(_resolvedPaths), pattern)); WriteError(new ErrorRecord(exc, "NoMatchingCounterSetsInFile", ErrorCategory.ObjectNotFound, null)); } } } }
private static void CreateRegistryEntry(string categoryName, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection creationData, ref bool iniRegistered) { RegistryKey key = null; RegistryKey key2 = null; RegistryKey key3 = null; new RegistryPermission(PermissionState.Unrestricted).Assert(); try { key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services", true); key2 = key.OpenSubKey(categoryName + @"\Performance", true); if (key2 == null) { key2 = key.CreateSubKey(categoryName + @"\Performance"); } key2.SetValue("Open", "OpenPerformanceData"); key2.SetValue("Collect", "CollectPerformanceData"); key2.SetValue("Close", "ClosePerformanceData"); key2.SetValue("Library", "netfxperf.dll"); key2.SetValue("IsMultiInstance", (int)categoryType, RegistryValueKind.DWord); key2.SetValue("CategoryOptions", 3, RegistryValueKind.DWord); string[] strArray = new string[creationData.Count]; string[] strArray2 = new string[creationData.Count]; for (int i = 0; i < creationData.Count; i++) { strArray[i] = creationData[i].CounterName; strArray2[i] = ((int)creationData[i].CounterType).ToString(CultureInfo.InvariantCulture); } key3 = key.OpenSubKey(categoryName + @"\Linkage", true); if (key3 == null) { key3 = key.CreateSubKey(categoryName + @"\Linkage"); } key3.SetValue("Export", new string[] { categoryName }); key2.SetValue("Counter Types", strArray2); key2.SetValue("Counter Names", strArray); if (key2.GetValue("First Counter") != null) { iniRegistered = true; } else { iniRegistered = false; } } finally { if (key2 != null) { key2.Close(); } if (key3 != null) { key3.Close(); } if (key != null) { key.Close(); } CodeAccessPermission.RevertAssert(); } }
public static PerformanceCounter CreateCounterWithCategory(string name, bool readOnly, PerformanceCounterCategoryType categoryType) { var category = Helpers.CreateCategory(name, categoryType); PerformanceCounter counterSample = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter(category, name, readOnly)); return(counterSample); }
static private unsafe extern bool Create_icall(char *categoryName, int categoryName_length, char *categoryHelp, int categoryHelp_length, PerformanceCounterCategoryType categoryType, CounterCreationData[] items);
static PerformanceCounterCategory Create ( string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) { CheckCategory (categoryName); CounterCreationData[] items = new CounterCreationData [1]; // we use PerformanceCounterType.NumberOfItems32 as the default type items [0] = new CounterCreationData (counterName, counterHelp, PerformanceCounterType.NumberOfItems32); if (!Create (categoryName, categoryHelp, categoryType, items)) throw new InvalidOperationException (); return new PerformanceCounterCategory (categoryName, categoryHelp); }
private static CounterCreationDataCollection GetCounterCreationDataCollection(IEnumerable <PerformanceCounterTarget> countersInCategory, out PerformanceCounterCategoryType categoryType) { categoryType = PerformanceCounterCategoryType.SingleInstance; var ccds = new CounterCreationDataCollection(); foreach (var counter in countersInCategory) { if (!string.IsNullOrEmpty(counter.InstanceName)) { categoryType = PerformanceCounterCategoryType.MultiInstance; } ccds.Add(new CounterCreationData(counter.CounterName, counter.CounterHelp, counter.CounterType)); } return(ccds); }
private static void CreateRegistryEntry(string categoryName, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection creationData, ref bool iniRegistered) { RegistryKey key = null; RegistryKey key2 = null; RegistryKey key3 = null; new RegistryPermission(PermissionState.Unrestricted).Assert(); try { key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services", true); key2 = key.OpenSubKey(categoryName + @"\Performance", true); if (key2 == null) { key2 = key.CreateSubKey(categoryName + @"\Performance"); } key2.SetValue("Open", "OpenPerformanceData"); key2.SetValue("Collect", "CollectPerformanceData"); key2.SetValue("Close", "ClosePerformanceData"); key2.SetValue("Library", "netfxperf.dll"); key2.SetValue("IsMultiInstance", (int) categoryType, RegistryValueKind.DWord); key2.SetValue("CategoryOptions", 3, RegistryValueKind.DWord); string[] strArray = new string[creationData.Count]; string[] strArray2 = new string[creationData.Count]; for (int i = 0; i < creationData.Count; i++) { strArray[i] = creationData[i].CounterName; strArray2[i] = ((int) creationData[i].CounterType).ToString(CultureInfo.InvariantCulture); } key3 = key.OpenSubKey(categoryName + @"\Linkage", true); if (key3 == null) { key3 = key.CreateSubKey(categoryName + @"\Linkage"); } key3.SetValue("Export", new string[] { categoryName }); key2.SetValue("Counter Types", strArray2); key2.SetValue("Counter Names", strArray); if (key2.GetValue("First Counter") != null) { iniRegistered = true; } else { iniRegistered = false; } } finally { if (key2 != null) { key2.Close(); } if (key3 != null) { key3.Close(); } if (key != null) { key.Close(); } CodeAccessPermission.RevertAssert(); } }
public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) { if (categoryType < PerformanceCounterCategoryType.Unknown || categoryType > PerformanceCounterCategoryType.MultiInstance) { throw new ArgumentOutOfRangeException(nameof(categoryType)); } if (counterData == null) { throw new ArgumentNullException(nameof(counterData)); } CheckValidCategory(categoryName); if (categoryHelp != null) { // null categoryHelp is a valid option - it gets set to "Help Not Available" later on. CheckValidHelp(categoryHelp); } string machineName = "."; Mutex mutex = null; try { NetFrameworkUtils.EnterMutex(PerfMutexName, ref mutex); if (PerformanceCounterLib.IsCustomCategory(machineName, categoryName) || PerformanceCounterLib.CategoryExists(machineName, categoryName)) { throw new InvalidOperationException(SR.Format(SR.PerformanceCategoryExists, categoryName)); } CheckValidCounterLayout(counterData); PerformanceCounterLib.RegisterCategory(categoryName, categoryType, categoryHelp, counterData); return(new PerformanceCounterCategory(categoryName, machineName)); } finally { if (mutex != null) { mutex.ReleaseMutex(); mutex.Close(); } } }
public IICPerformanceCounterCategory(string categoryName, PerformanceCounterCategoryType categoryType) : this(categoryName, categoryType, categoryName) { }
/// <summary> /// Registers one extensible performance category of the specified category type with counter type NumberOfItems32 with the system /// </summary> public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) { CounterCreationData customData = new CounterCreationData(counterName, counterHelp, PerformanceCounterType.NumberOfItems32); return(Create(categoryName, categoryHelp, categoryType, new CounterCreationDataCollection(new CounterCreationData[] { customData }))); }
static extern bool Create (string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationData[] items);
static bool Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationData[] items) { throw new System.NotImplementedException(); }
public IICPerformanceCountersAttribute(string categoryName, PerformanceCounterCategoryType categoryType, string categoryHelp) { CategoryName = categoryName; CategoryType = categoryType; CategoryHelp = categoryHelp; }
internal bool FindCustomCategory(string category, out PerformanceCounterCategoryType categoryType) { RegistryKey key = null; RegistryKey key2 = null; categoryType = PerformanceCounterCategoryType.Unknown; if (this.customCategoryTable == null) { Interlocked.CompareExchange <Hashtable>(ref this.customCategoryTable, new Hashtable(StringComparer.OrdinalIgnoreCase), null); } if (this.customCategoryTable.ContainsKey(category)) { categoryType = (PerformanceCounterCategoryType)this.customCategoryTable[category]; return(true); } PermissionSet set = new PermissionSet(PermissionState.None); set.AddPermission(new RegistryPermission(PermissionState.Unrestricted)); set.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)); set.Assert(); try { string name = @"SYSTEM\CurrentControlSet\Services\" + category + @"\Performance"; if ((this.machineName == ".") || (string.Compare(this.machineName, ComputerName, StringComparison.OrdinalIgnoreCase) == 0)) { key = Registry.LocalMachine.OpenSubKey(name); } else { key2 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, @"\\" + this.machineName); if (key2 != null) { try { key = key2.OpenSubKey(name); } catch (SecurityException) { categoryType = PerformanceCounterCategoryType.Unknown; this.customCategoryTable[category] = (PerformanceCounterCategoryType)categoryType; return(false); } } } if (key != null) { object obj2 = key.GetValue("Library"); if (((obj2 != null) && (obj2 is string)) && (string.Compare((string)obj2, "netfxperf.dll", StringComparison.OrdinalIgnoreCase) == 0)) { object obj3 = key.GetValue("IsMultiInstance"); if (obj3 != null) { categoryType = (PerformanceCounterCategoryType)obj3; if ((categoryType < PerformanceCounterCategoryType.Unknown) || (categoryType > PerformanceCounterCategoryType.MultiInstance)) { categoryType = PerformanceCounterCategoryType.Unknown; } } else { categoryType = PerformanceCounterCategoryType.Unknown; } object obj4 = key.GetValue("First Counter"); if (obj4 != null) { int num1 = (int)obj4; this.customCategoryTable[category] = (PerformanceCounterCategoryType)categoryType; return(true); } } } } finally { if (key != null) { key.Close(); } if (key2 != null) { key2.Close(); } PermissionSet.RevertAssert(); } return(false); }
public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) { PerformanceCounterCategory category; if ((categoryType < PerformanceCounterCategoryType.Unknown) || (categoryType > PerformanceCounterCategoryType.MultiInstance)) { throw new ArgumentOutOfRangeException("categoryType"); } if (counterData == null) { throw new ArgumentNullException("counterData"); } CheckValidCategory(categoryName); if (categoryHelp != null) { CheckValidHelp(categoryHelp); } string machineName = "."; new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer, machineName, categoryName).Demand(); SharedUtils.CheckNtEnvironment(); Mutex mutex = null; RuntimeHelpers.PrepareConstrainedRegions(); try { SharedUtils.EnterMutex("netfxperf.1.0", ref mutex); if (PerformanceCounterLib.IsCustomCategory(machineName, categoryName) || PerformanceCounterLib.CategoryExists(machineName, categoryName)) { throw new InvalidOperationException(SR.GetString("PerformanceCategoryExists", new object[] { categoryName })); } CheckValidCounterLayout(counterData); PerformanceCounterLib.RegisterCategory(categoryName, categoryType, categoryHelp, counterData); category = new PerformanceCounterCategory(categoryName, machineName); } finally { if (mutex != null) { mutex.ReleaseMutex(); mutex.Close(); } } return category; }
private static PerformanceCounter CreatePerformanceCounter( string categoryName, string counterName, PerformanceCounterCategoryType categoryType, bool isReadOnly) { if (categoryType == PerformanceCounterCategoryType.MultiInstance) { return new PerformanceCounter(categoryName, counterName, PerformanceCounterSettings.InstanceName, isReadOnly); } else { return new PerformanceCounter(categoryName, counterName, isReadOnly); } }
internal bool FindCustomCategory(string category, out PerformanceCounterCategoryType categoryType) { RegistryKey key = null; RegistryKey key2 = null; categoryType = PerformanceCounterCategoryType.Unknown; if (this.customCategoryTable == null) { Interlocked.CompareExchange<Hashtable>(ref this.customCategoryTable, new Hashtable(StringComparer.OrdinalIgnoreCase), null); } if (this.customCategoryTable.ContainsKey(category)) { categoryType = (PerformanceCounterCategoryType) this.customCategoryTable[category]; return true; } PermissionSet set = new PermissionSet(PermissionState.None); set.AddPermission(new RegistryPermission(PermissionState.Unrestricted)); set.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)); set.Assert(); try { string name = @"SYSTEM\CurrentControlSet\Services\" + category + @"\Performance"; if ((this.machineName == ".") || (string.Compare(this.machineName, ComputerName, StringComparison.OrdinalIgnoreCase) == 0)) { key = Registry.LocalMachine.OpenSubKey(name); } else { key2 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, @"\\" + this.machineName); if (key2 != null) { try { key = key2.OpenSubKey(name); } catch (SecurityException) { categoryType = PerformanceCounterCategoryType.Unknown; this.customCategoryTable[category] = (PerformanceCounterCategoryType) categoryType; return false; } } } if (key != null) { object obj2 = key.GetValue("Library"); if (((obj2 != null) && (obj2 is string)) && (string.Compare((string) obj2, "netfxperf.dll", StringComparison.OrdinalIgnoreCase) == 0)) { object obj3 = key.GetValue("IsMultiInstance"); if (obj3 != null) { categoryType = (PerformanceCounterCategoryType) obj3; if ((categoryType < PerformanceCounterCategoryType.Unknown) || (categoryType > PerformanceCounterCategoryType.MultiInstance)) { categoryType = PerformanceCounterCategoryType.Unknown; } } else { categoryType = PerformanceCounterCategoryType.Unknown; } object obj4 = key.GetValue("First Counter"); if (obj4 != null) { int num1 = (int) obj4; this.customCategoryTable[category] = (PerformanceCounterCategoryType) categoryType; return true; } } } } finally { if (key != null) { key.Close(); } if (key2 != null) { key2.Close(); } PermissionSet.RevertAssert(); } return false; }
public string[] GetCategoryInstanceNames ( PerformanceCounterCategoryType categoryType, Process process ) { var category = new PerformanceCounterCategory( categoryType.GetName() ); return GetProcessInstanceNames( categoryType, process.Id ); // category.GetInstanceNames().Where( s => s == process.ProcessName ).ToArray(); }
static PerformanceCounterCategory Create ( string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) { CheckCategory (categoryName); if (counterData == null) throw new ArgumentNullException ("counterData"); if (counterData.Count == 0) throw new ArgumentException ("counterData"); CounterCreationData[] items = new CounterCreationData [counterData.Count]; counterData.CopyTo (items, 0); if (!Create (categoryName, categoryHelp, categoryType, items)) throw new InvalidOperationException (); return new PerformanceCounterCategory (categoryName, categoryHelp); }
// // ProcessListSetPerMachine() helper lists counter sets on a machine. // NOTE: machine argument should be NULL for the local machine // private void ProcessListSetPerMachine(string machine) { StringCollection counterSets = new StringCollection(); uint res = _pdhHelper.EnumObjects(machine, ref counterSets); if (res != 0) { //add an error message string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoCounterSetsOnComputer"), machine, res); Exception exc = new Exception(msg); WriteError(new ErrorRecord(exc, "NoCounterSetsOnComputer", ErrorCategory.InvalidResult, machine)); return; } CultureInfo culture = Thread.CurrentThread.CurrentUICulture; List <Tuple <char, char> > characterReplacementList = null; StringCollection validPaths = new StringCollection(); _cultureAndSpecialCharacterMap.TryGetValue(culture.LCID, out characterReplacementList); foreach (string pattern in _listSet) { bool bMatched = false; string normalizedPattern = pattern; if (characterReplacementList != null) { foreach (Tuple <char, char> pair in characterReplacementList) { normalizedPattern = normalizedPattern.Replace(pair.Item1, pair.Item2); } } WildcardPattern wildLogPattern = new WildcardPattern(normalizedPattern, WildcardOptions.IgnoreCase); foreach (string counterSet in counterSets) { if (!wildLogPattern.IsMatch(counterSet)) { continue; } StringCollection counterSetCounters = new StringCollection(); StringCollection counterSetInstances = new StringCollection(); res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances); if (res == PdhResults.PDH_ACCESS_DENIED) { string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterSetEnumAccessDenied"), counterSet); Exception exc = new Exception(msg); WriteError(new ErrorRecord(exc, "CounterSetEnumAccessDenied", ErrorCategory.InvalidResult, null)); continue; } else if (res != 0) { ReportPdhError(res, false); continue; } string[] instanceArray = new string[counterSetInstances.Count]; int i = 0; foreach (string instance in counterSetInstances) { instanceArray[i++] = instance; } // // Special case: no instances present: change to * to create a valid paths // if (instanceArray.Length == 1 && instanceArray[0].Length == 0) { instanceArray[0] = "*"; } Dictionary <string, string[]> counterInstanceMapping = new Dictionary <string, string[]>(); foreach (string counter in counterSetCounters) { if (!counterInstanceMapping.ContainsKey(counter)) { counterInstanceMapping.Add(counter, instanceArray); } } PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.Unknown; if (counterSetInstances.Count > 1) { categoryType = PerformanceCounterCategoryType.MultiInstance; } else //if (counterSetInstances.Count == 1) //??? { categoryType = PerformanceCounterCategoryType.SingleInstance; } string setHelp = _pdhHelper.GetCounterSetHelp(machine, counterSet); CounterSet setObj = new CounterSet(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping); WriteObject(setObj); bMatched = true; } if (!bMatched) { string msg = _resourceMgr.GetString("NoMatchingCounterSetsFound"); Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg, machine ?? "localhost", normalizedPattern)); WriteError(new ErrorRecord(exc, "NoMatchingCounterSetsFound", ErrorCategory.ObjectNotFound, null)); } } }
static extern bool Create (string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationData[] items);
private static void CreateRegistryEntry(string categoryName, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection creationData, ref bool iniRegistered) { RegistryKey serviceParentKey = null; RegistryKey serviceKey = null; RegistryKey linkageKey = null; //SECREVIEW: Whoever is able to call this function, must already // have demmanded PerformanceCounterPermission // we can therefore assert the RegistryPermission. RegistryPermission registryPermission = new RegistryPermission(PermissionState.Unrestricted); registryPermission.Assert(); try { serviceParentKey = Registry.LocalMachine.OpenSubKey(ServicePath, true); serviceKey = serviceParentKey.OpenSubKey(categoryName + "\\Performance", true); if (serviceKey == null) serviceKey = serviceParentKey.CreateSubKey(categoryName + "\\Performance"); serviceKey.SetValue("Open","OpenPerformanceData"); serviceKey.SetValue("Collect", "CollectPerformanceData"); serviceKey.SetValue("Close","ClosePerformanceData"); serviceKey.SetValue("Library", DllName); serviceKey.SetValue("IsMultiInstance", (int) categoryType, RegistryValueKind.DWord); serviceKey.SetValue("CategoryOptions", 0x3, RegistryValueKind.DWord); string [] counters = new string[creationData.Count]; string [] counterTypes = new string[creationData.Count]; for (int i = 0; i < creationData.Count; i++) { counters[i] = creationData[i].CounterName; counterTypes[i] = ((int) creationData[i].CounterType).ToString(CultureInfo.InvariantCulture); } linkageKey = serviceParentKey.OpenSubKey(categoryName + "\\Linkage" , true); if (linkageKey == null) linkageKey = serviceParentKey.CreateSubKey(categoryName + "\\Linkage" ); linkageKey.SetValue("Export", new string[]{categoryName}); serviceKey.SetValue("Counter Types", (object) counterTypes); serviceKey.SetValue("Counter Names", (object) counters); object firstID = serviceKey.GetValue("First Counter"); if (firstID != null) iniRegistered = true; else iniRegistered = false; } finally { if (serviceKey != null) serviceKey.Close(); if (linkageKey != null) linkageKey.Close(); if (serviceParentKey != null) serviceParentKey.Close(); RegistryPermission.RevertAssert(); } }
/// <summary> /// Initializes this attribute with information needed to install this performance counter category. /// </summary> /// <param name="categoryName">Performance counter category name</param> /// <param name="categoryHelp">Counter category help resource name. /// This is not the help text itself, /// but is the resource name used to look up the internationalized help text at install-time. ///</param> /// <param name="categoryType">Performance counter category type.</param> public PerformanceCountersDefinitionAttribute(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType) { this.categoryName = categoryName; this.categoryHelp = categoryHelp; this.categoryType = categoryType; }
public IICPerformanceCounterCategory(string categoryName, PerformanceCounterCategoryType categoryType, string categoryHelp) { _categoryAttribute = new IICPerformanceCountersAttribute(categoryName, categoryType, categoryHelp); }
public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) { if (categoryType < PerformanceCounterCategoryType.Unknown || categoryType > PerformanceCounterCategoryType.MultiInstance) throw new ArgumentOutOfRangeException("categoryType"); if (counterData == null) throw new ArgumentNullException("counterData"); CheckValidCategory(categoryName); if (categoryHelp != null) { // null categoryHelp is a valid option - it gets set to "Help Not Available" later on. CheckValidHelp(categoryHelp); } string machineName = "."; PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer, machineName, categoryName); permission.Demand(); SharedUtils.CheckNtEnvironment(); Mutex mutex = null; RuntimeHelpers.PrepareConstrainedRegions(); try { SharedUtils.EnterMutex(perfMutexName, ref mutex); if (PerformanceCounterLib.IsCustomCategory(machineName, categoryName) || PerformanceCounterLib.CategoryExists(machineName , categoryName)) throw new InvalidOperationException(SR.GetString(SR.PerformanceCategoryExists, categoryName)); CheckValidCounterLayout(counterData); PerformanceCounterLib.RegisterCategory(categoryName, categoryType, categoryHelp, counterData); return new PerformanceCounterCategory(categoryName, machineName); } finally { if (mutex != null) { mutex.ReleaseMutex(); mutex.Close(); } } }
/// <summary> /// Initializes this attribute with information needed to install this performance counter category. /// </summary> /// <param name="categoryName">Performance counter category name</param> /// <param name="categoryHelp">Counter category help resource name. /// This is not the help text itself, /// but is the resource name used to look up the internationalized help text at install-time. ///</param> /// <param name="categoryType">Performance counter category type.</param> public PerformanceCountersDefinitionAttribute(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType) { this.categoryName = categoryName; this.categoryHelp = categoryHelp; this.categoryType = categoryType; }
public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) { CounterCreationData customData = new CounterCreationData(counterName, counterHelp, PerformanceCounterType.NumberOfItems32); return Create(categoryName, categoryHelp, categoryType, new CounterCreationDataCollection(new CounterCreationData [] {customData})); }
public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) { throw new NotImplementedException(); }
internal static void RegisterCategory(string categoryName, PerformanceCounterCategoryType categoryType, string categoryHelp, CounterCreationDataCollection creationData) { try { bool iniRegistered = false; CreateRegistryEntry(categoryName, categoryType, creationData, ref iniRegistered); if (!iniRegistered) { string[] languageIds = GetLanguageIds(); CreateIniFile(categoryName, categoryHelp, creationData, languageIds); CreateSymbolFile(creationData); RegisterFiles(IniFilePath, false); } CloseAllTables(); CloseAllLibraries(); } finally { DeleteTemporaryFiles(); } }
public IICPerformanceCounterCategory(string categoryName, PerformanceCounterCategoryType categoryType, string categoryHelp) { _categoryAttribute = new IICPerformanceCountersAttribute(categoryName, categoryType, categoryHelp); }
internal bool FindCustomCategory(string category, out PerformanceCounterCategoryType categoryType) { RegistryKey key = null; RegistryKey baseKey = null; categoryType = PerformanceCounterCategoryType.Unknown; if (this.customCategoryTable == null) { Interlocked.CompareExchange(ref this.customCategoryTable, new Hashtable(StringComparer.OrdinalIgnoreCase), null); } if (this.customCategoryTable.ContainsKey(category)) { categoryType= (PerformanceCounterCategoryType) this.customCategoryTable[category]; return true; } else { //SECREVIEW: Whoever is able to call this function, must already // have demanded PerformanceCounterPermission // we can therefore assert the RegistryPermission. PermissionSet ps = new PermissionSet(PermissionState.None); ps.AddPermission(new RegistryPermission(PermissionState.Unrestricted)); ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)); ps.Assert(); try { string keyPath = ServicePath + "\\" + category + "\\Performance"; if (machineName == "." || String.Compare(this.machineName, ComputerName, StringComparison.OrdinalIgnoreCase) == 0) { key = Registry.LocalMachine.OpenSubKey(keyPath); } else { baseKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "\\\\" + this.machineName); if (baseKey != null) { try { key = baseKey.OpenSubKey(keyPath); } catch (SecurityException) { // we may not have permission to read the registry key on the remote machine. The security exception // is thrown when RegOpenKeyEx returns ERROR_ACCESS_DENIED or ERROR_BAD_IMPERSONATION_LEVEL // // In this case we return an 'Unknown' category type and 'false' to indicate the category is *not* custom. // categoryType = PerformanceCounterCategoryType.Unknown; this.customCategoryTable[category] = categoryType; return false; } } } if (key != null) { object systemDllName = key.GetValue("Library", null, RegistryValueOptions.DoNotExpandEnvironmentNames); if (systemDllName != null && systemDllName is string && (String.Compare((string)systemDllName, PerformanceCounterLib.PerfShimName, StringComparison.OrdinalIgnoreCase) == 0 || ((string)systemDllName).EndsWith(PerformanceCounterLib.PerfShimFullNameSuffix, StringComparison.OrdinalIgnoreCase))) { object isMultiInstanceObject = key.GetValue("IsMultiInstance"); if (isMultiInstanceObject != null) { categoryType = (PerformanceCounterCategoryType) isMultiInstanceObject; if (categoryType < PerformanceCounterCategoryType.Unknown || categoryType > PerformanceCounterCategoryType.MultiInstance) categoryType = PerformanceCounterCategoryType.Unknown; } else categoryType = PerformanceCounterCategoryType.Unknown; object objectID = key.GetValue("First Counter"); if (objectID != null) { int firstID = (int)objectID; this.customCategoryTable[category] = categoryType; return true; } } } } finally { if (key != null) key.Close(); if (baseKey != null) baseKey.Close(); PermissionSet.RevertAssert(); } } return false; }
public IICPerformanceCountersAttribute(string catagoryName, PerformanceCounterCategoryType catagoryType) : this(catagoryName, catagoryType, catagoryName) { }
public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) { throw new NotImplementedException(); }
/// <summary> /// Intializes required resources /// </summary> private void InitializeImpl() { bool tookLock = false; try { Monitor.Enter(InstanceLockObject, ref tookLock); if (!_initialized) { string currentCategoryName = _categoryName; string currentMachineName = _machineName; if (currentCategoryName == string.Empty) { throw new InvalidOperationException(SR.CategoryNameMissing); } if (_counterName == string.Empty) { throw new InvalidOperationException(SR.CounterNameMissing); } if (ReadOnly) { if (!PerformanceCounterLib.CounterExists(currentMachineName, currentCategoryName, _counterName)) { throw new InvalidOperationException(SR.Format(SR.CounterExists, currentCategoryName, _counterName)); } PerformanceCounterCategoryType categoryType = PerformanceCounterLib.GetCategoryType(currentMachineName, currentCategoryName); if (categoryType == PerformanceCounterCategoryType.MultiInstance) { if (string.IsNullOrEmpty(_instanceName)) { throw new InvalidOperationException(SR.Format(SR.MultiInstanceOnly, currentCategoryName)); } } else if (categoryType == PerformanceCounterCategoryType.SingleInstance) { if (!string.IsNullOrEmpty(_instanceName)) { throw new InvalidOperationException(SR.Format(SR.SingleInstanceOnly, currentCategoryName)); } } if (_instanceLifetime != PerformanceCounterInstanceLifetime.Global) { throw new InvalidOperationException(SR.InstanceLifetimeProcessonReadOnly); } _initialized = true; } else { if (currentMachineName != "." && !string.Equals(currentMachineName, PerformanceCounterLib.ComputerName, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(SR.RemoteWriting); } if (!PerformanceCounterLib.IsCustomCategory(currentMachineName, currentCategoryName)) { throw new InvalidOperationException(SR.NotCustomCounter); } // check category type PerformanceCounterCategoryType categoryType = PerformanceCounterLib.GetCategoryType(currentMachineName, currentCategoryName); if (categoryType == PerformanceCounterCategoryType.MultiInstance) { if (string.IsNullOrEmpty(_instanceName)) { throw new InvalidOperationException(SR.Format(SR.MultiInstanceOnly, currentCategoryName)); } } else if (categoryType == PerformanceCounterCategoryType.SingleInstance) { if (!string.IsNullOrEmpty(_instanceName)) { throw new InvalidOperationException(SR.Format(SR.SingleInstanceOnly, currentCategoryName)); } } if (string.IsNullOrEmpty(_instanceName) && InstanceLifetime == PerformanceCounterInstanceLifetime.Process) { throw new InvalidOperationException(SR.InstanceLifetimeProcessforSingleInstance); } _sharedCounter = new SharedPerformanceCounter(currentCategoryName.ToLowerInvariant(), _counterName.ToLowerInvariant(), _instanceName.ToLowerInvariant(), _instanceLifetime); _initialized = true; } } } finally { if (tookLock) { Monitor.Exit(InstanceLockObject); } } }