public void CounterOperationWorkWithVirtualCounter()
        {
            // --- Arrange
            // ReSharper disable UseObjectOrCollectionInitializer
            var handle = new PerformanceCounterHandle(typeof(TestCounter1));

            // ReSharper restore UseObjectOrCollectionInitializer

            // --- Act
            handle.RawValue = 100;
            handle.Increment();
            var value1 = handle.RawValue;

            handle.IncrementBy(2);
            var value2 = handle.RawValue;

            handle.Decrement();
            var value3    = handle.RawValue;
            var sample    = handle.NextSample();
            var nextValue = handle.NextValue();

            handle.ReadOnly = true;

            // --- Assert
            value1.ShouldEqual(0);
            value2.ShouldEqual(0);
            value3.ShouldEqual(0);
            sample.ShouldEqual(CounterSample.Empty);
            nextValue.ShouldEqual(0.0F);
            handle.ReadOnly.ShouldBeFalse();
        }
        public void SingleInstanceCreationWorks()
        {
            // --- Act
            var handle = new PerformanceCounterHandle(typeof(TestCounter1));

            // --- Assert
            handle.ShouldNotBeNull();
            handle.HasInstance.ShouldBeFalse();
            handle.InstanceName.ShouldBeNull();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Obtains all performance counter handles used by the task processor.
 /// </summary>
 protected virtual void EnsurePerformanceCounters()
 {
     if (NumTasksPmc == null)
     {
         NumTasksPmc = PmcManager.GetCounter <TasksProcessedPmc>(Name);
     }
     if (NumTasksPerSecondPmc == null)
     {
         NumTasksPerSecondPmc = PmcManager.GetCounter <TasksProcessedPerSecondsPmc>(Name);
     }
     if (NumFailuresPmc == null)
     {
         NumFailuresPmc = PmcManager.GetCounter <TasksFailedPmc>(Name);
     }
     if (NumFailuresPerSecondPmc == null)
     {
         NumFailuresPerSecondPmc = PmcManager.GetCounter <TasksFailedPerSecondsPmc>(Name);
     }
     if (LastProcessTimePmc == null)
     {
         LastProcessTimePmc = PmcManager.GetCounter <LastTaskProcessingTimePmc>(Name);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Obtains all performance counter handles used by the task processor.
 /// </summary>
 protected virtual void EnsurePerformanceCounters()
 {
     if (NumTasksPmc == null)
         NumTasksPmc = PmcManager.GetCounter<TasksProcessedPmc>(Name);
     if (NumTasksPerSecondPmc == null)
         NumTasksPerSecondPmc = PmcManager.GetCounter<TasksProcessedPerSecondsPmc>(Name);
     if (NumFailuresPmc == null)
         NumFailuresPmc = PmcManager.GetCounter<TasksFailedPmc>(Name);
     if (NumFailuresPerSecondPmc == null)
         NumFailuresPerSecondPmc = PmcManager.GetCounter<TasksFailedPerSecondsPmc>(Name);
     if (LastProcessTimePmc == null)
         LastProcessTimePmc = PmcManager.GetCounter<LastTaskProcessingTimePmc>(Name);
 }