public void PerformanceCounterKeyTest_VerifyEmptyCheckCategory() { PerformanceCounterKey c1 = new PerformanceCounterKey("foo", null, "bar"); PerformanceCounterKey c2 = new PerformanceCounterKey("foo", string.Empty, "bar"); Assert.AreEqual(c1.KeyCode, c2.KeyCode); }
public void WindowsPerformanceFacadeTest_VerifyGetPerformanceCounterMatch() { int returnedId = WindowsPerformanceFacade.GetPerformanceCounterId("a", "b", "c"); PerformanceCounterKey foo = WindowsPerformanceFacade.GetPerformanceCounterKey(returnedId); Assert.AreEqual("a", foo.CategoryName); Assert.AreEqual("b", foo.InstanceName); Assert.AreEqual("c", foo.CounterName); }
public override bool Equals(object obj) { if (obj is PerformanceCounterKey) { PerformanceCounterKey other = (PerformanceCounterKey)obj; return(this.className.Equals(other.className) && this.instanceName.Equals(other.instanceName) && this.methodName.Equals(other.methodName)); } return(false); // other objects never are equal... }
public void PerformanceCounterKeyTest_KeyCodeBehavior() { PerformanceCounterKey c1 = new PerformanceCounterKey("foo", null, "bar"); PerformanceCounterKey c2 = new PerformanceCounterKey("foo", null, "bar"); PerformanceCounterKey c3 = new PerformanceCounterKey("foo", null, "bat"); PerformanceCounterKey c4 = new PerformanceCounterKey("bat", null, "bar"); Assert.AreEqual(c1.KeyCode, c2.KeyCode); Assert.AreNotEqual(c2.KeyCode, c3.KeyCode); Assert.AreNotEqual(c3.KeyCode, c4.KeyCode); Assert.AreNotEqual(c2.KeyCode, c4.KeyCode); }
private JCsProfilerMethod CreateNewPCMethod(PerformanceCounterKey key) { string className = key.ClassName; string instanceName = key.InstanceName; string methodName = key.MethodName; /* * The following operation is only done once for each method to * be profiled (when it's called for the very first time), so * instead of adding extra structures I do it the expansive way... */ PerformanceCounterClass myClass = null; PerformanceCounterInstance myInstance = null; JCsProfilerMethod newMethod = null; // see if the class exists already... foreach (PerformanceCounterClass pcClass in classes) { if (pcClass.Name.Equals(className)) { myClass = pcClass; break; } } // if not - create it... if (myClass == null) { myClass = new PerformanceCounterClass(className); classes.Add(myClass); } // now see if that class has the relevant instance foreach (PerformanceCounterInstance pcInstance in myClass.Instances) { if (pcInstance.Name.Equals(instanceName)) { myInstance = pcInstance; break; } } // if not - create it... if (myInstance == null) { myInstance = new PerformanceCounterInstance(instanceName, myClass); } // now we do know the method doesn't exist, or we wouldn't be here right now ;-) newMethod = new JCsProfilerMethod(methodName, myInstance); allPerformanceCounters.Add(key, newMethod); return(newMethod); }
/// <summary> /// This method starts the profiling. Put it at the beginning of the /// method you with to profile and don't forget to call CallIsFinished() /// on the returned instance of JCsProfilerMethod. /// </summary> /// <param name="className">The name of the class which is being profiled.</param> /// <param name="instanceName"> /// The name of the instance calling the method, usually you would pass gameObject.Name /// </param> /// <param name="methodName">The name of the method being profiled without parenthesis.</param> /// <returns> /// an instance of JCsProfilerMethod on which you MUST call /// CallIsFinished() as last statement of the method you're profiling... /// </returns> public JCsProfilerMethod StartCallStopWatch(string className, string instanceName, string methodName) { if (trackProfiling) { // this is a bit of a waste, but it *should* be better than concatenating the strings... PerformanceCounterKey key = new PerformanceCounterKey(className, instanceName, methodName); JCsProfilerMethod method = null; if (allPerformanceCounters.ContainsKey(key)) { method = (JCsProfilerMethod)allPerformanceCounters[key]; } else { method = CreateNewPCMethod(key); } method.StartCallStopWatch(); return(method); } else { return(dummy); } }
public void PerformanceCounterKeyTest_PagingFileCounters() { PerformanceCounterKey k = new PerformanceCounterKey("Paging File", "_Total", "% Usage"); Assert.IsNotNull(k); }