public DiagnosticsService(IIdleService idleService, ISchedulerService schedulerService)
        {
            using (Duration.Measure(Logger, "Constructor - " + GetType().Name))
            {
                _schedulerService = schedulerService;

                _disposable = new CompositeDisposable()
                              .DisposeWith(this);

                _sync = new object();

                _countersObservable = CreatePerformanceCounters()
                                      .DelaySubscription(Constants.UI.Diagnostics.DiagnosticsSubscriptionDelay, schedulerService.TaskPool)
                                      .SubscribeOn(schedulerService.TaskPool)
                                      .ObserveOn(schedulerService.TaskPool)
                                      .CombineLatest(
                    idleService.Idling.Buffer(Constants.UI.Diagnostics.DiagnosticsIdleBuffer,
                                              schedulerService.TaskPool).Where(x => x.Any()), (x, y) => x)
                                      .Replay(1);

                _loggingTarget = (LimitedMemoryTarget)LogManager.Configuration.FindTargetByName("memory");
            }
        }
Esempio n. 2
0
        public DiagnosticsService(IIdleService idleService, ISchedulerService schedulerService)
        {
            _schedulerService = schedulerService;

            _disposable = new CompositeDisposable();

            _sync = new object();

            _countersObservable = Observable.Create <Counters>(x =>
            {
                var disposable = new CompositeDisposable();

                try
                {
                    var processName = GetProcessInstanceName();

                    Logger.Info("Creating performance counter 'Working Set'");

                    var workingSetCounter = new PerformanceCounter("Process", "Working Set", processName);
                    disposable.Add(workingSetCounter);

                    Logger.Info("Creating performance counter '% Processor Time'");

                    var cpuCounter = new PerformanceCounter("Process", "% Processor Time", processName);
                    disposable.Add(cpuCounter);

                    using (Duration.Measure(Logger, "Initialising created performance counters"))
                    {
                        workingSetCounter.NextValue();
                        cpuCounter.NextValue();
                    }

                    x.OnNext(new Counters(workingSetCounter, cpuCounter));

                    Logger.Info("Ready");
                }
                catch (ArgumentException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (InvalidOperationException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (Win32Exception exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (PlatformNotSupportedException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (UnauthorizedAccessException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }

                return(disposable);
            })
                                  .DelaySubscription(Constants.DiagnosticsSubscriptionDelay, schedulerService.TaskPool)
                                  .SubscribeOn(schedulerService.TaskPool)
                                  .ObserveOn(schedulerService.TaskPool)
                                  .CombineLatest(idleService.Idling.Buffer(Constants.DiagnosticsIdleBuffer, schedulerService.TaskPool).Where(x => x.Any()), (x, y) => x)
                                  .Replay(1);

            _rpsQueue      = new Queue <long>();
            _rpsObservable = Observable.FromEventPattern <EventHandler, EventArgs>(h => CompositionTarget.Rendering += h,
                                                                                   h => CompositionTarget.Rendering -= h)
                             .Synchronize()
                             .Select(x => CalculateRps())
                             .Publish();

            _loggingTarget = (LimitedMemoryTarget)LogManager.Configuration.FindTargetByName("memory");
        }