/// <summary>
        ///   Creates the reporter.
        /// </summary>
        /// <param name = "reporterType">Type of the reporter.</param>
        /// <returns>An intialized <see cref = "PerformanceCounterReporter" /> instance.</returns>
        public static PerformanceCounterReporter CreateReporter(PerformanceCounterReporterType reporterType)
        {
            string operationCounterName;
            string executionTimeCounterName;

            switch (reporterType)
            {
            case PerformanceCounterReporterType.CheckFeatureState:
            {
                operationCounterName     = PerformanceCounterNameResources.CHECK_FEATURE_STATE_CALL_COUNT;
                executionTimeCounterName = PerformanceCounterNameResources.CHECK_FEATURE_STATE_EXECUTION_TIME;
                break;
            }

            case PerformanceCounterReporterType.CreateFeature:
            {
                operationCounterName     = PerformanceCounterNameResources.CREATE_FEATURE_CALL_COUNT;
                executionTimeCounterName = PerformanceCounterNameResources.CREATE_FEATURE_EXECUTION_TIME;
                break;
            }

            case PerformanceCounterReporterType.UpdateFeatureState:
            {
                operationCounterName     = PerformanceCounterNameResources.UPDATE_FEATURE_STATE_COUNT;
                executionTimeCounterName = PerformanceCounterNameResources.UPDATE_FEATURE_STATE_EXECUTION_TIME;
                break;
            }

            case PerformanceCounterReporterType.RetrieveDefinedFeatures:
            {
                operationCounterName     = PerformanceCounterNameResources.RETRIEVE_DEFINED_FEATURES_COUNT;
                executionTimeCounterName =
                    PerformanceCounterNameResources.RETRIEVE_DEFINED_FEATURES_EXECUTION_TIME;
                break;
            }

            default:
            {
                throw new UnknownReporterTypeException(reporterType);
            }
            }

            return
                (CreateReporter(
                     PerformanceCounterNameResources.PERFORMANCE_COUNTER_CATEGORY_NAME,
                     operationCounterName,
                     executionTimeCounterName));
        }
Пример #2
0
        /// <summary>
        /// Asserts the performance counters recorded.
        /// </summary>
        /// <param name="reporterType">Type of the reporter.</param>
        /// <param name="checkExecutionTime">if set to <c>true</c> [check execution time].</param>
        /// <param name="expectedCount">The expected count.</param>
        /// <remarks></remarks>
        private static void AssertPerformanceCountersRecorded(PerformanceCounterReporterType reporterType,
                                                              bool checkExecutionTime, int expectedCount)
        {
            PerformanceCounterReporter counterRecorder = PerformanceCounterReporterFactory.CreateReporter(reporterType);

            Assert.AreEqual(expectedCount, counterRecorder.OperationCountValue);

            Assert.IsTrue(counterRecorder.OperationCountValue > 0);
            float executionTime = counterRecorder.ExecutionTimeValue;

            Console.WriteLine(@"The execution time was reported as " + executionTime);

            // The CheckFeatureState method smokes the millisecond barrier at these cache sizes,
            // therefore this check is disabled for that method.
            if (checkExecutionTime)
            {
                Assert.IsTrue(executionTime > 0);
            }
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "UnknownReporterTypeException" /> class.
 /// </summary>
 /// <param name = "reporterType">Type of the reporter.</param>
 public UnknownReporterTypeException(PerformanceCounterReporterType reporterType)
     : base(
         string.Format(CultureInfo.CurrentUICulture, ErrorMessageResources.INVALID_PERFORMANCE_COUNTER_REPORTER_TYPE, reporterType))
 {
 }