Exemple #1
0
        public string ToString(string format, IFormatProvider formatProvider)
        {
            StringBuilder stringBuilder = new StringBuilder(LatencyDetectionContext.EstimatedStringCapacity);

            stringBuilder.AppendLine("---");
            LatencyDetectionContext.AppendLine(stringBuilder, "Location: ", this.latencyDetectionLocation.Identity);
            LatencyDetectionContext.AppendLine(stringBuilder, "Version: ", this.assemblyVersion);
            LatencyDetectionContext.AppendLine(stringBuilder, "Stack Trace Context: ", this.StackTraceContext.ToString());
            if (!string.IsNullOrEmpty(this.UserIdentity))
            {
                LatencyDetectionContext.AppendLine(stringBuilder, "User Identity: ", this.UserIdentity);
            }
            LatencyDetectionContext.AppendLine(stringBuilder, "Started: ", this.timeStarted.ToString(CultureInfo.InvariantCulture));
            TimeSpan elapsed = this.Elapsed;

            LatencyDetectionContext.AppendLine(stringBuilder, "Total Time: ", elapsed.ToString());
            if (MyStopwatch.CpuTimeIsAvailable && this.timer != null)
            {
                TimeSpan elapsedCpu = this.timer.ElapsedCpu;
                LatencyDetectionContext.AppendLine(stringBuilder, "Elapsed in CPU: ", elapsedCpu.ToString());
                LatencyDetectionContext.AppendLine(stringBuilder, "Elapsed in CPU (% of Latency): ", (100.0 * elapsedCpu.TotalMilliseconds / elapsed.TotalMilliseconds).ToString(CultureInfo.InvariantCulture));
                if (this.timer.FinishedOnDifferentProcessor)
                {
                    stringBuilder.AppendLine("Finished on different processor.");
                }
                if (this.timer.PowerManagementChangeOccurred)
                {
                    stringBuilder.AppendLine("Power management change occured.");
                }
            }
            for (int i = 0; i < this.providers.Length; i++)
            {
                TaskPerformanceData taskPerformanceData = this.taskData[i];
                uint count = taskPerformanceData.Difference.Count;
                if (count > 0U)
                {
                    string name = this.providers[i].Name;
                    LatencyDetectionContext.AppendLine <uint>(stringBuilder, name, " Count: ", count);
                    LatencyDetectionContext.AppendLine <int>(stringBuilder, name, " Latency: ", taskPerformanceData.Difference.Milliseconds, " ms");
                    if (format != "s" && !string.IsNullOrEmpty(taskPerformanceData.Operations))
                    {
                        LatencyDetectionContext.AppendLine <string>(stringBuilder, name, " Operations: ", taskPerformanceData.Operations);
                    }
                }
            }
            LatencyDetectionContext.estimatedStringCapacity = Math.Min(Math.Max(LatencyDetectionContext.estimatedStringCapacity, stringBuilder.Capacity), 42000);
            return(stringBuilder.ToString());
        }
Exemple #2
0
        private void SetDataProviders(IPerformanceDataProvider[] dataProviders)
        {
            int num = (dataProviders != null) ? dataProviders.Length : 0;

            this.providers = new IPerformanceDataProvider[num];
            this.taskData  = new TaskPerformanceData[num];
            for (int i = 0; i < num; i++)
            {
                IPerformanceDataProvider performanceDataProvider = dataProviders[i];
                if (performanceDataProvider == null)
                {
                    string message = string.Format(CultureInfo.InvariantCulture, "dataProviders[{0}] was null.", new object[]
                    {
                        i
                    });
                    throw new ArgumentNullException("dataProviders", message);
                }
                this.providers[i] = performanceDataProvider;
                TaskPerformanceData taskPerformanceData = new TaskPerformanceData();
                taskPerformanceData.Start = performanceDataProvider.TakeSnapshot(true);
                this.taskData[i]          = taskPerformanceData;
            }
        }
Exemple #3
0
 public TaskPerformanceData[] StopAndFinalizeCollection()
 {
     if (this.timer != null)
     {
         this.timer.Stop();
     }
     for (int i = 0; i < this.providers.Length; i++)
     {
         IPerformanceDataProvider performanceDataProvider = this.providers[i];
         TaskPerformanceData      taskPerformanceData     = this.taskData[i];
         taskPerformanceData.End        = performanceDataProvider.TakeSnapshot(false);
         taskPerformanceData.Operations = performanceDataProvider.Operations;
         performanceDataProvider.ResetOperations();
         if (performanceDataProvider.ThreadLocal)
         {
             taskPerformanceData.InvalidateIfAsynchronous();
         }
     }
     if ((this.contextOptions & ContextOptions.DoNotCreateReport) != ContextOptions.DoNotCreateReport && LatencyDetectionContext.options.LatencyDetectionEnabled)
     {
         LatencyDetectionContext.reporter.Log(this);
     }
     return(this.taskData);
 }