public void TestPerformance() { var pCounter = new ComprehensiveQueryPerformanceCounter(); //enable performance counting DatabaseCommandHelper.PerformanceCounter = pCounter; try { //send some queries var cata = new Catalogue(CatalogueRepository, "Fish"); Assert.IsTrue(cata.Name.Equals("Fish")); var commands = pCounter.DictionaryOfQueries.Values.ToArray(); Assert.IsTrue(commands.Any(c => c.QueryText.Contains("SELECT * FROM Catalogue WHERE ID="))); cata.DeleteInDatabase(); } finally { DatabaseCommandHelper.PerformanceCounter = null; } }
public void LoadState(ComprehensiveQueryPerformanceCounter performanceCounter) { _performanceCounter = performanceCounter; Roots = new List <StackFramesTree>(); _worstOffenderCount = performanceCounter.DictionaryOfQueries.Values.Sum(k => k.TimesSeen); Regex isSystemCall = new Regex(@"^\s*(at)?\s*System.Windows.Forms"); //for each documented query point (which has a stack trace) foreach (string stackTrace in performanceCounter.DictionaryOfQueries.Keys) { //get the query var query = performanceCounter.DictionaryOfQueries[stackTrace]; //get the stack trace split by line reversed so the root is at the top var lines = stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Reverse().ToArray(); lines = lines.Where(l => !isSystemCall.IsMatch(l)).ToArray(); if (lines.Length == 0) { continue; } if (collapseToMethod) { List <string> uniqueMethodLines = new List <string>(); string lastMethodName = StackFramesTree.GetMethodName(lines[0]); uniqueMethodLines.Add(lines[0]); for (int i = 1; i < lines.Length; i++) { string currentMethodName = StackFramesTree.GetMethodName(lines[i]); //if there is no method name or it is not new if (currentMethodName == null || lastMethodName.Equals(currentMethodName)) { continue; } lastMethodName = currentMethodName; uniqueMethodLines.Add(lines[i]); } lines = uniqueMethodLines.ToArray(); } StackFramesTree currentRoot = null; //if we have seen the root before? currentRoot = Roots.SingleOrDefault(n => n.CurrentFrame.Equals(lines[0])); //it's novel if (currentRoot == null) { //add a new root level entrypoint currentRoot = new StackFramesTree(lines, query, false); Roots.Add(currentRoot); } else { currentRoot.AddSubframes(lines, query); } } //if there is one root node if (Roots.Count == 1) { //find the first point at which it splits var firstBranch = Roots.Single(); //still hasn't split while (firstBranch.Children.Count == 1) { firstBranch = firstBranch.Children.Values.Single(); } //if it did split if (firstBranch.Children.Count > 1) { Roots = new List <StackFramesTree>(new [] { firstBranch }); } } tlvLocations.ClearObjects(); tlvLocations.AddObjects(Roots); tlvLocations.ExpandAll(); }