nitc: add option --count-isset-checks to count all compiled isset checks on non-nulla...
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 25 Mar 2014 19:43:15 +0000 (15:43 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 28 Apr 2014 13:46:22 +0000 (09:46 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/abstract_compiler.nit
src/separate_compiler.nit

index dae3d88..c9fe617 100644 (file)
@@ -54,6 +54,8 @@ redef class ToolContext
        var opt_typing_test_metrics: OptionBool = new OptionBool("Enable static and dynamic count of all type tests", "--typing-test-metrics")
        # --invocation-metrics
        var opt_invocation_metrics: OptionBool = new OptionBool("Enable static and dynamic count of all method invocations", "--invocation-metrics")
+       # --isset-checks-metrics
+       var opt_isset_checks_metrics: OptionBool = new OptionBool("Enable static and dynamic count of isset checks before attributes access", "--isset-checks-metrics")
        # --stacktrace
        var opt_stacktrace: OptionString = new OptionString("Control the generation of stack traces", "--stacktrace")
        # --no-gcc-directives
@@ -64,7 +66,7 @@ redef class ToolContext
                super
                self.option_context.add_option(self.opt_output, self.opt_no_cc, self.opt_make_flags, self.opt_compile_dir, self.opt_hardening, self.opt_no_shortcut_range)
                self.option_context.add_option(self.opt_no_check_covariance, self.opt_no_check_attr_isset, self.opt_no_check_assert, self.opt_no_check_autocast, self.opt_no_check_other)
-               self.option_context.add_option(self.opt_typing_test_metrics, self.opt_invocation_metrics)
+               self.option_context.add_option(self.opt_typing_test_metrics, self.opt_invocation_metrics, self.opt_isset_checks_metrics)
                self.option_context.add_option(self.opt_stacktrace)
                self.option_context.add_option(self.opt_no_gcc_directive)
        end
@@ -574,6 +576,13 @@ abstract class AbstractCompiler
                        v.compiler.header.add_decl("extern long count_invoke_by_inline;")
                end
 
+               if self.modelbuilder.toolcontext.opt_isset_checks_metrics.value then
+                       v.add_decl("long count_attr_reads = 0;")
+                       v.add_decl("long count_isset_checks = 0;")
+                       v.compiler.header.add_decl("extern long count_attr_reads;")
+                       v.compiler.header.add_decl("extern long count_isset_checks;")
+               end
+
                v.add_decl("void sig_handler(int signo)\{")
                v.add_decl("printf(\"Caught signal : %s\\n\", strsignal(signo));")
                v.add_decl("show_backtrace(signo);")
@@ -673,6 +682,12 @@ abstract class AbstractCompiler
                        v.add("printf(\"direct:   %ld (%.2f%%)\\n\", count_invoke_by_direct, 100.0*count_invoke_by_direct/count_invoke_total);")
                        v.add("printf(\"inlined:  %ld (%.2f%%)\\n\", count_invoke_by_inline, 100.0*count_invoke_by_inline/count_invoke_total);")
                end
+
+               if self.modelbuilder.toolcontext.opt_isset_checks_metrics.value then
+                       v.add("printf(\"# dynamic attribute reads: %ld\\n\", count_attr_reads);")
+                       v.add("printf(\"# dynamic isset checks: %ld\\n\", count_isset_checks);")
+               end
+
                v.add("return 0;")
                v.add("\}")
        end
index 4bbdd2d..bcd1deb 100644 (file)
@@ -877,7 +877,9 @@ class SeparateCompiler
                if self.modelbuilder.toolcontext.opt_tables_metrics.value then
                        display_sizes
                end
-
+               if self.modelbuilder.toolcontext.opt_isset_checks_metrics.value then
+                       display_isset_checks
+               end
                var tc = self.modelbuilder.toolcontext
                tc.info("# implementation of method invocation",2)
                var nb_invok_total = modelbuilder.nb_invok_by_tables + modelbuilder.nb_invok_by_direct + modelbuilder.nb_invok_by_inline
@@ -930,6 +932,16 @@ class SeparateCompiler
                print "\t{total}\t{holes}"
        end
 
+       protected var isset_checks_count = 0
+       protected var attr_read_count = 0
+
+       fun display_isset_checks do
+               print "# total number of compiled attribute reads"
+               print "\t{attr_read_count}"
+               print "# total number of compiled isset-checks"
+               print "\t{isset_checks_count}"
+       end
+
        redef fun compile_nitni_structs
        do
                self.header.add_decl("struct nitni_instance \{struct instance *value;\};")
@@ -1293,6 +1305,11 @@ class SeparateCompilerVisitor
                var intromclassdef = a.intro.mclassdef
                ret = ret.resolve_for(intromclassdef.bound_mtype, intromclassdef.bound_mtype, intromclassdef.mmodule, true)
 
+               if self.compiler.modelbuilder.toolcontext.opt_isset_checks_metrics.value then
+                       self.compiler.attr_read_count += 1
+                       self.add("count_attr_reads++;")
+               end
+
                self.require_declaration(a.const_color)
                if self.compiler.modelbuilder.toolcontext.opt_no_union_attribute.value then
                        # Get the attribute or a box (ie. always a val*)
@@ -1307,6 +1324,11 @@ class SeparateCompilerVisitor
                                self.add("if (unlikely({res} == NULL)) \{")
                                self.add_abort("Uninitialized attribute {a.name}")
                                self.add("\}")
+
+                               if self.compiler.modelbuilder.toolcontext.opt_isset_checks_metrics.value then
+                                       self.compiler.isset_checks_count += 1
+                                       self.add("count_isset_checks++;")
+                               end
                        end
 
                        # Return the attribute or its unboxed version
@@ -1321,6 +1343,10 @@ class SeparateCompilerVisitor
                                self.add("if (unlikely({res} == NULL)) \{")
                                self.add_abort("Uninitialized attribute {a.name}")
                                self.add("\}")
+                               if self.compiler.modelbuilder.toolcontext.opt_isset_checks_metrics.value then
+                                       self.compiler.isset_checks_count += 1
+                                       self.add("count_isset_checks++;")
+                               end
                        end
 
                        return res