X-Git-Url: http://nitlanguage.org diff --git a/src/metrics/mmodules_metrics.nit b/src/metrics/mmodules_metrics.nit index 4af3424..6381726 100644 --- a/src/metrics/mmodules_metrics.nit +++ b/src/metrics/mmodules_metrics.nit @@ -32,10 +32,13 @@ private class MModulesMetricsPhase redef fun process_mainmodule(mainmodule) do if not toolcontext.opt_mmodules.value and not toolcontext.opt_all.value then return + var csv = toolcontext.opt_csv.value + var out = "{toolcontext.opt_dir.value or else "metrics"}/mmodules" + out.mkdir print toolcontext.format_h1("\n# MModules metrics") - var metrics = new MModuleMetricSet + var metrics = new MetricSet metrics.register(new MNOA, new MNOP, new MNOC, new MNOD, new MDIT) metrics.register(new MNBI, new MNBR, new MNBCC, new MNBAC, new MNBIC) @@ -44,62 +47,30 @@ private class MModulesMetricsPhase for mproject in model.mprojects do print toolcontext.format_h2("\n ## project {mproject}") - for mgroup in mproject.mgroups do if mgroup.mmodules.is_empty then continue # Scalar metrics print toolcontext.format_h3(" `- group {mgroup.full_name}") - mmodules.add_all(mgroup.mmodules) - metrics.collect(new HashSet[MModule].from(mgroup.mmodules), mainmodule) - for name, metric in metrics.metrics do - if metric isa IntMetric then - print toolcontext.format_h4("\t{name}: {metric.desc}") - print toolcontext.format_p("\t avg: {metric.avg}") - var max = metric.max - print toolcontext.format_p("\t max: {max.first} ({max.second})") - var min = metric.min - print toolcontext.format_p("\t min: {min.first} ({min.second})") - end - end + metrics.collect(new HashSet[MModule].from(mgroup.mmodules)) + metrics.to_console(1, not toolcontext.opt_nocolors.value) + if csv then metrics.to_csv.save("{out}/{mgroup}.csv") end end if not mmodules.is_empty then # Global metrics print toolcontext.format_h2("\n ## global metrics") - - metrics.collect(mmodules, mainmodule) - for name, metric in metrics.metrics do - if metric isa IntMetric then - print toolcontext.format_h4( "\t{name}: {metric.desc}") - print toolcontext.format_p("\t avg: {metric.avg}") - var max = metric.max - print toolcontext.format_p("\t max: {max.first} ({max.second})") - var min = metric.min - print toolcontext.format_p("\t min: {min.first} ({min.second})") - end - end - end - end -end - -# A MetricSet for metrics about MModules -class MModuleMetricSet - super MetricSet - redef type METRIC: MModuleMetric - - # Collect all the metrics on the set of MModules - fun collect(mmodules: Set[MModule], mainmodule: MModule) do - clear - for metric in metrics.values do - metric.collect(mmodules) + metrics.clear + metrics.collect(mmodules) + metrics.to_console(1, not toolcontext.opt_nocolors.value) + if csv then metrics.to_csv.save("{out}/summary.csv") end end end -# An abstract Metric on MModules -abstract class MModuleMetric +# A metric about MModule +interface MModuleMetric super Metric redef type ELM: MModule end