mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
allow profiling without updating of hash values
This commit is contained in:
parent
3962810e4b
commit
d2c6208421
3 changed files with 30 additions and 19 deletions
|
@ -546,7 +546,9 @@ void ProfileFunc::CheckRecordConstructor(TypePtr t) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileFuncs::ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred, bool _full_record_hashes) {
|
ProfileFuncs::ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred, bool _compute_func_hashes,
|
||||||
|
bool _full_record_hashes) {
|
||||||
|
compute_func_hashes = _compute_func_hashes;
|
||||||
full_record_hashes = _full_record_hashes;
|
full_record_hashes = _full_record_hashes;
|
||||||
|
|
||||||
for ( auto& f : funcs ) {
|
for ( auto& f : funcs ) {
|
||||||
|
@ -558,6 +560,11 @@ ProfileFuncs::ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred
|
||||||
// Track the profile even if we're not compiling the function, since
|
// Track the profile even if we're not compiling the function, since
|
||||||
// the AST optimizer will still need it to reason about function-call
|
// the AST optimizer will still need it to reason about function-call
|
||||||
// side effects.
|
// side effects.
|
||||||
|
|
||||||
|
// Propagate previous hash if requested.
|
||||||
|
if ( ! compute_func_hashes && f.Profile() )
|
||||||
|
pf->SetHashVal(f.Profile()->HashVal());
|
||||||
|
|
||||||
f.SetProfile(std::move(pf));
|
f.SetProfile(std::move(pf));
|
||||||
func_profs[f.Func()] = f.ProfilePtr();
|
func_profs[f.Func()] = f.ProfilePtr();
|
||||||
}
|
}
|
||||||
|
@ -805,15 +812,18 @@ void ProfileFuncs::ComputeTypeHashes(const std::vector<const Type*>& types) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileFuncs::ComputeBodyHashes(std::vector<FuncInfo>& funcs) {
|
void ProfileFuncs::ComputeBodyHashes(std::vector<FuncInfo>& funcs) {
|
||||||
for ( auto& f : funcs )
|
if ( compute_func_hashes )
|
||||||
if ( ! f.ShouldSkip() )
|
for ( auto& f : funcs )
|
||||||
ComputeProfileHash(f.ProfilePtr());
|
if ( ! f.ShouldSkip() )
|
||||||
|
ComputeProfileHash(f.ProfilePtr());
|
||||||
|
|
||||||
for ( auto& l : lambdas ) {
|
for ( auto& l : lambdas ) {
|
||||||
auto pf = ExprProf(l);
|
auto pf = ExprProf(l);
|
||||||
func_profs[l->PrimaryFunc().get()] = pf;
|
func_profs[l->PrimaryFunc().get()] = pf;
|
||||||
lambda_primaries[l->Name()] = l->PrimaryFunc().get();
|
lambda_primaries[l->Name()] = l->PrimaryFunc().get();
|
||||||
ComputeProfileHash(pf);
|
|
||||||
|
if ( compute_func_hashes )
|
||||||
|
ComputeProfileHash(pf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -347,13 +347,15 @@ using is_compilable_pred = bool (*)(const ProfileFunc*, const char** reason);
|
||||||
// Collectively profile an entire collection of functions.
|
// Collectively profile an entire collection of functions.
|
||||||
class ProfileFuncs {
|
class ProfileFuncs {
|
||||||
public:
|
public:
|
||||||
// Updates entries in "funcs" to include profiles. If pred is
|
// Updates entries in "funcs" to include profiles. If pred is non-nil,
|
||||||
// non-nil, then it is called for each profile to see whether it's
|
// then it is called for each profile to see whether it's compilable,
|
||||||
// compilable, and, if not, the FuncInfo is marked as ShouldSkip().
|
// and, if not, the FuncInfo is marked as ShouldSkip().
|
||||||
// "full_record_hashes" controls whether the hashes for extended
|
// "compute_func_hashes" governs whether we compute hashes for the
|
||||||
// records covers their final, full form, or should only their
|
// FuncInfo entries, or keep their existing ones. "full_record_hashes"
|
||||||
// original fields.
|
// controls whether the hashes for extended records covers their final,
|
||||||
ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred, bool full_record_hashes);
|
// full form, or should only their original fields.
|
||||||
|
ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred, bool compute_func_hashes,
|
||||||
|
bool full_record_hashes);
|
||||||
|
|
||||||
// The following accessors provide a global profile across all of
|
// The following accessors provide a global profile across all of
|
||||||
// the (non-skipped) functions in "funcs". See the comments for
|
// the (non-skipped) functions in "funcs". See the comments for
|
||||||
|
@ -604,6 +606,9 @@ protected:
|
||||||
// These can arise for example due to lambdas or record attributes.
|
// These can arise for example due to lambdas or record attributes.
|
||||||
std::vector<const Expr*> pending_exprs;
|
std::vector<const Expr*> pending_exprs;
|
||||||
|
|
||||||
|
// Whether to compute new hashes for the FuncInfo entries.
|
||||||
|
bool compute_func_hashes;
|
||||||
|
|
||||||
// Whether the hashes for extended records should cover their final,
|
// Whether the hashes for extended records should cover their final,
|
||||||
// full form, or only their original fields.
|
// full form, or only their original fields.
|
||||||
bool full_record_hashes;
|
bool full_record_hashes;
|
||||||
|
|
|
@ -391,7 +391,7 @@ static void use_CPP() {
|
||||||
|
|
||||||
int num_used = 0;
|
int num_used = 0;
|
||||||
|
|
||||||
auto pfs = std::make_unique<ProfileFuncs>(funcs, is_CPP_compilable, false);
|
auto pfs = std::make_unique<ProfileFuncs>(funcs, is_CPP_compilable, true, false);
|
||||||
|
|
||||||
for ( auto& f : funcs ) {
|
for ( auto& f : funcs ) {
|
||||||
auto hash = f.Profile()->HashVal();
|
auto hash = f.Profile()->HashVal();
|
||||||
|
@ -435,18 +435,16 @@ static void use_CPP() {
|
||||||
reporter->FatalError("no C++ functions found to use");
|
reporter->FatalError("no C++ functions found to use");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void generate_CPP() {
|
static void generate_CPP(std::shared_ptr<ProfileFuncs> pfs) {
|
||||||
const auto gen_name = CPP_dir + "CPP-gen.cc";
|
const auto gen_name = CPP_dir + "CPP-gen.cc";
|
||||||
|
|
||||||
const bool standalone = analysis_options.gen_standalone_CPP;
|
const bool standalone = analysis_options.gen_standalone_CPP;
|
||||||
const bool report = analysis_options.report_uncompilable;
|
const bool report = analysis_options.report_uncompilable;
|
||||||
|
|
||||||
auto pfs = std::make_shared<ProfileFuncs>(funcs, is_CPP_compilable, false);
|
|
||||||
|
|
||||||
CPPCompile cpp(funcs, pfs, gen_name, standalone, report);
|
CPPCompile cpp(funcs, pfs, gen_name, standalone, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void analyze_scripts_for_ZAM() {
|
static void analyze_scripts_for_ZAM(std::shared_ptr<ProfileFuncs> pfs) {
|
||||||
if ( analysis_options.usage_issues > 0 && analysis_options.optimize_AST ) {
|
if ( analysis_options.usage_issues > 0 && analysis_options.optimize_AST ) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"warning: \"-O optimize-AST\" option is incompatible with -u option, "
|
"warning: \"-O optimize-AST\" option is incompatible with -u option, "
|
||||||
|
@ -454,8 +452,6 @@ static void analyze_scripts_for_ZAM() {
|
||||||
analysis_options.optimize_AST = false;
|
analysis_options.optimize_AST = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pfs = std::make_shared<ProfileFuncs>(funcs, nullptr, true);
|
|
||||||
|
|
||||||
if ( analysis_options.profile_ZAM ) {
|
if ( analysis_options.profile_ZAM ) {
|
||||||
#ifdef ENABLE_ZAM_PROFILE
|
#ifdef ENABLE_ZAM_PROFILE
|
||||||
AST_blocks = std::make_unique<ASTBlockAnalyzer>(funcs);
|
AST_blocks = std::make_unique<ASTBlockAnalyzer>(funcs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue