internal void ProcessEndExtMarker(Match match, long lineNumber) { // 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; } lastPopped = popped; } } var call = callChain.Pop(); lastPopped = call; call.StopLine = lineNumber; call.Duration = Double.Parse(dur); ResetReturnStack(); }
internal void ProcessStartExtMarker(Match match, long lineNumber) { _ppcCodeCallCount++; // we have the start of a function var call = new ExecutionCall() { Context = ContextID, 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(); lastPopped = parent; if (parent.StopLine == 0) { parent.StopLine = lineNumber; } parent.Children.Add(call); call.Parent = parent; } callChain.Push(call); if (callChain.Count > _maxCallDepth) { _maxCallDepth = callChain.Count; } ResetReturnStack(); }
internal void ProcessEndOrReend(Match match, long lineNumber) { // 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(); lastPopped = call; if (call.Nest == nest && call.Function == func) { callFound = true; call.StopLine = lineNumber; call.Duration = Double.Parse(dur); } } if (callChain.Count > 0) { /* If 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; } ResetReturnStack(); }
private void rightBuildExpandingNode(TreeNode node, ExecutionCall call) { node.Nodes.Clear(); foreach (var child in call.Children) { UIBuilder.BuildExecutionTree(node, child, rSQLMap, rExecMap, true, true); } }
public static void FlattenCall(ExecutionCall call, List <ExecutionCall> flat) { flat.Add(call); foreach (var child in call.Children) { FlattenCall(child, flat); } }
internal void ResetReturnStack() { ReturnStackCall = null; ReturnStackClassMethod = null; ReturnStackClassName = null; ReturnStackIsClass = false; ParsingReturnStack = false; ParsingReturnValue = false; }
ExecutionCall FindCallForLineNumber(long lineNumber) { ExecutionCall call = null; foreach (ExecutionContext ctx in contextMap.Values) { call = ctx.allCalls.Where(c => c.StartLine <= lineNumber && c.StopLine >= lineNumber).LastOrDefault(); if (call != null) { break; } } return(call); }
internal void ProcessCallMarker(Match match, long lineNumber) { _ppcCodeCallCount++; var call = new ExecutionCall() { Context = ContextID, 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; } lastPopped = popped; } 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; } lastPopped = popped; } } if (callChain.Count > 0) { callChain.Peek().Children.Add(call); call.Parent = callChain.Peek(); } if (callChain.Count == 0) { executionCalls.Add(call); } callChain.Push(call); ResetReturnStack(); return; }
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); } }
internal void ProcessSQLStatement(Match match, long lineNumber) { var sqlCall = new ExecutionCall() { Context = ContextID, 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); ResetReturnStack(); }
internal void ProcessStartOrResume(Match match, long lineNumber) { _ppcCodeCallCount++; // we have the start of a function var call = new ExecutionCall() { Context = ContextID, 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; } ResetReturnStack(); }
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 + (call.Type.HasFlag(ExecutionCallType.AE) ? "" : " Dur: " + (call.Duration))); ExecCallToTree.Add(call, newRoot); if (call.Type.HasFlag(ExecutionCallType.SQL) && call.SQLStatement != null) { SQLMapToTree.Add(call.SQLStatement, newRoot); newRoot.Tag = call; } 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 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 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); } }
internal void ProcessAECall(Match match, long lineNumber) { var timeStamp = match.Groups[1].Value; var indent = match.Groups[2].Value.Length; var program = match.Groups[3].Value; var section = match.Groups[4].Value; var step = match.Groups[5].Value; var action = match.Groups[6].Value; ExecutionCallType callType; switch (action) { case "Do When": callType = ExecutionCallType.SQL | ExecutionCallType.AE_DOWHEN; break; case "Do While": callType = ExecutionCallType.SQL | ExecutionCallType.AE_DOWHILE; break; case "Do Select": callType = ExecutionCallType.SQL | ExecutionCallType.AE_DOSELECT; break; case "PeopleCode": callType = ExecutionCallType.AE_PPC; break; case "SQL": callType = ExecutionCallType.SQL | ExecutionCallType.AE_SQL; break; case "Call Section": callType = ExecutionCallType.AE_CALL; break; case "Log Message": callType = ExecutionCallType.AE_LOGMSG; break; case "Do Until": callType = ExecutionCallType.SQL | ExecutionCallType.AE_DOUNTIL; break; default: callType = ExecutionCallType.NORMAL; break; } callType |= ExecutionCallType.AE; var call = new ExecutionCall() { Context = ContextID, Type = callType, StartLine = lineNumber, AE_Program = program, AE_Section = section, AE_Step = step, AE_Action = action, Function = program + "." + section + "." + step + " (" + action + ")", indentCount = indent }; allCalls.Add(call); call.Duration = 0; _aeStepCount++; if (callType == ExecutionCallType.AE_PPC) { _ppcCodeCallCount++; } if (callChain.Count > 0 && callChain.Peek().indentCount == call.indentCount) { var popped = callChain.Pop(); if (popped.StopLine == 0) { popped.StopLine = lineNumber; } lastPopped = popped; } if (callChain.Count > 0 && (callChain.Peek().Type == ExecutionCallType.AE_CALL || call.indentCount < callChain.Peek().indentCount)) { while (callChain.Count > 0 && callChain.Peek().indentCount >= call.indentCount) { var popped = callChain.Pop(); if (popped.StopLine == 0) { popped.StopLine = lineNumber; } lastPopped = popped; } } if (callChain.Count > 0) { callChain.Peek().Children.Add(call); call.Parent = callChain.Peek(); } if (callChain.Count == 0) { executionCalls.Add(call); } callChain.Push(call); //throw new NotImplementedException(); }
internal void ProcessReturnStackLine(Match match, long lineNumber) { if (ReturnStackIsClass == false) { if (match.Groups[1].Value.StartsWith("UUU") && match.Groups[2].Value == ":") { ReturnStackIsClass = true; ReturnStackClassName = match.Groups[3].Value; } else { if (callChain.Count > 0 && callChain.Peek().Parent != null && callChain.Peek().Parent.Function.StartsWith("constructor:")) { /* this is a constructor parameter? */ ReturnStackIsClass = true; ReturnStackClassMethod = ""; ReturnStackCall = callChain.Peek().Parent; ReturnStackCall.Parameters = new List <string>(); ProcessReturnStackLine(match, lineNumber); } else { ReturnStackIsClass = false; ReturnStackClassName = null; ReturnStackClassMethod = null; ReturnStackCall = null; } } } else { /* already identified this return stack as a class */ if (ReturnStackClassMethod == null) { ReturnStackClassMethod = match.Groups[3].Value; } else { if (ReturnStackCall == null) { /* find the most recent call that matches that doesn't have parameters... */ ReturnStackCall = allCalls.Where(c => c.Parameters == null && c.Function.Contains($":{ReturnStackClassName}.{ReturnStackClassMethod}")).LastOrDefault(); if (ReturnStackCall == null) { /* Check for a private method */ ReturnStackCall = allCalls.Where(c => c.Parameters == null && c.Function.Contains($"private: {ReturnStackClassMethod}")).LastOrDefault(); } /* add this parameter */ if (ReturnStackCall != null) { ReturnStackCall.Parameters = new List <string>(); if (match.Groups.Count > 2) { /* this is a Something = Something parameter */ ReturnStackCall.Parameters.Add($"{match.Groups[1].Value} = {match.Groups[3].Value}"); } else { /* this parameter is a builtin like array or record etc */ ReturnStackCall.Parameters.Add($"{match.Groups[1].Value}"); } } } else { /* we've found the call, this must be a parameter... add it */ if (match.Groups.Count > 1) { /* this is a Something = Something parameter */ ReturnStackCall.Parameters.Add($"{match.Groups[1].Value} = {match.Groups[3].Value}"); } else { /* this parameter is a builtin like array or record etc */ ReturnStackCall.Parameters.Add($"{match.Groups[1].Value}"); } } } } }