private static bool AddStartMethodToAggregatedCallTree(ProfilerEvent?previousProfilerEvent, ProfilerEvent?currentProfilerEvent, ref AggregatedEventNode currentAggregatedEventNode) { // If it is the root method or if it is non AL event we also push start event into the stack. if (currentAggregatedEventNode.Parent == null || currentProfilerEvent.Value.IsNonAlEvent || (previousProfilerEvent.HasValue && previousProfilerEvent.Value.IsNonAlEvent)) { currentAggregatedEventNode = currentAggregatedEventNode.PushEventIntoCallStack(currentProfilerEvent.Value); } currentAggregatedEventNode.EvaluatedType = EventType.StartMethod; return(true); }
private static bool AddStartMethodToAggregatedCallTree( ProfilerEvent?previousProfilerEvent, ProfilerEvent?currentProfilerEvent, ref AggregatedEventNode currentAggregatedEventNode, ref Stack <ProfilerEvent> callStack) { // If it is the root method or if it is non AL event we also push start event into the stack. if (currentAggregatedEventNode.Parent == null || currentProfilerEvent.Value.IsNonAlEvent) { currentAggregatedEventNode = currentAggregatedEventNode.PushEventIntoCallStack(currentProfilerEvent.Value); } currentAggregatedEventNode.EvaluatedType = EventType.StartMethod; if (currentProfilerEvent.Value.IsAlEvent) { currentAggregatedEventNode.IsExecutingFunction = true; } callStack.Push(currentProfilerEvent.Value); return(true); }
private static bool PopEventFromCallStackIfSomeEventsWereMissing( ProfilerEvent?previousProfilerEvent, ProfilerEvent?currentProfilerEvent, ref AggregatedEventNode currentAggregatedEventNode, ref Stack <ProfilerEvent> callStack, out bool skipCurrentEvent) { if (currentAggregatedEventNode.Parent != null && currentAggregatedEventNode.OriginalType == EventType.StartMethod && currentAggregatedEventNode.SubType == EventSubType.SqlEvent && currentProfilerEvent.HasValue && !(currentProfilerEvent.Value.Type == EventType.StopMethod && currentProfilerEvent.Value.SubType == EventSubType.SqlEvent)) { // TODO: Here we have two consecutive start events. First event is of the SQL subtype. This should never happen because SQL queries cannot be nested. // TODO: It could indicates an issue in evening. // TODO: Need to pop previous event and push current. ProfilerEvent missingProfilerEvent = new ProfilerEvent { SessionId = currentAggregatedEventNode.SessionId, ObjectType = currentAggregatedEventNode.ObjectType, ObjectId = currentAggregatedEventNode.ObjectId, LineNo = currentAggregatedEventNode.LineNo, Type = EventType.StartMethod, StatementName = StopEventIsMissing + currentAggregatedEventNode.StatementName }; currentAggregatedEventNode = currentAggregatedEventNode.PopEventFromCallStackAndCalculateDuration(previousProfilerEvent.Value.TimeStampRelativeMSec); currentAggregatedEventNode = currentAggregatedEventNode.PushEventIntoCallStack(missingProfilerEvent); currentAggregatedEventNode = currentAggregatedEventNode.PopEventFromCallStackAndCalculateDuration(missingProfilerEvent.TimeStampRelativeMSec); if (currentProfilerEvent.Value.Type == EventType.StartMethod || currentProfilerEvent.Value.Type == EventType.Statement) { currentAggregatedEventNode = currentAggregatedEventNode.PushEventIntoCallStack(currentProfilerEvent.Value); } skipCurrentEvent = true; return(true); } if (currentAggregatedEventNode.Parent != null && previousProfilerEvent.HasValue && previousProfilerEvent.Value.Type == EventType.StopMethod && currentProfilerEvent.HasValue && currentProfilerEvent.Value.Type == EventType.StopMethod && currentProfilerEvent.Value.IsAlEvent != currentAggregatedEventNode.IsAlEvent) { //TODO: We hit this block for example in the case if Codeunit 1 trigger is called and it does not have any code. //TODO: We should consider if we want to fix it in the product. // Skip this event. Should never happen. Indicates a issue in the event generation. // Some events were missed. // Create fake start event. ProfilerEvent profilerEvent = currentProfilerEvent.Value; profilerEvent.Type = EventType.StartMethod; profilerEvent.StatementName = StartEventIsMissing + profilerEvent.StatementName; currentAggregatedEventNode = currentAggregatedEventNode.PushEventIntoCallStack(profilerEvent); currentAggregatedEventNode = currentAggregatedEventNode.PopEventFromCallStackAndCalculateDuration(currentProfilerEvent.Value.TimeStampRelativeMSec); skipCurrentEvent = false; return(true); } skipCurrentEvent = false; return(false); }