Esempio n. 1
0
        /// <summary>
        /// Record the duration and, optionally, set the timestamp to the current time.
        /// </summary>
        /// <param name="telemetry">Telemetry item object to update.</param>
        /// <param name="duration">The duration of the operation.</param>
        private static void StopImpl(OperationTelemetry telemetry, TimeSpan duration)
        {
            telemetry.Duration = duration;

            if (telemetry.Timestamp == DateTimeOffset.MinValue)
            {
                telemetry.Timestamp = PreciseTimestamp.GetUtcNow();
            }

            RichPayloadEventSource.Log.ProcessOperationStop(telemetry);
        }
        /// <summary>
        /// An extension to telemetry item that initializes the timer for the respective telemetry
        /// using a timestamp from a high-resolution <see cref="Stopwatch"/>.
        /// </summary>
        /// <param name="telemetry">Telemetry item object that calls this extension method.</param>
        /// <param name="timestamp">A high-resolution timestamp from <see cref="Stopwatch"/>.</param>
        public static void Start(this OperationTelemetry telemetry, long timestamp)
        {
            telemetry.Timestamp = PreciseTimestamp.GetUtcNow();

            // Begin time is used internally for calculating duration of operation at the end call,
            // and hence is stored using higher precision Clock.
            // Stopwatch.GetTimestamp() is used (instead of ElapsedTicks) as it is thread-safe.
            telemetry.BeginTimeInTicks = timestamp;

            RichPayloadEventSource.Log.ProcessOperationStart(telemetry);
        }