예제 #1
0
        /// <summary>
        /// Constructs the timed scope correlation data
        /// </summary>
        /// <returns>Correlation data</returns>
        private CorrelationData ConstructCorrelationDataEntries(IMachineInformation machineInformation)
        {
            CorrelationData correlationData = TimedScopeData;

            CorrelationData scopeData = TimedScopeData.Clone();

            scopeData.AddData(TimedScopeDataKeys.InternalOnly.ScopeName, Name);
            scopeData.AddData(TimedScopeDataKeys.InternalOnly.InstanceId, InstanceId.ToString());
            scopeData.AddData(TimedScopeDataKeys.InternalOnly.IsSuccessful, IsSuccessful.HasValue ? IsSuccessful.Value.ToString() : bool.FalseString);
            scopeData.AddData(TimedScopeDataKeys.InternalOnly.IsRoot, IsRoot.ToString());
            scopeData.AddData(TimedScopeDataKeys.InternalOnly.ScopeResult, Result.ToString());

            bool isFailed = !IsSuccessful ?? false;

            if (isFailed && FailureDescription != null)
            {
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.FailureDescription, FailureDescription.ToString());
            }

            scopeData.AddData(TimedScopeDataKeys.InternalOnly.Duration, DurationInMilliseconds.ToString(CultureInfo.InvariantCulture));
            long sequenceNumber = correlationData == null ? 0 : correlationData.NextEventSequenceNumber();

            scopeData.AddData(TimedScopeDataKeys.InternalOnly.SequenceNumber, sequenceNumber.ToString(CultureInfo.InvariantCulture));
            scopeData.AddData(TimedScopeDataKeys.InternalOnly.CallDepth, correlationData == null ? "0" : correlationData.CallDepth.ToString(CultureInfo.InvariantCulture));

            IMachineInformation machineInfo = machineInformation;

            if (machineInfo != null)
            {
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.MachineId, machineInfo.MachineId);
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.MachineCluster, machineInfo.MachineCluster);
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.MachineRole, machineInfo.MachineRole);
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.AgentName, machineInfo.AgentName);
            }

            // if the user hash has been set, add it to the scope data
            if (!string.IsNullOrWhiteSpace(m_userHashOverride))
            {
                ULSLogging.LogTraceTag(0x23817500 /* tag_96xua */, Categories.TimingGeneral, Levels.Verbose,
                                       "Overriding user hash metadata in the Timed Scope '{0}' with value '{1}'", Name, m_userHashOverride);
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.UserHash, m_userHashOverride);
            }
            else if (correlationData != null && !string.IsNullOrWhiteSpace(correlationData.UserHash))
            {
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.UserHash, correlationData.UserHash);
            }

            // capture performance metrics
            if (PerfDiagnostics != null && PerfDiagnostics.LastStatus)
            {
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.CpuCycles,
                                  PerfDiagnostics.CyclesUsed.ToString(CultureInfo.InvariantCulture));
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.UserModeDuration,
                                  PerfDiagnostics.UserModeMilliseconds.ToString(CultureInfo.InvariantCulture));
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.KernelModeDuration,
                                  PerfDiagnostics.KernelModeMilliseconds.ToString(CultureInfo.InvariantCulture));
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.HttpRequestCount,
                                  PerfDiagnostics.HttpRequestCount.ToString(CultureInfo.InvariantCulture));
                scopeData.AddData(TimedScopeDataKeys.InternalOnly.ServiceCallCount,
                                  PerfDiagnostics.ServiceCallCount.ToString(CultureInfo.InvariantCulture));
            }

            return(scopeData);
        }
예제 #2
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();
        }