Exemplo n.º 1
0
        private static void Set(string label, ThreadCounter threadCounter, ClientContext clientContext, RequestLogger requestLogger, ThreadContext.ExecuteDelegate executeDelegate)
        {
            string text = (clientContext != null) ? clientContext.IdentityForFilteredTracing : "none";
            RequestStatisticsForThread requestStatisticsForThread = RequestStatisticsForThread.Begin();

            threadCounter.Increment();
            ThreadContext.Tracer.TraceDebug <string, string, string>(0L, "{0}: Thread entered {1}. MessageId={2}", text, label, (clientContext != null) ? (clientContext.MessageId ?? "<null>") : "none");
            try
            {
                using (new ASTraceFilter(null, text))
                {
                    TraceContext.Set(text);
                    try
                    {
                        executeDelegate();
                    }
                    finally
                    {
                        TraceContext.Reset();
                    }
                }
            }
            finally
            {
                threadCounter.Decrement();
                RequestStatistics requestStatistics = requestStatisticsForThread.End(RequestStatisticsType.ThreadCPULongPole, label);
                if (requestStatistics != null && requestLogger != null)
                {
                    requestLogger.Add(requestStatistics);
                }
                ThreadContext.Tracer.TraceDebug <string, string>(0L, "{0}: Thread exited {1}", text, label);
            }
        }
Exemplo n.º 2
0
        private ReturnType ExecuteWithPerformanceMeasurement()
        {
            Query <ReturnType> .Tracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: {1}.Execute: enter", TraceContext.Get(), base.GetType().Name);

            RequestStatisticsForThread requestStatisticsForThread = RequestStatisticsForThread.Begin();
            RequestStatisticsForMapi   requestStatisticsForMapi   = RequestStatisticsForMapi.Begin();
            RequestStatisticsForAD     requestStatisticsForAD     = RequestStatisticsForAD.Begin();
            Stopwatch stopwatch       = Stopwatch.StartNew();
            Guid      serverRequestId = Microsoft.Exchange.Diagnostics.Trace.TraceCasStart(this.casTraceEventType);

            this.currentRequestsCounter.Increment();
            ReturnType result;

            try
            {
                result = this.ExecuteInternal();
            }
            finally
            {
                stopwatch.Stop();
                this.TraceExecuteInternalStop(serverRequestId);
                this.UpdateCountersAtExecuteEnd(stopwatch);
                this.currentRequestsCounter.Decrement();
                Query <ReturnType> .Tracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: {1}.Execute: exit", TraceContext.Get(), base.GetType().Name);

                RequestStatistics requestStatistics = requestStatisticsForMapi.End(RequestStatisticsType.MailboxRPC);
                requestStatistics.Log(this.RequestLogger);
                RequestStatistics requestStatistics2 = requestStatisticsForAD.End(RequestStatisticsType.AD);
                requestStatistics2.Log(this.RequestLogger);
                RequestStatistics requestStatistics3 = requestStatisticsForThread.End(RequestStatisticsType.RequestCPUMain);
                if (requestStatistics3 != null)
                {
                    requestStatistics3.Log(this.RequestLogger);
                }
                this.RequestLogger.Log();
                this.LogExpensiveRequests(requestStatistics3, requestStatistics, requestStatistics2);
            }
            return(result);
        }