예제 #1
0
        internal void AgentInvokeReturnsHandler(object dispatcher, MExSession context)
        {
            MExCountersInstance instance = MExCounters.GetInstance(context.CurrentAgent.Name);

            if (context.IsAsyncAgent)
            {
                SlidingAverageCounter slidingAverageCounter = this.asynchronousAgentProcessorUsageSlidingCounters[context.CurrentAgent.SequenceNumber];
                slidingAverageCounter.AddValue(context.TotalProcessorTime);
                long rawValue2;
                long rawValue = slidingAverageCounter.CalculateAverageAcrossAllSamples(out rawValue2);
                instance.AverageAgentProcessorUsageAsynchronousInvocations.RawValue = rawValue;
                instance.AsynchronousAgentInvocationSamples.RawValue = rawValue2;
            }
            else
            {
                SlidingAverageCounter slidingAverageCounter2 = this.synchronousAgentProcessorUsageSlidingCounters[context.CurrentAgent.SequenceNumber];
                slidingAverageCounter2.AddValue(context.TotalProcessorTime);
                long rawValue4;
                long rawValue3 = slidingAverageCounter2.CalculateAverageAcrossAllSamples(out rawValue4);
                instance.AverageAgentProcessorUsageSynchronousInvocations.RawValue = rawValue3;
                instance.SynchronousAgentInvocationSamples.RawValue = rawValue4;
            }
            context.CleanupCpuTracker();
        }
예제 #2
0
        public void Invoke(MExSession session)
        {
            string      eventTopic = session.EventTopic;
            AgentRecord agentRecord;

            if (session.CurrentAgent == null)
            {
                agentRecord = this.executionChain;
                if (this.clonedTopic != null && this.clonedExecutionEntry >= 0 && this.clonedTopic == eventTopic)
                {
                    ExTraceGlobals.DispatchTracer.TraceDebug <string, int>((long)this.GetHashCode(), this.InstanceNameFormatted + "restore clone state for '{0}' at index {1}", eventTopic, this.clonedExecutionEntry);
                    for (int i = 0; i < this.clonedExecutionEntry; i++)
                    {
                        if (agentRecord == null)
                        {
                            ExTraceGlobals.DispatchTracer.TraceError <int>((long)this.GetHashCode(), this.InstanceNameFormatted + "restore clone state failed at index {0}", i);
                            break;
                        }
                        agentRecord = agentRecord.Next;
                    }
                }
            }
            else
            {
                agentRecord = session.NextAgent;
            }
            session.IsAsyncAgent = false;
            while (agentRecord != null)
            {
                session.CurrentAgent = agentRecord;
                if (agentRecord.Enabled)
                {
                    Agent instance = agentRecord.Instance;
                    instance.Session     = session;
                    instance.Synchronous = true;
                    instance.EventTopic  = eventTopic;
                    Delegate @delegate = (Delegate)instance.Handlers[eventTopic];
                    if (@delegate != null)
                    {
                        ExTraceGlobals.DispatchTracer.Information <string, string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "dispatching event '{0}' to {1} ({2})", eventTopic, instance.GetType().FullName, instance.GetHashCode().ToString());
                        session.IsAsyncAgent = false;
                        if (this.OnAgentInvokeStart != null)
                        {
                            this.OnAgentInvokeStart(this, session);
                        }
                        bool flag = true;
                        try
                        {
                            session.StartCpuTracking(instance.Name);
                            instance.Invoke(eventTopic, session.CurrentEventSource, session.CurrentEventArgs);
                            flag = false;
                        }
                        finally
                        {
                            session.StopCpuTracking();
                            if (flag)
                            {
                                session.NextAgent = null;
                                session.ExecutionCompleted();
                                session.CleanupCpuTracker();
                                ExTraceGlobals.DispatchTracer.TraceDebug <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "agent {0} crashed during event '{1}'", instance.GetType().FullName, eventTopic);
                            }
                        }
                        ExTraceGlobals.DispatchTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "event '{0}' handled by {1} {2}synchronously", eventTopic, instance.GetType().FullName, session.IsAsyncAgent ? "a" : string.Empty);
                        if (this.OnAgentInvokeReturns != null)
                        {
                            this.OnAgentInvokeReturns(this, session);
                        }
                        session.NextAgent = agentRecord.Next;
                        if (session.IsStatusHalt)
                        {
                            this.AgentInvokeCompleted(session);
                            session.NextAgent = null;
                            break;
                        }
                        if (session.IsAsyncAgent)
                        {
                            if (!session.IsSyncInvoke)
                            {
                                ExTraceGlobals.DispatchTracer.Information((long)this.GetHashCode(), this.InstanceNameFormatted + "async agent pending");
                                break;
                            }
                            session.Wait();
                            this.AgentInvokeCompleted(session);
                        }
                        else
                        {
                            this.AgentInvokeCompleted(session);
                        }
                    }
                    else if (this.settings.MonitoringOptions.MessageSnapshotEnabled)
                    {
                        instance.Invoke(eventTopic, session.CurrentEventSource, session.CurrentEventArgs);
                    }
                }
                agentRecord = agentRecord.Next;
            }
            if (agentRecord == null || (session.NextAgent == null && !session.IsAsyncAgent))
            {
                ExTraceGlobals.DispatchTracer.TraceDebug <string>((long)this.GetHashCode(), this.InstanceNameFormatted + "dispatching of event '{0}' completed", eventTopic);
                session.ExecutionCompleted();
            }
        }