private static void SetCumulativeComponentDependency(this MetricsReport metrics)
 {
     foreach (var type in metrics.Types)
     {
         type.CumulativeComponentDependency = CumulativeComponentDependency.Of(type, metrics.GraphOfTypes);
     }
 }
Exemplo n.º 2
0
 public static IEnumerable <NamespaceMetricsReport> NamespacesOverLimit <T>(this MetricsReport metrics, Func <NamespaceMetricsReport, T> metricSelector, Func <RatingFunctionLimits, Func <CommonReportKnowledge, T> > limitSelector)
     where T : IComparable <T>
 {
     return(from namespaceMetric in metrics.Namespaces
            where metricSelector(namespaceMetric).CompareTo(limitSelector(RatingFunctions.Limits)(metrics.CommonKnowledge)) > 0
            select namespaceMetric);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Schedule a generic reporter to be executed at a fixed <paramref name="interval"/>
        /// </summary>
        /// <param name="report">Function that returns an instance of a reporter</param>
        /// <param name="interval">Interval at which to run the report.</param>
        /// <param name="filter">Only report metrics that match the filter.</param>
        public MetricsReports WithReport(MetricsReport report, TimeSpan interval, MetricsFilter filter = null)
        {
            var newReport = new ScheduledReporter(report, this.metricsDataProvider.WithFilter(filter), this.healthStatus, interval);

            this.reports.Add(newReport);
            return(this);
        }
Exemplo n.º 4
0
 public void Ensure_MetricsReportIsAvailable()
 {
     if (Metrics == null)
     {
         Metrics = Analyze.Me();
     }
 }
 private static void SetInterestingDirectDependencies(this MetricsReport metrics)
 {
     foreach (var type in metrics.Types)
     {
         type.InterestingDirectDependencies = InterestingDirectDependencies.Of(type, metrics.Types);
     }
 }
Exemplo n.º 6
0
        private void OutputMetricsReport(MetricsReport metrics)
        {
            foreach (var namespaceMetrics in metrics.Namespaces)
            {
                OutputNamespaceMetricsReport(namespaceMetrics);
            }

            OutputSeperator(2);

            foreach (var type in metrics.Types.Where(t => !t.CompilerGenerated))
            {
                OutputTypeMetricsReport(type);
            }

            OutputSeperator(2);

            foreach (var method in metrics.Methods.Where(m => !m.CompilerGenerated && !m.OnlyDeclaration))
            {
                OutputMethodMetricsReport(method);
            }

            OutputSeperator(3);

            OutputRatings(metrics.Rate());
            OutputHotspots(metrics.Hotspots());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Schedule a generic reporter to be executed at a fixed <paramref name="interval"/>
        /// </summary>
        /// <param name="report">Function that returns an instance of a reporter</param>
        /// <param name="interval">Interval at which to run the report.</param>
        public MetricsReports WithReport(MetricsReport report, TimeSpan interval)
        {
            var newReport = new ScheduledReporter(report, this.metricsDataProvider, this.healthStatus, interval);

            this.ScheduledReporters.Add(newReport);
            return(this);
        }
 private static IEnumerable <MethodAndTypeMetrics> GetMethodOfLine(this MetricsReport metrics, LineLocation location)
 {
     return(from type in metrics.Types
            from method in metrics.MethodsOfType(type)
            where IsMethodAtLine(method, location)
            select new MethodAndTypeMetrics(type, method));
 }
        public PreparedMetricsReport Prepare(MetricsReport metrics)
        {
            var preparedMetrics = new PreparedMetricsReport(metrics, _lastMetrics);

            _lastMetrics = metrics;
            return(preparedMetrics);
        }
Exemplo n.º 10
0
 internal PreparedMetricsReport(MetricsReport metrics, MetricsReport lastMetrics)
 {
     Report         = metrics;
     PreviousReport = lastMetrics;
     ThrowExceptionWhenNoMetrics();
     Prepare();
 }
Exemplo n.º 11
0
        private PreparedMetricsReport AnalyzeProjectFiles(string[] files)
        {
            MetricsReport metrics = ShouldUseParallelism() ?
                                    AnalyzeParallel.PortableExecutables(files) :
                                    Analyze.PortableExecutables(files);

            return(metricsFactory.Prepare(metrics));
        }
Exemplo n.º 12
0
 public ScheduledReporter(MetricsReport report, MetricsDataProvider metricsDataProvider, Func <HealthStatus> healthStatus, TimeSpan interval, Scheduler scheduler)
 {
     this.report = report;
     this.metricsDataProvider = metricsDataProvider;
     this.healthStatus        = healthStatus;
     this.scheduler           = scheduler;
     this.scheduler.Start(interval, t => RunReport(t));
 }
Exemplo n.º 13
0
 public static IEnumerable <MethodMetricsReport> MethodsOverLimit <T>(this MetricsReport metrics, Func <MethodMetricsReport, T> metricSelector, Func <RatingFunctionLimits, Func <CommonReportKnowledge, T> > limitSelector, Func <MethodMetricsReport, bool> condition)
     where T : IComparable <T>
 {
     return(from method in metrics.Methods
            where condition(method)
            where metricSelector(method).CompareTo(limitSelector(RatingFunctions.Limits)(metrics.CommonKnowledge)) > 0
            select method);
 }
Exemplo n.º 14
0
 public static IEnumerable <TypeMetricsReport> TypesOverLimit <T>(this MetricsReport metrics, Func <TypeMetricsReport, T> metricSelector, Func <RatingFunctionLimits, Func <CommonReportKnowledge, T> > limitSelector, Func <TypeMetricsReport, bool> condition)
     where T : IComparable <T>
 {
     return(from type in metrics.Types
            where condition(type)
            where metricSelector(type).CompareTo(limitSelector(RatingFunctions.Limits)(metrics.CommonKnowledge)) > 0
            select type);
 }
 public static MethodAndTypeMetrics MethodOfLine(this MetricsReport metrics, LineLocation location)
 {
     if (metrics == null)
     {
         return(null);
     }
     return((metrics.GetMethodOfLine(location)).FirstOrDefault());
 }
Exemplo n.º 16
0
 public ScheduledReporter(MetricsReport report, MetricsDataProvider metricsDataProvider, Func<HealthStatus> healthStatus, TimeSpan interval, Scheduler scheduler)
 {
     this.report = report;
     this.metricsDataProvider = metricsDataProvider;
     this.healthStatus = healthStatus;
     this.scheduler = scheduler;
     this.scheduler.Start(interval, t => RunReport(t));
 }
Exemplo n.º 17
0
        /// <summary>
        /// Schedule a generic reporter to be executed at a fixed <paramref name="interval"/>
        /// </summary>
        /// <param name="report">Function that returns an instance of a reporter</param>
        /// <param name="interval">Interval at which to run the report.</param>
        /// <param name="filter">Only report metrics that match the filter.</param>
        public MetricsReports WithReport(MetricsReport report, TimeSpan interval, MetricsFilter filter = null)
        {
            var toleratedConsecutiveFailures = ReadToleratedFailuresConfig();
            var newReport = new ScheduledReporter(report, this.metricsDataProvider.WithFilter(filter), this.healthStatus, interval, new ActionScheduler(toleratedConsecutiveFailures));

            this.reports.Add(newReport);
            return(this);
        }
Exemplo n.º 18
0
        internal static MetricsReport Combine(this MetricsReport[] reports)
        {
            var report = MetricsReport.Of(reports);

            report.Remember.AssemblyAnalysisDone();
            report.PostProcess();
            report.Remember.PostProcessingDone();
            return(report);
        }
Exemplo n.º 19
0
 private static IEnumerable <T> MethodsNotGenerated <T>(this MetricsReport metrics, Func <MethodMetricsReport, T> selector)
 {
     return(from m in metrics.Methods
            where !m.CompilerGenerated
            where !m.OnlyDeclaration
            where m.CyclomaticComplexity > 0
            where m.MethodLength > 0
            select selector(m));
 }
Exemplo n.º 20
0
 private void InitializeStatistics(MetricsReport metrics)
 {
     AverageRatedCyclomaticComplexity          = RatedMethods.AverageAny(m => m.RatedCyclomaticComplexity, m => m.CyclomaticComplexity > 0);
     AverageRatedMethodLength                  = RatedMethods.AverageAny(m => m.RatedMethodLength, m => m.MethodLength > 0);
     AverageRatedClassSize                     = RatedTypes.AverageAny(m => m.RatedClassSize);
     AverageRatedNumberOfNonStaticPublicFields = RatedTypes.AverageAny(m => m.RatedNumberOfNonStaticPublicFields);
     AverageComponentDependency                = RatedTypes.AverageAny(m => m.CumulativeComponentDependency) / metrics.CommonKnowledge.NumberOfTypes;
     NamespacesWithCyclicDependencies          = (double)RatedNamespaces.CountAny(m => m.IsInCycle) / metrics.CommonKnowledge.NumberOfNamespaces;
 }
        private static void SetNamespacesWithCyclicDependencies(this MetricsReport metrics)
        {
            var cycles = CyclicDependencies.In(metrics.GraphOfNamespaces);

            foreach (var namespaceWithTypes in metrics.GraphOfNamespaces.Vertices)
            {
                metrics.AddNamespaceReport(namespaceWithTypes);
                namespaceWithTypes.Namespace.CyclicDependencies = CyclicDependencies.Of(namespaceWithTypes, cycles);
            }
        }
Exemplo n.º 22
0
        internal static MetricsReport MetricsReport(params TypeMetricsWithMethodMetrics[] typeMetrics)
        {
            var metricsReport = new MetricsReport();

            foreach (var typeMetric in typeMetrics)
            {
                metricsReport.AddTypeReport(TypeMetrics(typeMetric.Type, typeMetric.Methods));
            }
            return(metricsReport);
        }
Exemplo n.º 23
0
        public static MetricsReport MetricsReport(IEnumerable <TypeMetricsReport> typeMetrics)
        {
            var metricsReport = new MetricsReport();

            foreach (var typeMetric in typeMetrics)
            {
                metricsReport.AddTypeReport(TypeMetrics(typeMetric, Enumerable.Empty <MethodMetricsReport>()));
            }
            return(metricsReport);
        }
Exemplo n.º 24
0
        public static MetricsReport MetricsReport(IEnumerable <NamespaceMetricsReport> namespaceMetrics)
        {
            var metricsReport = new MetricsReport();

            foreach (var namespaceMetric in namespaceMetrics)
            {
                metricsReport.AddNamespaceReport(NamespaceMetrics(namespaceMetric, Enumerable.Empty <TypeMetricsReport>()));
            }
            return(metricsReport);
        }
Exemplo n.º 25
0
        public static MetricsReport MetricsReport(IEnumerable <MethodMetricsReport> methodMetrics)
        {
            var metricsReport = new MetricsReport();

            metricsReport.AddTypeReport(TypeMetrics(new TypeMetricsReport()
            {
                FullName = RandomName()
            }, methodMetrics));
            return(metricsReport);
        }
Exemplo n.º 26
0
        private static TypeMetricsReport GetTypeMetrics(this MetricsReport metrics, Type type)
        {
            var typeMetrics = metrics.ForType(type);

            if (typeMetrics != null)
            {
                return(typeMetrics);
            }
            throw new MetricsNotFoundException(type);
        }
Exemplo n.º 27
0
        private static MethodMetricsReport GetMethodMetrics(this MetricsReport metrics, MethodInfo method)
        {
            var methodMetrics = metrics.ForMethod(method);

            if (methodMetrics != null)
            {
                return(methodMetrics);
            }
            throw new MetricsNotFoundException(method);
        }
Exemplo n.º 28
0
        private static bool VerifyType <T>(this T expectation, Type type, MetricsReport metrics) where T : TypeExpectation
        {
            Debug.WriteLine("verify " + type.Name);
            var typeMetrics = metrics.GetTypeMetrics(type);

            if (expectation.Verify(typeMetrics))
            {
                return(true);
            }
            throw new VerificationException(type, expectation);
        }
Exemplo n.º 29
0
        private static bool VerifyMethod <T>(this T expectation, MethodInfo method, MetricsReport metrics) where T : MethodExpectation
        {
            Debug.WriteLine("verify " + method.Name);
            var methodMetrics = metrics.GetMethodMetrics(method);

            if (expectation.Verify(methodMetrics))
            {
                return(true);
            }
            throw new VerificationException(method, expectation);
        }
        public PerfCounterReporter(MetricsReport report, TimeSpan interval, ICounterSamplingConfiguration counterSamplingConfig)
        {
            _report = report;
            _counterSamplingConfig = counterSamplingConfig;

            _handler = new PdhPathHandler();
            _healthStatus = new HealthStatus();
            _timers = new ConcurrentDictionary<string, MetricInfo>();
            _currentMetrics = new Dictionary<string, MetricInfo>();

            _couunterReporters = new List<CounterReporter>();

            this._reportScheduler = new ActionScheduler();
            this._reportScheduler.Start(interval, t => RunReport(t));
            this._timerScheduler = new ActionScheduler();
            this._timerScheduler.Start(TimeSpan.FromSeconds(1), t => ReportMetrics());
        }
        public PerfCounterReporter(MetricsReport report, TimeSpan interval, ICounterSamplingConfiguration counterSamplingConfig)
        {
            _report = report;
            _counterSamplingConfig = counterSamplingConfig;

            _handler        = new PdhPathHandler();
            _healthStatus   = new HealthStatus();
            _timers         = new ConcurrentDictionary <string, MetricInfo>();
            _currentMetrics = new Dictionary <string, MetricInfo>();

            _couunterReporters = new List <CounterReporter>();

            this._reportScheduler = new ActionScheduler();
            this._reportScheduler.Start(interval, t => RunReport(t));
            this._timerScheduler = new ActionScheduler();
            this._timerScheduler.Start(TimeSpan.FromSeconds(1), t => ReportMetrics());
        }
Exemplo n.º 32
0
 public ScheduledReporter(MetricsReport reporter, MetricsDataProvider metricsDataProvider, Func<HealthStatus> healthStatus, TimeSpan interval)
     : this(reporter, metricsDataProvider, healthStatus, interval, new ActionScheduler()) { }
Exemplo n.º 33
0
 public ScheduledReporter(MetricsReport reporter, MetricsDataProvider metricsDataProvider, Func <HealthStatus> healthStatus, TimeSpan interval)
     : this(reporter, metricsDataProvider, healthStatus, interval, new ActionScheduler())
 {
 }
Exemplo n.º 34
0
 /// <summary>
 /// Schedule a generic reporter to be executed at a fixed <paramref name="interval"/>
 /// </summary>
 /// <param name="report">Function that returns an instance of a reporter</param>
 /// <param name="interval">Interval at which to run the report.</param>
 public MetricsReports WithReport(MetricsReport report, TimeSpan interval)
 {
     var newReport = new ScheduledReporter(report, this.metricsDataProvider, this.healthStatus, interval);
     this.reports.Add(newReport);
     return this;
 }