Exemplo n.º 1
0
 private void IncrementPerfCounter()
 {
     this.webServiceCallTimer.Stop();
     this.averageProcessingTimeCounter.IncrementBy(this.webServiceCallTimer.ElapsedTicks);
     this.averageProcessingTimeCounterBase.Increment();
     base.RequestLogger.Add(RequestStatistics.Create(this.requestStatisticsType, this.webServiceCallTimer.ElapsedMilliseconds, this.queryList.Count, this.url));
 }
Exemplo n.º 2
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.º 3
0
 private void ComputeStatistics()
 {
     if (Interlocked.Exchange(ref this.statisticsComputed, 1) != 0)
     {
         return;
     }
     if (this.localRequestStopwatch != null)
     {
         this.localRequestStopwatch.Stop();
         base.RequestLogger.Add(RequestStatistics.Create(RequestStatisticsType.TotalLocal, this.localRequestStopwatch.ElapsedMilliseconds, base.QueryList.Count));
     }
 }
Exemplo n.º 4
0
        private void ExecuteInternal(BaseQuery query)
        {
            IStandardBudget standardBudget = null;

            if (Interlocked.Exchange(ref this.firstThreadEntryTimeCaptured, 1) == 0)
            {
                base.RequestLogger.Add(RequestStatistics.Create(RequestStatisticsType.LocalFirstThreadExecute, this.localRequestStopwatch.ElapsedMilliseconds));
            }
            if (base.Aborted)
            {
                return;
            }
            RequestStatisticsForMapi requestStatisticsForMapi = RequestStatisticsForMapi.Begin();
            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                if (base.ClientContext.Budget != null)
                {
                    standardBudget = StandardBudget.Acquire(base.ClientContext.Budget.Owner);
                    if (standardBudget != null)
                    {
                        standardBudget.StartLocal("LocalRequest.ExecuteInternal", default(TimeSpan));
                    }
                }
                LocalRequest.RequestRoutingTracer.TraceDebug <object, int>((long)this.GetHashCode(), "{0}: Entered LocalRequest.Execute() using thread {1}", TraceContext.Get(), Environment.CurrentManagedThreadId);
                if (query.SetResultOnFirstCall(this.localQuery.GetData(query)))
                {
                    LocalRequest.RequestRoutingTracer.TraceDebug <object, EmailAddress, int>((long)this.GetHashCode(), "{0}: Request for mailbox {1} complete and result set in time. Thread {2}", TraceContext.Get(), query.Email, Environment.CurrentManagedThreadId);
                }
            }
            finally
            {
                stopwatch.Stop();
                if (standardBudget != null)
                {
                    standardBudget.EndLocal();
                    standardBudget.Dispose();
                }
                base.RequestLogger.Add(RequestStatistics.Create(RequestStatisticsType.LocalElapsedTimeLongPole, stopwatch.ElapsedMilliseconds, query.ExchangePrincipal.MailboxInfo.Location.ServerFqdn));
                base.RequestLogger.Add(requestStatisticsForMapi.End(RequestStatisticsType.Local, query.ExchangePrincipal.MailboxInfo.Location.ServerFqdn));
                if (Interlocked.Decrement(ref this.pendingItems) == 0)
                {
                    this.ComputeStatistics();
                    this.DisposeIfInternalContext();
                    base.Complete();
                }
                LocalRequest.RequestRoutingTracer.TraceDebug <object, int>((long)this.GetHashCode(), "{0}: Exited LocalRequest.Execute() using thread {1}", TraceContext.Get(), Environment.CurrentManagedThreadId);
            }
        }
Exemplo n.º 5
0
        public RequestStatistics End(RequestStatisticsType tag, string destination)
        {
            ThreadTimes fromCurrentThread = ThreadTimes.GetFromCurrentThread();

            if (this.begin == null || fromCurrentThread == null)
            {
                return(null);
            }
            long timeTaken = (long)(fromCurrentThread.Kernel.TotalMilliseconds - this.begin.Kernel.TotalMilliseconds) + (long)(fromCurrentThread.User.TotalMilliseconds - this.begin.User.TotalMilliseconds);

            if (destination == null)
            {
                return(RequestStatistics.Create(tag, timeTaken));
            }
            return(RequestStatistics.Create(tag, timeTaken, destination));
        }
