Ejemplo n.º 1
0
        /// <summary>
        /// This method is called right after the body of the aspected method has been
        /// executed, independently whether it was successful or failed.
        /// </summary>
        /// <param name="args">Descriptor representing the method call</param>
        /// <param name="result">Result descriptor representing the return values of the call</param>
        public override void OnExit(IMethodCallDescriptor args, IMethodResultDescriptor result)
        {
            // --- Decrement current call counters
            PmcManager.GetCounter <CurrentCallsPmc>(TOTAL).Decrement();
            var instanceName = GetInstanceName(args.Method);

            PmcManager.GetCounter <CurrentCallsPmc>(instanceName).Decrement();
        }
 public void PredefinedCountersWithInvalidInstanceNameFail()
 {
     // --- Act
     var counterInstance = PmcManager.GetCounter <ProcessorTimePercentagePmc>("x");
     // ReSharper disable UnusedVariable
     var value = counterInstance.RawValue;
     // ReSharper restore UnusedVariable
 }
        public void PredefinedCountersWork()
        {
            // --- Act
            var counterInstance1 = PmcManager.GetCounter <ProcessorTimePercentagePmc>("_Total");
            var counterInstance2 = PmcManager.GetCounter <ProcessorTimePercentagePmc>("_Total");
            var value            = counterInstance1.RawValue;

            // --- Assert
            counterInstance1.ShouldBeSameAs(counterInstance2);
            counterInstance1.HasInstance.ShouldBeTrue();
            value.ShouldBeGreaterThanOrEqualTo(0);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method is called right after <see cref="IMethodAspect.OnExit"/>, when the method body
        /// invocation raised an exception. Otherwise, the <see cref="IMethodAspect.OnSuccess"/> method is
        /// called.
        /// </summary>
        /// <param name="argsMessage">Message representing the method call</param>
        /// <param name="exceptionRaised">Exception raised by the method body</param>
        /// <returns>Exception instance to be raised by the caller of the aspected method</returns>
        public override Exception OnException(IMethodCallDescriptor argsMessage, Exception exceptionRaised)
        {
            // --- Increment Total counters
            PmcManager.GetCounter <NumberOfFailedCallsPmc>(TOTAL).Increment();
            PmcManager.GetCounter <NumberOfFailedCallsPerSecondsPmc>(TOTAL).Increment();

            // --- Increment operation counters
            var instanceName = GetInstanceName(argsMessage.Method);

            PmcManager.GetCounter <NumberOfFailedCallsPmc>(instanceName).Increment();
            PmcManager.GetCounter <NumberOfFailedCallsPerSecondsPmc>(instanceName).Increment();

            return(base.OnException(argsMessage, exceptionRaised));
        }
        public void BuiltInCountersWork()
        {
            // --- Act
            var counter = PmcManager.GetCounter <ProcessorTimePercentagePmc>();
            var sample1 = counter.NextSample();

            Thread.Sleep(400);
            var sample2 = counter.NextSample();
            var value   = CounterSample.Calculate(sample1, sample2);

            Console.WriteLine(value);

            // --- Assert
            value.ShouldBeGreaterThanOrEqualTo(0.0F);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method is called before the body of the aspected method is about to be
        /// invoked.
        /// </summary>
        /// <param name="args">Descriptor representing the method call</param>
        /// <param name="result">Result descriptor coming from the previous aspect.</param>
        /// <returns>
        /// This method should return null value indicating that the aspected method's body should
        /// be called. If the method body invocation should be omitted, this method returns the
        /// result descriptor substituting the result coming from the invocation of the method body.
        /// </returns>
        public override IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
        {
            // --- Increment Total counters
            PmcManager.GetCounter <NumberOfCallsPmc>(TOTAL).Increment();
            PmcManager.GetCounter <NumberOfCallsPerSecondsPmc>(TOTAL).Increment();
            PmcManager.GetCounter <CurrentCallsPmc>(TOTAL).Increment();

            // --- Increment operation counters
            var instanceName = GetInstanceName(args.Method);

            PmcManager.GetCounter <NumberOfCallsPmc>(instanceName).Increment();
            PmcManager.GetCounter <NumberOfCallsPerSecondsPmc>(instanceName).Increment();
            PmcManager.GetCounter <CurrentCallsPmc>(instanceName).Increment();

            return(base.OnEntry(args, result));
        }
        public void MultipleInstanceWork()
        {
            // --- Arrange
            var pmcData = new PmcCreationData();

            pmcData.Add(typeof(TestCounter1));
            pmcData.Add(typeof(TestCounter2));
            PmcManager.InstallPerformanceCounters(pmcData);

            // --- Act
            var inst1 = PmcManager.GetCounter <TestCounter1>("1");
            var inst2 = PmcManager.GetCounter <TestCounter1>("2");

            inst1.RawValue = 10;
            inst2.RawValue = 20;

            // --- Assert
            inst1.RawValue.ShouldEqual(10);
            inst2.RawValue.ShouldEqual(20);
        }
Ejemplo n.º 8
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);
     }
 }
 public void UsingGetCounterWithInvalidTypeFails()
 {
     // --- Act
     PmcManager.GetCounter(typeof(int));
 }
 public void UsingGetCounterWithNullDataFails()
 {
     // --- Act
     PmcManager.GetCounter(null);
 }