public void PerformanceCounterUtilityPlaceholderExpansionTest() { PerformanceCounterUtility.InvalidatePlaceholderCache(); var win32Instances = PerformanceCounterUtility.GetWin32ProcessInstances(); var clrInstances = PerformanceCounterUtility.GetClrProcessInstances(); bool usesInstanceNamePlaceholder; var pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??APP_WIN32_PROC??)\% Processor Time", win32Instances, clrInstances, out usesInstanceNamePlaceholder); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??APP_CLR_PROC??)\% Processor Time", win32Instances, clrInstances, out usesInstanceNamePlaceholder); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??APP_W3SVC_PROC??)\% Processor Time", win32Instances, clrInstances, out usesInstanceNamePlaceholder); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time", win32Instances, clrInstances, out usesInstanceNamePlaceholder); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??NON_EXISTENT??)\% Processor Time", win32Instances, clrInstances, out usesInstanceNamePlaceholder); Assert.AreEqual("??NON_EXISTENT??", pc.InstanceName); // validate placeholder cache state var cache = new PrivateType(typeof(PerformanceCounterUtility)).GetStaticField( "PlaceholderCache", BindingFlags.NonPublic) as ConcurrentDictionary <string, string>; Assert.AreEqual(3, cache.Count); Assert.IsTrue(cache.ContainsKey("APP_WIN32_PROC")); Assert.IsTrue(cache.ContainsKey("APP_CLR_PROC")); Assert.IsTrue(cache.ContainsKey("APP_W3SVC_PROC")); PerformanceCounterUtility.InvalidatePlaceholderCache(); Assert.IsFalse(cache.Any()); }
public void PerformanceCounterUtilityPlaceholderExpansionTest() { PerformanceCounterUtility.InvalidatePlaceholderCache(); var win32Instances = PerformanceCounterUtility.GetWin32ProcessInstances(); var clrInstances = PerformanceCounterUtility.GetClrProcessInstances(); var pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??APP_WIN32_PROC??)\% Processor Time", win32Instances, clrInstances); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??APP_CLR_PROC??)\% Processor Time", win32Instances, clrInstances); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??APP_W3SVC_PROC??)\% Processor Time", win32Instances, clrInstances); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time", win32Instances, clrInstances); Assert.IsFalse(pc.InstanceName.Contains("?")); pc = PerformanceCounterUtility.ParsePerformanceCounter(@"\Processor(??NON_EXISTENT??)\% Processor Time", win32Instances, clrInstances); Assert.AreEqual("??NON_EXISTENT??", pc.InstanceName); // validate placeholder cache state var cache = new PrivateType(typeof(PerformanceCounterUtility)).GetStaticField( "PlaceholderCache", BindingFlags.NonPublic) as Dictionary<string, string>; Assert.AreEqual(3, cache.Count); Assert.IsTrue(cache.ContainsKey("APP_WIN32_PROC")); Assert.IsTrue(cache.ContainsKey("APP_CLR_PROC")); Assert.IsTrue(cache.ContainsKey("APP_W3SVC_PROC")); PerformanceCounterUtility.InvalidatePlaceholderCache(); Assert.IsFalse(cache.Any()); }