Exemplo n.º 6
0
        public RequestStatistics End(RequestStatisticsType tag, string destination)
        {
            long timeTaken    = 0L;
            int  requestCount = 0;
            PerformanceContext performanceContext;

            if (NativeMethods.GetTLSPerformanceContext(out performanceContext))
            {
                timeTaken    = (long)((performanceContext.rpcLatency - this.beginRpcLatency) / 100000UL);
                requestCount = (int)(performanceContext.rpcCount - this.beginRpcCount);
            }
            if (destination == null)
            {
                return(RequestStatistics.Create(tag, timeTaken, requestCount));
            }
            return(RequestStatistics.Create(tag, timeTaken, requestCount, destination));
        }
Exemplo n.º 7
0
        public RequestStatistics End(RequestStatisticsType tag, string destination)
        {
            PerformanceContext performanceContext = PerformanceContext.Current;
            long timeTaken    = 0L;
            int  requestCount = 0;

            if (this.begin != null && performanceContext != null)
            {
                timeTaken    = (long)(performanceContext.RequestLatency - this.begin.RequestLatency);
                requestCount = (int)(performanceContext.RequestCount - this.begin.RequestCount);
            }
            if (destination == null)
            {
                return(RequestStatistics.Create(tag, timeTaken, requestCount));
            }
            return(RequestStatistics.Create(tag, timeTaken, requestCount, destination));
        }
 private void Complete(IAsyncResult asyncResult)
 {
     try
     {
         this.requestedToken = this.securityTokenService.EndIssueToken(asyncResult);
     }
     catch (LocalizedException ex)
     {
         this.exception = ex;
     }
     finally
     {
         this.stopwatch.Stop();
         this.requestLogger.Add(RequestStatistics.Create(RequestStatisticsType.FederatedToken, this.stopwatch.ElapsedMilliseconds));
         base.Complete();
     }
 }
