private static void CreateReport(LatencyReportingThreshold threshold, LatencyDetectionContext trigger, ICollection <LatencyDetectionContext> dataToLog, LatencyDetectionException exception) { StringBuilder stringBuilder = new StringBuilder(Math.Min(LatencyDetectionContext.EstimatedStringCapacity * (dataToLog.Count + 1), 42000)); stringBuilder.Append("Latency Threshold: ").Append(threshold.Threshold.TotalMilliseconds).AppendLine(" ms"); stringBuilder.AppendLine("Trigger").AppendLine(trigger.ToString()); if (dataToLog.Count > 0) { stringBuilder.Append(dataToLog.Count).AppendLine(" Backlog Entries"); foreach (LatencyDetectionContext latencyDetectionContext in dataToLog) { stringBuilder.AppendLine(latencyDetectionContext.ToString()); } } stringBuilder.AppendLine(exception.StackTrace); string text = trigger.Version; if (string.IsNullOrEmpty(text)) { text = "00.00.0000.000"; } string callstack = (trigger.StackTraceContext ?? string.Empty) + Environment.NewLine + exception.StackTrace; ExWatson.SendLatencyWatsonReport(text, trigger.Location.Identity, exception.WatsonExceptionName, callstack, exception.WatsonMethodName, stringBuilder.ToString()); }
public void Log(LatencyReportingThreshold threshold, LatencyDetectionContext trigger, ICollection <LatencyDetectionContext> context, LatencyDetectionException exception) { if (threshold == null) { throw new ArgumentNullException("threshold"); } if (trigger == null) { throw new ArgumentNullException("trigger"); } if (context == null) { throw new ArgumentNullException("context"); } if (exception == null) { throw new ArgumentNullException("exception"); } DateTime utcNow = DateTime.UtcNow; if (ExWatson.LastWatsonReport + TimeSpan.FromMinutes(1.0) < utcNow && this.lastReport + PerformanceReportingOptions.Instance.WatsonThrottle < utcNow) { this.lastReport = DateTime.UtcNow; WindowsErrorReportingLogger.CreateReport(threshold, trigger, context, exception); } }
private void IncrementCountAboveThreshold(LatencyDetectionContext data) { if (this.IsLatencyAboveThreshold(data)) { this.countAboveThreshold++; } }
internal bool ShouldCreateReport(LatencyDetectionContext currentContext, LoggingType loggingType, out LatencyDetectionContext trigger, out LatencyReportingThreshold thresholdToCheck, out ICollection <LatencyDetectionContext> dataToLog) { bool flag = false; dataToLog = null; thresholdToCheck = null; trigger = null; if (Thread.VolatileRead(ref this.creatingReport) == 0) { LatencyDetectionLocation location = currentContext.Location; BackLog backLog = location.GetBackLog(loggingType); thresholdToCheck = location.GetThreshold(loggingType); flag = backLog.AddAndQueryThreshold(currentContext); if (flag) { flag = (Interlocked.CompareExchange(ref this.creatingReport, 1, 0) == 0); if (flag) { try { flag = backLog.IsBeyondThreshold(out trigger); if (flag) { dataToLog = this.MoveBacklogDataToReport(loggingType); } } finally { Thread.VolatileWrite(ref this.creatingReport, 0); } } } } return(flag); }
private void RemoveNode(LinkedListNode <LatencyDetectionContext> node) { LatencyDetectionContext value = node.Value; if (this.IsLatencyAboveThreshold(value)) { this.countAboveThreshold--; } this.list.Remove(node); }
private bool IsLatencyAboveThreshold(LatencyDetectionContext data) { bool result = false; if ((data.TriggerOptions & TriggerOptions.DoNotTrigger) == TriggerOptions.None) { result = (data.Elapsed >= this.threshold.Threshold); } return(result); }
internal bool IsBeyondThreshold(out LatencyDetectionContext triggerContext) { bool flag = false; triggerContext = null; lock (this.lockObject) { flag = (this.countAboveThreshold >= (int)this.threshold.NumberRequired); if (flag) { triggerContext = this.trigger; } } return(flag); }
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()); }
internal void Log(LatencyDetectionContext context) { foreach (KeyValuePair <LoggingType, ILatencyDetectionLogger> keyValuePair in this.loggers) { ILatencyDetectionLogger value = keyValuePair.Value; LoggingType key = keyValuePair.Key; LatencyDetectionContext latencyDetectionContext; LatencyReportingThreshold threshold; ICollection <LatencyDetectionContext> backlog; bool flag = this.checker.ShouldCreateReport(context, key, out latencyDetectionContext, out threshold, out backlog); if (flag) { LatencyDetectionException exception = latencyDetectionContext.CreateLatencyDetectionException(); PerformanceReporter.LogData state = new PerformanceReporter.LogData(value, threshold, latencyDetectionContext, backlog, exception); ThreadPool.QueueUserWorkItem(PerformanceReporter.LogReportDelegate, state); } } }
internal bool AddAndQueryThreshold(LatencyDetectionContext data) { bool flag = false; try { if (Monitor.TryEnter(this.lockObject)) { flag = (this.countAboveThreshold >= (int)this.threshold.NumberRequired); if (flag) { this.Add(data); } else { this.TrimOldEntries(); flag = this.IsLatencyAboveThreshold(data); if (flag) { this.SetTrigger(data); } else { this.Add(data); } this.LimitBacklogSize(); } } } finally { if (Monitor.IsEntered(this.lockObject)) { Monitor.Exit(this.lockObject); } } return(flag); }
public void Log(LatencyReportingThreshold threshold, LatencyDetectionContext trigger, ICollection <LatencyDetectionContext> context, LatencyDetectionException exception) { if (threshold == null) { throw new ArgumentNullException("threshold"); } if (trigger == null) { throw new ArgumentNullException("trigger"); } if (context == null) { throw new ArgumentNullException("context"); } if (exception == null) { throw new ArgumentNullException("exception"); } LatencyEventLogger.eventLogger.LogEvent(CommonEventLogConstants.Tuple_LatencyDetection, string.Empty, new object[] { threshold.Threshold.TotalMilliseconds.ToString(), string.Format("Trigger:{0}", trigger.ToString("s")) }); }
internal LogData(ILatencyDetectionLogger logger, LatencyReportingThreshold threshold, LatencyDetectionContext trigger, ICollection <LatencyDetectionContext> backlog, LatencyDetectionException exception) { this.logger = logger; this.threshold = threshold; this.trigger = trigger; this.backlog = backlog; this.exception = exception; }
public LatencyDetectionContext CreateContext(ContextOptions contextOptions, string version, object hash, params IPerformanceDataProvider[] providers) { LatencyDetectionContext.ValidateBinningParameters(this.location, version, hash); return(new LatencyDetectionContext(this.location, contextOptions, version, hash, providers)); }
internal LatencyDetectionException(LatencyDetectionContext trigger, IPerformanceDataProvider provider) : this(trigger.Location.Identity, trigger.StackTraceContext.ToString(), trigger.Elapsed, trigger.Latencies, provider.Name) { }
internal LatencyDetectionException(LatencyDetectionContext trigger) : this(trigger.Location.Identity, trigger.StackTraceContext.ToString(), trigger.Elapsed, trigger.Latencies, string.Empty) { }
private void Add(LatencyDetectionContext data) { this.list.AddLast(data); this.IncrementCountAboveThreshold(data); }
internal CpuLatencyDetectionException(LatencyDetectionContext trigger) : base(trigger) { }
private void SetTrigger(LatencyDetectionContext data) { this.trigger = data; this.IncrementCountAboveThreshold(data); }
internal DataProviderLatencyDetectionException(LatencyDetectionContext trigger, IPerformanceDataProvider provider) : base(trigger, provider) { }