private void rightBuildExpandingNode(TreeNode node, ExecutionCall call) { node.Nodes.Clear(); foreach (var child in call.Children) { UIBuilder.BuildExecutionTree(node, child, rSQLMap, rExecMap, true, true); } }
private void BuildExecutionTree(TreeNode root, ExecutionCall call) { TreeNode newRoot = null; if (call.Type == ExecutionCallType.SQL) { var sqlItem = call.SQLStatement; switch(sqlItem.Type) { case SQLType.SELECT: newRoot = root.Nodes.Add("SELECT FROM " + sqlItem.FromClause + "Fetched=" + sqlItem.FetchCount + " Dur=" + sqlItem.Duration); break; case SQLType.UPDATE: newRoot = root.Nodes.Add("UPDATE " + sqlItem.FromClause + " Dur=" + sqlItem.Duration); break; case SQLType.INSERT: newRoot = root.Nodes.Add("INSERT INTO " + sqlItem.FromClause + " Dur=" + sqlItem.Duration); break; case SQLType.DELETE: newRoot = root.Nodes.Add("DELETE FROM " + sqlItem.FromClause + " Dur=" + sqlItem.Duration); break; } SQLMapToTree.Add(sqlItem, newRoot); newRoot.Tag = sqlItem; if (sqlItem.IsError) { newRoot.BackColor = Color.Red; } } else { newRoot = root.Nodes.Add(call.Function + " Dur: " + (call.Duration)); ExecCallToTree.Add(call, newRoot); if (call.HasError) { newRoot.BackColor = Color.Yellow; } else if (call.IsError) { newRoot.BackColor = Color.Red; } else if (call.Duration >= Properties.Settings.Default.LongCall) { newRoot.BackColor = Color.LightGreen; } newRoot.Tag = call; } foreach (var child in call.Children.OrderBy(p => p.StartLine)) { BuildExecutionTree(newRoot, child); } }
public void ProcessLine(string line, long lineNumber) { if (contextMarker.IsMatch(line) == false) { return; } var currentContextString = contextMarker.Match(line).Groups[0].Value; var match = callMarker.Match(line); if (match.Success) { _ppcCodeCallCount++; var call = new ExecutionCall() { Context = currentContextString, Type = ExecutionCallType.CALL, StartLine = lineNumber, Function = match.Groups[3].Value + ": " + match.Groups[4].Value, indentCount = match.Groups[2].Value.Length }; allCalls.Add(call); call.Duration = Double.Parse(match.Groups[1].Value); if (callChain.Count > 0 && callChain.Peek().indentCount == call.indentCount) { var popped = callChain.Pop(); if (popped.StopLine == 0) { popped.StopLine = lineNumber; } } if (callChain.Count > 0 && callChain.Peek().Type == ExecutionCallType.CALL) { while(callChain.Count > 0 && callChain.Peek().indentCount >= call.indentCount) { var popped = callChain.Pop(); if (popped.StopLine == 0) { popped.StopLine = lineNumber; } } } if (callChain.Count > 0) { callChain.Peek().Children.Add(call); call.Parent = callChain.Peek(); } if (callChain.Count == 0) { executionCalls.Add(call); } callChain.Push(call); return; } match = startMarker.Match(line); if (match.Success == false) { match = resumeMarker.Match(line); } /* Start marker, or Resume Marker */ if (match.Success) { _ppcCodeCallCount++; // we have the start of a function var call = new ExecutionCall() { Context = currentContextString, Type = ExecutionCallType.NORMAL, StartLine = lineNumber, Nest = match.Groups[1].Value, Function = match.Groups[2].Value }; allCalls.Add(call); if (callChain.Count == 0) { executionCalls.Add(call); } callChain.Push(call); if (callChain.Count > _maxCallDepth) { _maxCallDepth = callChain.Count; } return; } match = endMarker.Match(line); if (match.Success == false) { match = reendMarker.Match(line); } /* end marker or reend marker */ if (match.Success) { // we've reached the end of a call, we need to find it in the list and mark the ending line var nest = match.Groups[1].Value; var func = match.Groups[2].Value; var dur = match.Groups.Count == 4 ? match.Groups[3].Value : "0"; bool callFound = false; ExecutionCall call = null; while (callFound == false) { call = callChain.Pop(); if (call.Nest == nest && call.Function == func) { callFound = true; call.StopLine = lineNumber; call.Duration = Double.Parse(dur); } } if (nest.Equals("00") == false && callChain.Count > 0) { /* If we are a nested call, and there are calls on the call chain * * then we should associate the current call with its parent * */ var parent = callChain.Peek(); parent.Children.Add(call); call.Parent = parent; } return; } match = startExtMarker.Match(line); if (match.Success) { _ppcCodeCallCount++; // we have the start of a function var call = new ExecutionCall() { Context = currentContextString, Type = ExecutionCallType.EXTERNAL, StartLine = lineNumber, Nest = match.Groups[1].Value, Function = match.Groups[2].Value }; allCalls.Add(call); if (callChain.Count == 0) { executionCalls.Add(call); } /* test */ if (callChain.Count > 0 && callChain.Peek().Type == ExecutionCallType.CALL) { var parent = callChain.Pop(); if (parent.StopLine == 0) { parent.StopLine = lineNumber; } parent.Children.Add(call); call.Parent = parent; } callChain.Push(call); if (callChain.Count > _maxCallDepth) { _maxCallDepth = callChain.Count; } return; } match = endExtMarker.Match(line); if (match.Success) { // we've reached the end of a call, we need to find it in the list and mark the ending line var nest = match.Groups[1].Value; var func = match.Groups[2].Value; var dur = match.Groups[3].Value; if (callChain.Count > 0 && callChain.Peek().Type == ExecutionCallType.CALL) { while (callChain.Peek().Type == ExecutionCallType.CALL || callChain.Peek().Nest != nest) { var popped = callChain.Pop(); if (popped.StopLine == 0) { popped.StopLine = lineNumber; } } } //var call = executionCalls.Where(p => p.Context.Equals(currentContextString) && p.Nest.Equals(nest) && p.Function.Equals(func) && p.StopLine == 0).First<ExecutionCall>(); var call = callChain.Pop(); call.StopLine = lineNumber; call.Duration = Double.Parse(dur); } match = sqlStatement.Match(line); if (match.Success) { var sqlCall = new ExecutionCall() {Context= currentContextString, Type = ExecutionCallType.SQL, StartLine = lineNumber, StopLine = lineNumber, Function = "SQL" }; allCalls.Add(sqlCall); if (callChain.Count > 0) { sqlCall.Parent = callChain.Peek(); callChain.Peek().Children.Add(sqlCall); } else { executionCalls.Add(sqlCall); } sqlCalls.Add(sqlCall); return; } match = ppcExceptionStatement.Match(line); if (match.Success) { _ppcExceptionCount++; var exception = new PPCException() { Message = match.Groups[1].Value }; if (callChain.Count > 0) { var call = callChain.Peek(); call.PPCException = exception; call.IsError = true; var parent = call.Parent; while (parent != null) { parent.HasError = true; parent = parent.Parent; } } } return; }
public static void BuildExecutionTree(TreeNode root, ExecutionCall call, Dictionary<SQLStatement, TreeNode> SQLMapToTree, Dictionary<ExecutionCall, TreeNode> ExecCallToTree, bool showLoading, bool diffMode = false) { TreeNode newRoot = null; if (call.Type == ExecutionCallType.SQL) { var sqlItem = call.SQLStatement; switch (sqlItem.Type) { case SQLType.SELECT: newRoot = root.Nodes.Add("SELECT FROM " + sqlItem.FromClause + "Fetched=" + sqlItem.FetchCount + " Dur=" + sqlItem.Duration); break; case SQLType.UPDATE: newRoot = root.Nodes.Add("UPDATE " + sqlItem.FromClause + " Dur=" + sqlItem.Duration); break; case SQLType.INSERT: newRoot = root.Nodes.Add("INSERT INTO " + sqlItem.FromClause + " Dur=" + sqlItem.Duration); break; case SQLType.DELETE: newRoot = root.Nodes.Add("DELETE FROM " + sqlItem.FromClause + " Dur=" + sqlItem.Duration); break; } SQLMapToTree.Add(sqlItem, newRoot); newRoot.Tag = call; if (!diffMode) { if (sqlItem.IsError) { newRoot.BackColor = Color.Red; } } else { if (call.DiffStatus == DiffStatus.DELETE) { newRoot.BackColor = Color.Red; } else if (call.DiffStatus == DiffStatus.INSERT) { newRoot.BackColor = Color.LightBlue; } else if (call.DiffStatus == DiffStatus.MODIFIED) { newRoot.BackColor = Color.Yellow; } } } else { newRoot = root.Nodes.Add(call.Function + " Dur: " + (call.Duration)); ExecCallToTree.Add(call, newRoot); if (!diffMode) { if (call.HasError) { newRoot.BackColor = Color.Yellow; } else if (call.IsError) { newRoot.BackColor = Color.Red; } else if (call.Duration >= Properties.Settings.Default.LongCall) { newRoot.BackColor = Color.LightGreen; } } else { if (call.DiffStatus == DiffStatus.INSERT) { newRoot.BackColor = Color.LightBlue; } else if (call.DiffStatus == DiffStatus.DELETE) { newRoot.BackColor = Color.Red; } else if (call.DiffStatus == DiffStatus.MODIFIED) { newRoot.BackColor = Color.Yellow; } } newRoot.Tag = call; if (showLoading && call.Children.Count > 0) { newRoot.Nodes.Add("Loading..."); } } }
private void SerializeExecutionCall(List<string> ContextList, List<string> FunctionList, ExecutionCall call) { /* Parameters in order * * -InternalID * -SQLStatement Present - bool * -SQLStatement - InternalId * -StackTrace Present - bool * -StackTrace - InternalId * -PPCException Present - bool * -PPCException - inline (1,2,3) * -HasError - bool; * -IsError - bool; * -indentCount - uint * -Context - IndexOf in ContextList * Nest - String * Function - IndexOf in FunctionList * Duration (internal duration) - Double * Start Line - long * StopLine (internal stopline) - long * Execution Call Type * Call Parent Exists - bool * Execution Call Parent - InternalID */ WriteUint(call.InternalID); WriteBool(call.SQLStatement != null); if (call.SQLStatement != null) { WriteUint(call.SQLStatement.InternalID); } WriteBool(call.StackTrace != null); if (call.StackTrace != null) { WriteUint(call.StackTrace.InternalID); } WriteBool(call.PPCException != null); if (call.PPCException != null) { WriteUint(call.PPCException.InternalID); WriteLong(call.PPCException.LineNumber); WriteString(call.PPCException.Message); } WriteBool(call.HasError); WriteBool(call.IsError); WriteInt(call.indentCount); WriteInt(ContextList.IndexOf(call.Context)); WriteString(call.Nest); WriteInt(FunctionList.IndexOf(call.Function)); WriteDouble(call.InternalDuration); WriteLong(call.StartLine); WriteLong(call.InternalStopLine); switch (call.Type) { case ExecutionCallType.CALL: WriteByte(1); break; case ExecutionCallType.EXTERNAL: WriteByte(2); break; case ExecutionCallType.NORMAL: WriteByte(3); break; case ExecutionCallType.SQL: WriteByte(4); break; } WriteBool(call.Parent != null); if (call.Parent != null) { WriteUint(call.Parent.InternalID); } }
private void DeserializeExecutionCall(List<string> ContextList, List<string> FunctionList) { ExecutionCall call = new ExecutionCall(); Data.AllExecutionCalls.Add(call); call.InternalID = ReadUint(); var sqlStatementPresent = ReadBool(); if (sqlStatementPresent) { var sqlId = ReadUint(); ExecToResolveSQL.Add(call,sqlId); } var stackTracePresent = ReadBool(); if (stackTracePresent) { var stackTraceId = ReadUint(); ExecToResolveStackTrace.Add(call, stackTraceId); } var ppcExceptionPresent = ReadBool(); if (ppcExceptionPresent) { call.PPCException = new PPCException(); call.PPCException.InternalID = ReadUint(); call.PPCException.LineNumber = ReadLong(); call.PPCException.Message = ReadString(); } call.HasError = ReadBool(); call.IsError = ReadBool(); call.indentCount = ReadInt(); call.Context = ContextList[ReadInt()]; call.Nest = ReadString(); call.Function = FunctionList[ReadInt()]; call.Duration = ReadDouble(); call.StartLine = ReadLong(); call.StopLine = ReadLong(); var callType = ReadByte(); switch(callType) { case 1: call.Type = ExecutionCallType.CALL; break; case 2: call.Type = ExecutionCallType.EXTERNAL; break; case 3: call.Type = ExecutionCallType.NORMAL; break; case 4: call.Type = ExecutionCallType.SQL; break; } var parentPresent = ReadBool(); if (parentPresent) { //TODO: Can we shortcut this and look starting backwards for our parent? var parentID = ReadUint(); for (var y = Data.AllExecutionCalls.Count - 2; y >= 0; y--) { if (Data.AllExecutionCalls[y].InternalID.Equals(parentID)) { Data.AllExecutionCalls[y].Children.Add(call); call.Parent = Data.AllExecutionCalls[y]; break; } } } }
private void BuildOutTreeForCall(ExecutionCall call) { Stack<ExecutionCall> parentCalls = new Stack<ExecutionCall>(); var parent = call; while (parent != null && ExecCallToTree.ContainsKey(parent) == false) { parentCalls.Push(parent); parent = parent.Parent; } /* we need to "expand" this parent to populate it's children */ var current = parent; while (parentCalls.Count > 0) { BuildExpandingNode(ExecCallToTree[current], current); ExecCallToTree[current].Parent.Expand(); current = parentCalls.Pop(); } BuildExpandingNode(ExecCallToTree[current], current); ExecCallToTree[current].Parent.Expand(); ExecCallToTree[current].Expand(); }
private static void SerializeCall(StringBuilder sb, ExecutionCall call) { if (call.Type == ExecutionCallType.SQL) { var sqlSB = new StringBuilder(); sqlSB.Append(call.SQLStatement.FetchCount).Append(call.SQLStatement.Statement); var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(sqlSB.ToString())); sb.AppendLine(BitConverter.ToString(hash)); //sb.AppendLine("SQL: " + call.SQLStatement.Statement); } else { var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(call.Function)); sb.AppendLine(BitConverter.ToString(hash)); //sb.AppendLine("PPC: " + call.Function); } }
public static void FlattenCall(ExecutionCall call, List<ExecutionCall> flat) { flat.Add(call); foreach(var child in call.Children) { FlattenCall(child, flat); } }