Exemplo n.º 9
0
 public void Add(RequestStatistics requestStatistics)
 {
     lock (this.items)
     {
         RequestStatistics requestStatistics2;
         if (this.items.TryGetValue(requestStatistics.Tag, out requestStatistics2))
         {
             if (requestStatistics.TimeTaken > requestStatistics2.TimeTaken)
             {
                 this.items[requestStatistics.Tag] = requestStatistics;
             }
         }
         else
         {
             this.items[requestStatistics.Tag] = requestStatistics;
         }
     }
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 protected void HandleResult(AutoDiscoverRequestResult[] autoDiscoverResults)
 {
     this.autoDiscoverTimer.Stop();
     base.RequestLogger.Add(RequestStatistics.Create(RequestStatisticsType.AutoDiscoverRequest, this.autoDiscoverTimer.ElapsedMilliseconds, autoDiscoverResults.Length, this.TargetUri.ToString()));
     this.Results = autoDiscoverResults;
 }
Exemplo n.º 12
0
        protected override void EndInvoke(IAsyncResult asyncResult)
        {
            WebResponse webResponse = null;

            try
            {
                AutoDiscoverRequest.FaultInjectionTracer.TraceTest(2263231805U);
                webResponse = this.request.EndGetResponse(asyncResult);
                if (webResponse != null)
                {
                    this.headers = webResponse.Headers;
                    HttpWebResponse httpWebResponse = webResponse as HttpWebResponse;
                    if (httpWebResponse != null && httpWebResponse.StatusCode == HttpStatusCode.Found)
                    {
                        string text = this.headers["Location"];
                        if (string.IsNullOrEmpty(text))
                        {
                            this.HandleException(Strings.descAutoDiscoverBadRedirectLocation(this.emailAddress.ToString(), "null"), 50492U);
                        }
                        else
                        {
                            AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, string, Uri>((long)this.GetHashCode(), "{0}: Got a redirect from AutoDiscover to {1}, original location was {1}.", TraceContext.Get(), text, this.targetUri);
                            Uri uri;
                            try
                            {
                                uri = new Uri(text);
                            }
                            catch (UriFormatException exception)
                            {
                                this.HandleException(Strings.descAutoDiscoverBadRedirectLocation(this.emailAddress.ToString(), text), exception);
                                return;
                            }
                            UriBuilder uriBuilder = new UriBuilder(uri);
                            uriBuilder.Scheme = (Configuration.UseSSLForAutoDiscoverRequests ? "https" : "http");
                            this.Result       = new AutoDiscoverRequestResult(this.targetUri, null, uriBuilder.Uri, null, this.headers[WellKnownHeader.XFEServer], this.headers[WellKnownHeader.XBEServer]);
                        }
                    }
                    else
                    {
                        this.responseText = this.GetResponseText(webResponse);
                        if (this.responseText == null || this.responseText.Length == 0)
                        {
                            this.HandleException(Strings.descNullAutoDiscoverResponse, new XmlException());
                        }
                        else
                        {
                            string text2 = this.FindError();
                            if (text2 != null)
                            {
                                this.HandleException(Strings.descAutoDiscoverFailedWithException(this.emailAddress.ToString(), text2), 47420U);
                            }
                            else
                            {
                                string text3 = this.FindRedirectAddress();
                                if (text3 != null)
                                {
                                    string frontEndServerName  = null;
                                    string backEnderServerName = null;
                                    if (this.headers != null)
                                    {
                                        frontEndServerName  = this.headers[WellKnownHeader.XFEServer];
                                        backEnderServerName = this.headers[WellKnownHeader.XBEServer];
                                    }
                                    this.Result = new AutoDiscoverRequestResult(this.targetUri, text3, null, null, frontEndServerName, backEnderServerName);
                                }
                                else
                                {
                                    WebServiceUri webServiceUri = this.FindWebServiceUrlForProtocol("EXPR");
                                    if (webServiceUri != null)
                                    {
                                        this.Result = new AutoDiscoverRequestResult(this.targetUri, null, null, webServiceUri, null, null);
                                    }
                                    else
                                    {
                                        webServiceUri = this.FindWebServiceUrlForProtocol("EXCH");
                                        if (webServiceUri != null)
                                        {
                                            this.Result = new AutoDiscoverRequestResult(this.targetUri, null, null, webServiceUri, null, null);
                                        }
                                        else
                                        {
                                            this.HandleException(Strings.descProtocolNotFoundInAutoDiscoverResponse("EXCH", this.targetUri.ToString()), null);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (WebException exception2)
            {
                this.HandleException(exception2);
            }
            catch (ArgumentNullException exception3)
            {
                this.HandleException(exception3);
            }
            catch (ArgumentException exception4)
            {
                this.HandleException(exception4);
            }
            catch (InvalidOperationException exception5)
            {
                this.HandleException(exception5);
            }
            catch (NotSupportedException exception6)
            {
                this.HandleException(exception6);
            }
            catch (XmlException exception7)
            {
                this.HandleException(exception7);
            }
            catch (XPathException exception8)
            {
                this.HandleException(exception8);
            }
            catch (UriFormatException exception9)
            {
                this.HandleException(exception9);
            }
            finally
            {
                if (webResponse != null)
                {
                    webResponse.Close();
                }
                this.timer.Stop();
                base.RequestLogger.Add(RequestStatistics.Create(RequestStatisticsType.AutoDiscoverRequest, this.timer.ElapsedMilliseconds, this.targetUri.ToString()));
            }
        }
Exemplo n.º 13
0
 protected virtual void LogExpensiveRequests(RequestStatistics threadStatistics, RequestStatistics mapiStatistics, RequestStatistics adStatistics)
 {
 }