src: use `as_notnullable` in code
[nit.git] / src / metrics / rta_metrics.nit
index d274207..1224513 100644 (file)
@@ -25,12 +25,12 @@ import mclasses_metrics
 import frontend
 
 redef class ToolContext
-       var rta_metrics_phase = new RTAMetricsPhase(self, null)
+       var rta_metrics_phase: Phase = new RTAMetricsPhase(self, null)
 end
 
 private class RTAMetricsPhase
        super Phase
-       redef fun process_mainmodule(mainmodule)
+       redef fun process_mainmodule(mainmodule, given_mmodules)
        do
                if not toolcontext.opt_rta.value and not toolcontext.opt_all.value then return
                var csv = toolcontext.opt_csv.value
@@ -80,14 +80,39 @@ private class RTAMetricsPhase
                gmetrics.to_console(1, not toolcontext.opt_nocolors.value)
                if csv then gmetrics.to_csv.save("{out}/complexity.csv")
 
+               callsite_info(analysis)
+
                # dump type and method infos
                if csv then
                        analysis.live_types_to_csv.save("{out}/rta_types.csv")
+                       analysis.live_methods_to_tree.write_to_file("{out}/rta_methods.dat")
+               end
+       end
 
-                       var s = new OFStream.open("{out}/rta_methods.dat")
-                       analysis.live_methods_to_tree.pretty(s)
-                       s.close
+       fun callsite_info(rta: RapidTypeAnalysis)
+       do
+               print toolcontext.format_h2("\n ## Callsites")
+               print "* {rta.live_callsites.length} live callsites"
+
+               var csep = new Counter[MPropDef]
+               var cglo = new Counter[MPropDef]
+               var morphisme = new Counter[Int]
+               for cs in rta.live_callsites do
+                       csep.inc(cs.mpropdef)
+                       var targets = rta.live_targets(cs)
+                       for d in targets do
+                               cglo.inc(d)
+                       end
+                       morphisme.inc(targets.length)
                end
+
+               print toolcontext.format_h3("MMethodDef locally designated (by number of CallSites)")
+               csep.print_summary
+               csep.print_elements(5)
+
+               print toolcontext.format_h3("MMethodDef possibly invoked at runtime (by number of CallSites)")
+               cglo.print_summary
+               cglo.print_elements(5)
        end
 end
 
@@ -351,7 +376,7 @@ redef class RapidTypeAnalysis
                super
                tnlc.values.inc(mtype)
 
-               if mtype isa MNullableType then mtype = mtype.mtype
+               mtype = mtype.as_notnullable
                if mtype isa MClassType then
                        cnlc.values.inc(mtype.mclass)
                end
@@ -362,8 +387,7 @@ end
 
 redef class MType
        private fun signature_depth: Int do
-               var mtype = self
-               if mtype isa MNullableType then mtype = mtype.mtype
+               var mtype = self.as_notnullable
                if not mtype isa MGenericType then return 0
 
                var depth = 0