/// <summary>
        /// Creates the real time listener.
        /// </summary>
        /// <param name="providerGuid">The provider unique identifier.</param>
        /// <param name="etlSessionConfigName">Name of the etl session configuration.</param>
        /// <param name="action">The action.</param>
        /// <param name="eventIdFilter">Event Id filter to call the action</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The ETW listener</returns>
        private static RawListener CreateRealTimeListener(
            Guid providerGuid,
            string etlSessionConfigName,
            Action <IDiagnosticHeartbeat> action,
            int eventIdFilter,
            CancellationToken cancellationToken)
        {
            return(RawListener.CreateRealTimeListener(
                       etlSessionConfigName,
                       eventRecord =>
            {
                if (eventRecord->EventHeader.ProviderId == providerGuid && eventRecord->EventHeader.Id == eventIdFilter)
                {
                    action(DiagnosticHeartbeat.FromEtwEvent(eventRecord));
                }
            },
                       eventTraceLog =>
            {
                Logger.Log(
                    LoggerLevel.Info,
                    LogId,
                    "CreateRealTimeListener",
                    "DiagnosticHeartbeat, cancelled = {0}",
                    cancellationToken.IsCancellationRequested);

                return !cancellationToken.IsCancellationRequested;
            }));
        }
Exemple #2
0
        /// <summary>
        /// Froms the etw event.
        /// </summary>
        /// <param name="etwMetricData">The etw metric data.</param>
        /// <returns>The diagnostic heartbeat.</returns>
        public static unsafe IDiagnosticHeartbeat FromEtwEvent(NativeMethods.EventRecord *etwMetricData)
        {
            var heartbeat = new DiagnosticHeartbeat();

            var pointerInPayload = etwMetricData->UserData;

            heartbeat.InstanceName = EtwPayloadManipulationUtils.ReadString(ref pointerInPayload);

            var uptimeSec = *((int *)pointerInPayload);

            pointerInPayload      = EtwPayloadManipulationUtils.Shift(pointerInPayload, sizeof(int));
            heartbeat.UptimeInSec = uptimeSec;

            var etwEventsDropped = *((int *)pointerInPayload);

            pointerInPayload = EtwPayloadManipulationUtils.Shift(pointerInPayload, sizeof(int));
            heartbeat.EtwEventsDroppedCount = etwEventsDropped;

            var etwEventsLost = *((int *)pointerInPayload);

            pointerInPayload             = EtwPayloadManipulationUtils.Shift(pointerInPayload, sizeof(int));
            heartbeat.EtwEventsLostCount = etwEventsLost;

            var aggregatedMetricsDropped = *((int *)pointerInPayload);

            pointerInPayload = EtwPayloadManipulationUtils.Shift(pointerInPayload, sizeof(int));
            heartbeat.AggregatedMetricsDroppedCount = aggregatedMetricsDropped;

            var isNearingEtwLimit = *((byte *)pointerInPayload);

            pointerInPayload = EtwPayloadManipulationUtils.Shift(pointerInPayload, sizeof(byte));
            heartbeat.IsNearingEtwQueueLimit = isNearingEtwLimit != 0;

            var isNearingAggregationLimit = *((byte *)pointerInPayload);

            heartbeat.IsNearingAggregationQueueLimit = isNearingAggregationLimit != 0;

            return(heartbeat);
        }