1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2012 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # General statistics on a model
21 private import metrics_base
23 # Print general statistics on a model
24 fun compute_statistics
(model
: Model)
26 print
"--- Statistics of the model ---"
27 var nbmod
= model
.mmodules
.length
28 print
"Number of modules: {nbmod}"
32 var nbcla
= model
.mclasses
.length
33 var nbcladef
= model
.mclassdef_hierarchy
.length
34 print
"Number of classes: {nbcla}"
36 # determine the distribution of:
37 # * class kinds (interface, abstract class, etc.)
38 # * refinex classes (vs. unrefined ones)
39 var kinds
= new Counter[MClassKind]
41 for c
in model
.mclasses
do
43 if c
.mclassdefs
.length
> 1 then
47 for k
in kinds
.sort
do
49 print
" Number of {k} kind: {v} ({div(v*100,nbcla)}%)"
55 print
"Number of class definitions: {nbcladef}"
56 print
"Number of refined classes: {refined} ({div(refined*100,nbcla)}%)"
57 print
"Average number of class refinments by classes: {div(nbcladef-nbcla,nbcla)}"
58 print
"Average number of class refinments by refined classes: {div(nbcladef-nbcla,refined)}"
62 var nbprop
= model
.mproperties
.length
65 print
"Number of properties: {model.mproperties.length}"
66 var pkinds
= new Counter[String]
67 for p
in model
.mproperties
do
68 nbpropdef
+= p
.mpropdefs
.length
69 if p
.mpropdefs
.length
> 1 then
72 pkinds
.inc
(p
.class_name
)
74 for k
in pkinds
.sort
do
76 print
" Number of {k}: {v} ({div(v*100,nbprop)}%)"
81 print
"Number of property definitions: {nbpropdef}"
82 print
"Number of redefined properties: {redefined} ({div(redefined*100,nbprop)}%)"
83 print
"Average number of property redefinitions by property: {div(nbpropdef-nbprop,nbprop)}"
84 print
"Average number of property redefinitions by redefined property: {div(nbpropdef-nbprop,redefined)}"
87 # Print class tables statistics for the classes of the program main
88 fun compute_tables
(main
: MModule)
90 var model
= main
.model
92 var nc
= 0 # Number of runtime classes
93 var nl
= 0 # Number of usages of class definitions (a class definition can be used more than once)
94 var nhp
= 0 # Number of usages of properties (a property can be used more than once)
95 var npas
= 0 # Number of usages of properties without lookup (easy easy case, easier that CHA)
97 # Collect the full class hierarchy
98 var hier
= main
.flatten_mclass_hierarchy
100 # Skip classes without direct instances
101 if c
.kind
== interface_kind
or c
.kind
== abstract_kind
then continue
105 # Now, we need to collect all properties defined/inherited/imported
106 # So, visit all definitions of all super-classes
107 for sup
in hier
[c
].greaters
do
108 for cd
in sup
.mclassdefs
do
111 # Now, search properties introduced
112 for p
in cd
.intro_mproperties
do
115 # Select property definition
116 if p
.mpropdefs
.length
== 1 then
119 var sels
= p
.lookup_definitions
(main
, c
.mclassdefs
.first
.bound_mtype
)
120 if sels
.length
> 1 then
121 print
"conflict for {p.full_name} in class {c.full_name}: {sels.join(", ")}"
122 else if sels
.is_empty
then
123 print
"ERROR: no property for {p.full_name} in class {c.full_name}!"
131 print
"--- Construction of tables ---"
132 print
"Number of runtime classes: {nc} (excluding interfaces and abstract classes)"
133 print
"Average number of composing class definition by runtime class: {div(nl,nc)}"
134 print
"Total size of tables (classes and instances): {nhp} (not including stuff like info for subtyping or call-next-method)"
135 print
"Average size of table by runtime class: {div(nhp,nc)}"
136 print
"Values never redefined: {npas} ({div(npas*100,nhp)}%)"