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
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
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);")
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
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
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;\};")
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*)
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
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