/// <summary> /// Create a timed scope /// </summary> /// <param name="scopeDefinition">Timed scope definition</param> /// <param name="initialResult">The default result for the scope</param> /// <param name="customLogger">Use a custom logger for the timed scope</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <param name="correlationData">Correlation data</param> /// <param name="machineInformation">Machine Information</param> /// <returns>Newly created scope</returns> public static TimedScope Create(TimedScopeDefinition scopeDefinition, CorrelationData correlationData, IMachineInformation machineInformation, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, TimedScopeResult initialResult = default(TimedScopeResult)) { return(new TimedScope(scopeDefinition, correlationData, customLogger, replayEventConfigurator, machineInformation, timedScopeStackManager) { TimedScopeData = correlationData, RunningTransaction = TransactionMonitor.RunningTransaction(correlationData), Result = initialResult, }); }
/// <summary> /// Start the timed scope /// </summary> public void Start() { if (IsDisposed) { ULSLogging.LogTraceTag(0x238174dd /* tag_96xt3 */, Categories.TimingGeneral, Levels.Error, "Attempting to start scope '{0}' that has already been disposed.", Name); return; } if (IsScopeActive) { ULSLogging.LogTraceTag(0x238174de /* tag_96xt4 */, Categories.TimingGeneral, Levels.Error, "Attempting to start scope '{0}' that has already been started.", Name); return; } string metaDataCopy = MetaData; string subTypeCopy = SubType; CorrelationData currentCorrelation = CorrelationData; TimedScopeData = currentCorrelation.Clone() ?? new CorrelationData(); RunningTransaction = TransactionMonitor.RunningTransaction(TimedScopeData); if (!string.IsNullOrWhiteSpace(metaDataCopy) && string.IsNullOrWhiteSpace(MetaData)) { MetaData = metaDataCopy; } if (!string.IsNullOrWhiteSpace(subTypeCopy) && string.IsNullOrWhiteSpace(SubType)) { SubType = subTypeCopy; } // differentiate scope name when running under a test transaction if (IsTransaction) { NameSuffix = string.Concat(NameSuffix, "::Trx", RunningTransaction.ToString(CultureInfo.InvariantCulture)); } // differentiate special scopes if (TimedScopeData.IsFallbackCall) { NameSuffix = string.Concat(NameSuffix, "::Fallback"); } // differentiate scope name for inner (proxied) calls if (TimedScopeData.CallDepth > 0) { NameSuffix = string.Concat(NameSuffix, "::Depth", TimedScopeData.CallDepth.ToString(CultureInfo.InvariantCulture)); if (currentCorrelation != null) { // reset call depth so any inner scopes are reported as layer 0 again currentCorrelation.CallDepth = 0; } } Parent = TimedScopeStackManager.Scopes?.Peek(); IsRoot = Parent == null && TimedScopeData.CallDepth == 0; StartTick = Stopwatch.GetTimestamp(); IsScopeActive = true; ScopeLogger.LogScopeStart(this); PerfDiagnostics = new PerfDiagnostics(Parent != null ? Parent.PerfDiagnostics : null); PerfDiagnostics.Start(); }