diff --git a/src/Options.cc b/src/Options.cc index 9ddeed5b0c..ccc9ddae5e 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -193,7 +193,8 @@ static void print_analysis_help() fprintf(stderr, " no-ZAM-opt omit low-level ZAM optimization\n"); fprintf(stderr, " optimize-all optimize all scripts, even inlined ones\n"); fprintf(stderr, " optimize-AST optimize the (transformed) AST; implies xform\n"); - fprintf(stderr, " profile-ZAM generate to stdout a ZAM execution profile\n"); + fprintf(stderr, + " profile-ZAM generate to stdout a ZAM execution profile; implies -O ZAM\n"); fprintf(stderr, " report-recursive report on recursive functions and exit\n"); fprintf(stderr, " xform transform scripts to \"reduced\" form\n"); @@ -248,7 +249,7 @@ static void set_analysis_option(const char* opt, Options& opts) else if ( util::streq(opt, "optimize-AST") ) a_o.activate = a_o.optimize_AST = true; else if ( util::streq(opt, "profile-ZAM") ) - a_o.activate = a_o.profile_ZAM = true; + a_o.activate = a_o.gen_ZAM_code = a_o.profile_ZAM = true; else if ( util::streq(opt, "report-C++") ) a_o.report_CPP = true; else if ( util::streq(opt, "report-recursive") ) diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 05ef655016..94f711da6c 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -578,4 +578,23 @@ void analyze_scripts() analyze_scripts_for_ZAM(pfs); } +void profile_script_execution() + { + if ( analysis_options.profile_ZAM ) + { + report_ZOP_profile(); + + for ( auto& f : funcs ) + { + if ( f.Body()->Tag() == STMT_ZAM ) + cast_intrusive(f.Body())->ProfileExecution(); + } + } + } + +void finish_script_execution() + { + profile_script_execution(); + } + } // namespace zeek::detail diff --git a/src/script_opt/ScriptOpt.h b/src/script_opt/ScriptOpt.h index dba9a41187..95d7889d7e 100644 --- a/src/script_opt/ScriptOpt.h +++ b/src/script_opt/ScriptOpt.h @@ -185,6 +185,9 @@ extern bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body); // Analyze all of the parsed scripts collectively for optimization. extern void analyze_scripts(); +// Called when Zeek is terminating. +extern void finish_script_execution(); + // Used for C++-compiled scripts to signal their presence, by setting this // to a non-empty value. extern void (*CPP_init_hook)(); diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index c0786f29fd..968bac26f3 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -324,6 +324,8 @@ static void terminate_bro() plugin_mgr->FinishPlugins(); + finish_script_execution(); + delete zeekygen_mgr; delete packet_mgr; delete analyzer_mgr;