nitmetrics: extract tables metrics from model_metrics to tables_metrics
authorAlexandre Terrasa <alexadre@moz-code.org>
Sun, 4 Nov 2012 20:02:03 +0000 (15:02 -0500)
committerJean Privat <jean@pryen.org>
Mon, 5 Nov 2012 19:17:53 +0000 (14:17 -0500)
Signed-off-by: Alexandre Terrasa <alexadre@moz-code.org>

src/metrics/metrics.nit
src/metrics/model_stats.nit
src/metrics/tables_metrics.nit [new file with mode: 0644]
src/nitmetrics.nit

index 159368a..507c67b 100644 (file)
@@ -25,3 +25,4 @@ import model_stats
 import generate_hierarchies
 import rta_stats
 import model_hyperdoc
+import tables_metrics
index b12cc2d..3ee2323 100644 (file)
@@ -83,55 +83,3 @@ do
        print "Average number of property redefinitions by property: {div(nbpropdef-nbprop,nbprop)}"
        print "Average number of property redefinitions by redefined property: {div(nbpropdef-nbprop,redefined)}"
 end
-
-# Print class tables statistics for the classes of the program main
-fun compute_tables(main: MModule)
-do
-       var model = main.model
-
-       var nc = 0 # Number of runtime classes
-       var nl = 0 # Number of usages of class definitions (a class definition can be used more than once)
-       var nhp = 0 # Number of usages of properties (a property can be used more than once)
-       var npas = 0 # Number of usages of properties without lookup (easy easy case, easier that CHA)
-
-       # Collect the full class hierarchy
-       var hier = main.flatten_mclass_hierarchy
-       for c in hier do
-               # Skip classes without direct instances
-               if c.kind == interface_kind or c.kind == abstract_kind then continue
-
-               nc += 1
-
-               # Now, we need to collect all properties defined/inherited/imported
-               # So, visit all definitions of all super-classes
-               for sup in hier[c].greaters do
-                       for cd in sup.mclassdefs do
-                               nl += 1
-
-                               # Now, search properties introduced
-                               for p in cd.intro_mproperties do
-
-                                       nhp += 1
-                                       # Select property definition
-                                       if p.mpropdefs.length == 1 then
-                                               npas += 1
-                                       else
-                                               var sels = p.lookup_definitions(main, c.mclassdefs.first.bound_mtype)
-                                               if sels.length > 1 then
-                                                       print "conflict for {p.full_name} in class {c.full_name}: {sels.join(", ")}"
-                                               else if sels.is_empty then
-                                                       print "ERROR: no property for {p.full_name} in class {c.full_name}!"
-                                               end
-                                       end
-                               end
-                       end
-               end
-       end
-
-       print "--- Construction of tables ---"
-       print "Number of runtime classes: {nc} (excluding interfaces and abstract classes)"
-       print "Average number of composing class definition by runtime class: {div(nl,nc)}"
-       print "Total size of tables (classes and instances): {nhp} (not including stuff like info for subtyping or call-next-method)"
-       print "Average size of table by runtime class: {div(nhp,nc)}"
-       print "Values never redefined: {npas} ({div(npas*100,nhp)}%)"
-end
diff --git a/src/metrics/tables_metrics.nit b/src/metrics/tables_metrics.nit
new file mode 100644 (file)
index 0000000..1c3ce7c
--- /dev/null
@@ -0,0 +1,73 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2012 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Metrics on table generation
+module tables_metrics
+
+import model
+private import metrics_base
+
+# Print class tables statistics for the classes of the program main
+fun compute_tables_metrics(main: MModule)
+do
+       var model = main.model
+
+       var nc = 0 # Number of runtime classes
+       var nl = 0 # Number of usages of class definitions (a class definition can be used more than once)
+       var nhp = 0 # Number of usages of properties (a property can be used more than once)
+       var npas = 0 # Number of usages of properties without lookup (easy easy case, easier that CHA)
+
+       # Collect the full class hierarchy
+       var hier = main.flatten_mclass_hierarchy
+       for c in hier do
+               # Skip classes without direct instances
+               if c.kind == interface_kind or c.kind == abstract_kind then continue
+
+               nc += 1
+
+               # Now, we need to collect all properties defined/inherited/imported
+               # So, visit all definitions of all super-classes
+               for sup in hier[c].greaters do
+                       for cd in sup.mclassdefs do
+                               nl += 1
+
+                               # Now, search properties introduced
+                               for p in cd.intro_mproperties do
+
+                                       nhp += 1
+                                       # Select property definition
+                                       if p.mpropdefs.length == 1 then
+                                               npas += 1
+                                       else
+                                               var sels = p.lookup_definitions(main, c.mclassdefs.first.bound_mtype)
+                                               if sels.length > 1 then
+                                                       print "conflict for {p.full_name} in class {c.full_name}: {sels.join(", ")}"
+                                               else if sels.is_empty then
+                                                       print "ERROR: no property for {p.full_name} in class {c.full_name}!"
+                                               end
+                                       end
+                               end
+                       end
+               end
+       end
+
+       print "--- Construction of tables ---"
+       print "Number of runtime classes: {nc} (excluding interfaces and abstract classes)"
+       print "Average number of composing class definition by runtime class: {div(nl,nc)}"
+       print "Total size of tables (classes and instances): {nhp} (not including stuff like info for subtyping or call-next-method)"
+       print "Average size of table by runtime class: {div(nhp,nc)}"
+       print "Values never redefined: {npas} ({div(npas*100,nhp)}%)"
+end
index 1b2ebd1..202d497 100644 (file)
@@ -74,7 +74,7 @@ generate_class_hierarchy(toolcontext, mainmodule)
 generate_model_hyperdoc(toolcontext, model)
 
 print ""
-compute_tables(mainmodule)
+compute_tables_metrics(mainmodule)
 
 print ""
 compute_rta_stats(modelbuilder, mainmodule)