Exemple #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="item">Item stored in the stack</param>
        /// <param name="parent">Parent of this stack</param>
        private TimedScopeStack(TimedScope item, TimedScopeStack parent)
        {
            Code.ExpectsArgument(parent, nameof(parent), TaggingUtilities.ReserveTag(0x23817061 /* tag_96xb7 */));

            Item   = item;
            Parent = parent;
        }
Exemple #2
0
        /// <summary>
        /// Creates a scope (and starts by default)
        /// </summary>
        /// <param name="correlationData">Correlation Data</param>
        /// <param name="machineInformation">Machine Information</param>
        /// <param name="initialResult">Initial result to use</param>
        /// <param name="startScope">Should the scope be automatically started (for use in e.g. 'using' statement)</param>
        /// <param name="customLogger">Optional custom timed scope logger</param>
        /// <param name="replayEventConfigurator">Optional replay event configurator</param>
        /// <param name="timedScopeStackManager">Timed scope stack manager</param>
        /// <returns>A timed scope</returns>
        public TimedScope Create(CorrelationData correlationData, IMachineInformation machineInformation, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator,
                                 ITimedScopeStackManager timedScopeStackManager, TimedScopeResult initialResult = default(TimedScopeResult), bool startScope = true)
        {
            TimedScope scope = TimedScope.Create(this, correlationData, machineInformation, customLogger, replayEventConfigurator, timedScopeStackManager, initialResult);

            if (startScope)
            {
                scope.Start();
            }

            return(scope);
        }
Exemple #3
0
 /// <summary>
 /// Remove item from the stack and return the new stack
 /// </summary>
 /// <param name="scope">TimedScope stored at the top od the stack</param>
 /// <returns>New stack with the top item removed</returns>
 public TimedScopeStack Pop(out TimedScope scope)
 {
     scope = Item;
     return(Parent);
 }
Exemple #4
0
 /// <summary>
 /// Adds a new item to the stack
 /// </summary>
 /// <param name="item">Data item to store</param>
 /// <returns>Stack with the new item on it</returns>
 public TimedScopeStack Push(TimedScope item) => new TimedScopeStack(item, this);
Exemple #5
0
        /// <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();
        }
Exemple #6
0
 /// <summary>
 /// Deprecated - Creates a scope
 /// </summary>
 /// <remarks>This overload is obsoleted. Use the overload with TimedScopeResult for new scopes instead.</remarks>
 /// <param name="correlationData">Correlation data</param>
 /// <param name="machineInformation">Machine Information</param>
 /// <param name="initialResult">Initial result to use</param>
 /// <param name="startScope">Should the scope be automatically started (for use in e.g. 'using' statement)</param>
 /// <param name="customLogger">Optional custom timed scope logger</param>
 /// <param name="replayEventConfigurator">Optional replay event configurator</param>
 /// <param name="timedScopeStackManager">Timed scope stack manager</param>
 /// <returns>A timed scope</returns>
 public TimedScope Create(CorrelationData correlationData, IMachineInformation machineInformation, ITimedScopeLogger customLogger,
                          IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, bool?initialResult, bool startScope = true)
 => Create(correlationData, machineInformation, customLogger, replayEventConfigurator, timedScopeStackManager,
           TimedScope.ConvertBoolResultToTimedScopeResult(initialResult), startScope);