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); }
public PerformanceCounterInstance(string instanceName, PerformanceCounterClass parent) : base(instanceName) { this.parent = parent; this.parent.AddInstance(this); }