private void OnEventObservered(KeyValuePair <string, object> eventInfo)
        {
            if (eventInfo.Key != null &&
                eventInfo.Value != null &&
                eventInfo.Value is DiagnosticEventsSpecification.EventPayload eventPayload)
            {
                if (eventInfo.Key.Equals(DiagnosticEventsSpecification.DirectSourceEventName, StringComparison.Ordinal) &&
                    eventPayload.SourceName != null &&
                    eventPayload.SourceName.Equals(DiagnosticEventsSpecification.DirectSourceName, StringComparison.Ordinal))
                {
                    _directSourceResultAccumulator.SetReceived(eventPayload.Iteration);
                    return;
                }

                if (eventInfo.Key.Equals(DiagnosticEventsSpecification.StubbedSourceEventName, StringComparison.Ordinal) &&
                    eventPayload.SourceName != null &&
                    eventPayload.SourceName.Equals(DiagnosticEventsSpecification.StubbedSourceName, StringComparison.Ordinal))
                {
                    _stubbedSourceResultAccumulator.SetReceived(eventPayload.Iteration);
                    return;
                }
            }

            ConsoleWrite.Line();
            ConsoleWrite.Line($"Unexpected event info:");
            ConsoleWrite.Line($"    Name:          \"{eventInfo.Key ?? "<null>"}\"");
            ConsoleWrite.Line($"    Payload type:  \"{eventInfo.Value?.GetType()?.FullName ?? "<null>"}\"");
            ConsoleWrite.Line($"    Payload value: \"{eventInfo.Value?.ToString() ?? "<null>"}\"");
        }
Пример #2
0
        public async Task Run()
        {
            ConsoleWrite.Line();
            ConsoleWrite.Line($"Starting {this.GetType().Name}.{nameof(Run)}.");

            string           srcName          = DiagnosticEventsSpecification.DirectSourceName;
            DiagnosticSource diagnosticSource = new DiagnosticListener(srcName);

            Random rnd = new Random();

            int currIteration = CurrentIteration;

            while (currIteration < _maxInterations)
            {
                if (diagnosticSource.IsEnabled(DiagnosticEventsSpecification.DirectSourceEventName))
                {
                    diagnosticSource.Write(DiagnosticEventsSpecification.DirectSourceEventName, new DiagnosticEventsSpecification.EventPayload(currIteration, srcName));
                }

                if (currIteration == _phaseOneIterations)
                {
                    PhaseOneCompletedEvent.Set();
                }

                int sleepMillis = rnd.Next(MaxSleepMillis);
                if (sleepMillis == 0)
                {
                    ;
                }
                if (sleepMillis == 1)
                {
                    Thread.Yield();
                }
                else
                {
                    await Task.Delay(sleepMillis);
                }

                currIteration = Interlocked.Increment(ref _currentIteration);
            }

            ConsoleWrite.Line();
            ConsoleWrite.Line($"Finishing {this.GetType().Name}.{nameof(Run)}.");

            if (diagnosticSource is IDisposable disposableSource)
            {
                disposableSource.Dispose();
            }

            ConsoleWrite.Line($"Finished {this.GetType().Name}.{nameof(Run)}.");
        }
Пример #3
0
        public async Task Run()
        {
            ConsoleWrite.LineLine($"Starting {this.GetType().Name}.{nameof(Run)}.");

            Random rnd = new Random();

            DiagnosticSourceAssembly.SubscribeDynamicInvokerInitializedListener(OnDynamicDiagnosticSourceInvokerInitialized, rnd);

            {
                ConsoleWrite.LineLine($"Kicking off the DS magic.");
                bool prevInit = DiagnosticSourceAssembly.IsInitialized;
                bool nowInit  = DiagnosticSourceAssembly.EnsureInitialized();
                ConsoleWrite.Line($"DiagnosticSourceAssembly-magic status: prevInit={prevInit}, nowInit={nowInit}.");
            }

            int currIteration = CurrentIteration;

            while (currIteration < _maxInterations)
            {
                WriteIfEnabled(_diagnosticSource, currIteration);

                if (currIteration == _phaseOneIterations)
                {
                    PhaseOneCompletedEvent.Set();
                }

                int sleepMillis = rnd.Next(MaxSleepMillis);
                if (sleepMillis == 0)
                {
                    ;
                }
                else if (sleepMillis == 1)
                {
                    Thread.Yield();
                }
                else
                {
                    await Task.Delay(sleepMillis - 2);
                }

                currIteration = Interlocked.Increment(ref _currentIteration);
            }

            ConsoleWrite.Line();
            ConsoleWrite.Line($"Finishing {this.GetType().Name}.{nameof(Run)}.");

            Dispose(_diagnosticSource);

            ConsoleWrite.Line($"Finished {this.GetType().Name}.{nameof(Run)}.");
        }