fixes for ZAM profiling, which didn't get fully integrated originally

This commit is contained in:
Vern Paxson 2022-02-03 08:59:39 -08:00
parent 94e71b738a
commit 16e9af137f
4 changed files with 27 additions and 2 deletions

View file

@ -193,7 +193,8 @@ static void print_analysis_help()
fprintf(stderr, " no-ZAM-opt omit low-level ZAM optimization\n"); 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-all optimize all scripts, even inlined ones\n");
fprintf(stderr, " optimize-AST optimize the (transformed) AST; implies xform\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, " report-recursive report on recursive functions and exit\n");
fprintf(stderr, " xform transform scripts to \"reduced\" form\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") ) else if ( util::streq(opt, "optimize-AST") )
a_o.activate = a_o.optimize_AST = true; a_o.activate = a_o.optimize_AST = true;
else if ( util::streq(opt, "profile-ZAM") ) 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++") ) else if ( util::streq(opt, "report-C++") )
a_o.report_CPP = true; a_o.report_CPP = true;
else if ( util::streq(opt, "report-recursive") ) else if ( util::streq(opt, "report-recursive") )

View file

@ -578,4 +578,23 @@ void analyze_scripts()
analyze_scripts_for_ZAM(pfs); 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<ZBody>(f.Body())->ProfileExecution();
}
}
}
void finish_script_execution()
{
profile_script_execution();
}
} // namespace zeek::detail } // namespace zeek::detail

View file

@ -185,6 +185,9 @@ extern bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body);
// Analyze all of the parsed scripts collectively for optimization. // Analyze all of the parsed scripts collectively for optimization.
extern void analyze_scripts(); 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 // Used for C++-compiled scripts to signal their presence, by setting this
// to a non-empty value. // to a non-empty value.
extern void (*CPP_init_hook)(); extern void (*CPP_init_hook)();

View file

@ -324,6 +324,8 @@ static void terminate_bro()
plugin_mgr->FinishPlugins(); plugin_mgr->FinishPlugins();
finish_script_execution();
delete zeekygen_mgr; delete zeekygen_mgr;
delete packet_mgr; delete packet_mgr;
delete analyzer_mgr; delete analyzer_mgr;