public void cpu_sample_generated_on_sample()
        {
            // Arrange
            var cpuSample = null as ImmutableCpuSample;

            Mock.Arrange(() => _cpuSampleTransformer.Transform(Arg.IsAny <ImmutableCpuSample>()))
            .DoInstead <ImmutableCpuSample>(sample => cpuSample = sample);

            // Act
            _sampleAction();

            // Assert
            Assert.NotNull(cpuSample);
        }
 public override void Sample()
 {
     try
     {
         var currentSampleTime    = DateTime.UtcNow;
         var currentProcessorTime = GetCurrentUserProcessorTime();
         var immutableCpuSample   = new ImmutableCpuSample(_processorCount, _lastSampleTime, _lastProcessorTime, currentSampleTime, currentProcessorTime);
         _cpuSampleTransformer.Transform(immutableCpuSample);
         _lastSampleTime    = currentSampleTime;
         _lastProcessorTime = currentProcessorTime;
     }
     catch (Exception ex)
     {
         Log.Error($"Unable to get CPU sample.  No CPU metrics will be reported.  Error : {ex}");
         Stop();
     }
 }