mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Tweak FuncInfo memory management
Idea being for everything to be automatically released when process exits just so there's less potential noise from leak profilers.
This commit is contained in:
parent
c7bec09e14
commit
7b2ee2514e
4 changed files with 30 additions and 37 deletions
|
@ -24,13 +24,13 @@ void Inliner::Analyze()
|
||||||
std::unordered_set<const Func*> cs;
|
std::unordered_set<const Func*> cs;
|
||||||
|
|
||||||
// Aspirational ....
|
// Aspirational ....
|
||||||
non_recursive_funcs.insert(f->Func());
|
non_recursive_funcs.insert(f.Func());
|
||||||
|
|
||||||
for ( auto& func : f->Profile()->ScriptCalls() )
|
for ( auto& func : f.Profile()->ScriptCalls() )
|
||||||
{
|
{
|
||||||
cs.insert(func);
|
cs.insert(func);
|
||||||
|
|
||||||
if ( func == f->Func() )
|
if ( func == f.Func() )
|
||||||
{
|
{
|
||||||
if ( report_recursive )
|
if ( report_recursive )
|
||||||
printf("%s is directly recursive\n",
|
printf("%s is directly recursive\n",
|
||||||
|
@ -40,7 +40,7 @@ void Inliner::Analyze()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
call_set[f->Func()] = cs;
|
call_set[f.Func()] = cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transitive closure. If we had any self-respect, we'd implement
|
// Transitive closure. If we had any self-respect, we'd implement
|
||||||
|
@ -118,11 +118,11 @@ void Inliner::Analyze()
|
||||||
// sizes for them correctly, and more fundamentally since
|
// sizes for them correctly, and more fundamentally since
|
||||||
// we don't compile them and hence inlining them will
|
// we don't compile them and hence inlining them will
|
||||||
// make the parent non-compilable.
|
// make the parent non-compilable.
|
||||||
if ( f->Func()->Flavor() == FUNC_FLAVOR_FUNCTION &&
|
if ( f.Func()->Flavor() == FUNC_FLAVOR_FUNCTION &&
|
||||||
non_recursive_funcs.count(f->Func()) > 0 &&
|
non_recursive_funcs.count(f.Func()) > 0 &&
|
||||||
f->Profile()->NumLambdas() == 0 &&
|
f.Profile()->NumLambdas() == 0 &&
|
||||||
f->Profile()->NumWhenStmts() == 0 )
|
f.Profile()->NumWhenStmts() == 0 )
|
||||||
inline_ables.insert(f->Func());
|
inline_ables.insert(f.Func());
|
||||||
|
|
||||||
for ( auto& f : funcs )
|
for ( auto& f : funcs )
|
||||||
{
|
{
|
||||||
|
@ -134,8 +134,8 @@ void Inliner::Analyze()
|
||||||
// circumstances in which a Zeek function can be called
|
// circumstances in which a Zeek function can be called
|
||||||
// not ultimately stemming from an event (such as global
|
// not ultimately stemming from an event (such as global
|
||||||
// scripting, or expiration functions).
|
// scripting, or expiration functions).
|
||||||
if ( inline_ables.count(f->Func()) == 0 )
|
if ( inline_ables.count(f.Func()) == 0 )
|
||||||
InlineFunction(f);
|
InlineFunction(&f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
// First argument is a collection of information about *all* of
|
// First argument is a collection of information about *all* of
|
||||||
// the script functions. Second argument states whether to report
|
// the script functions. Second argument states whether to report
|
||||||
// recursive functions (of interest as they're not in-lineable).
|
// recursive functions (of interest as they're not in-lineable).
|
||||||
Inliner(std::vector<FuncInfo*>& _funcs, bool _report_recursive)
|
Inliner(std::vector<FuncInfo>& _funcs, bool _report_recursive)
|
||||||
: funcs(_funcs), report_recursive(_report_recursive)
|
: funcs(_funcs), report_recursive(_report_recursive)
|
||||||
{ Analyze(); }
|
{ Analyze(); }
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ protected:
|
||||||
|
|
||||||
// Information about all of the functions (and events/hooks) in
|
// Information about all of the functions (and events/hooks) in
|
||||||
// the full set of scripts.
|
// the full set of scripts.
|
||||||
std::vector<FuncInfo*>& funcs;
|
std::vector<FuncInfo>& funcs;
|
||||||
|
|
||||||
// Functions that we've determined to be suitable for inlining.
|
// Functions that we've determined to be suitable for inlining.
|
||||||
std::unordered_set<Func*> inline_ables;
|
std::unordered_set<Func*> inline_ables;
|
||||||
|
|
|
@ -12,19 +12,19 @@ namespace zeek::detail {
|
||||||
std::unordered_set<const Func*> non_recursive_funcs;
|
std::unordered_set<const Func*> non_recursive_funcs;
|
||||||
|
|
||||||
// Tracks all of the loaded functions (including event handlers and hooks).
|
// Tracks all of the loaded functions (including event handlers and hooks).
|
||||||
static std::vector<FuncInfo*> funcs;
|
static std::vector<FuncInfo> funcs;
|
||||||
|
|
||||||
|
|
||||||
FuncInfo::~FuncInfo()
|
FuncInfo::FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body)
|
||||||
{
|
: func(std::move(_func)), scope(std::move(_scope)), body(std::move(_body))
|
||||||
delete pf;
|
{}
|
||||||
delete save_file;
|
|
||||||
}
|
void FuncInfo::SetProfile(std::unique_ptr<ProfileFunc> _pf)
|
||||||
|
{ pf = std::move(_pf); }
|
||||||
|
|
||||||
void analyze_func(ScriptFuncPtr f)
|
void analyze_func(ScriptFuncPtr f)
|
||||||
{
|
{
|
||||||
auto info = new FuncInfo(f, {NewRef{}, f->GetScope()}, f->CurrentBody());
|
funcs.emplace_back(f, ScopePtr{NewRef{}, f->GetScope()}, f->CurrentBody());
|
||||||
funcs.push_back(info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_env_opt(const char* opt, bool& opt_flag)
|
static void check_env_opt(const char* opt, bool& opt_flag)
|
||||||
|
@ -50,8 +50,8 @@ void analyze_scripts(Options& opts)
|
||||||
|
|
||||||
for ( auto& f : funcs )
|
for ( auto& f : funcs )
|
||||||
{
|
{
|
||||||
f->SetProfile(new ProfileFunc(true));
|
f.SetProfile(std::make_unique<ProfileFunc>(true));
|
||||||
f->Body()->Traverse(f->Profile());
|
f.Body()->Traverse(f.Profile());
|
||||||
}
|
}
|
||||||
|
|
||||||
Inliner* inl = nullptr;
|
Inliner* inl = nullptr;
|
||||||
|
|
|
@ -32,34 +32,27 @@ using ScriptFuncPtr = IntrusivePtr<ScriptFunc>;
|
||||||
// Info we need for tracking an instance of a function.
|
// Info we need for tracking an instance of a function.
|
||||||
class FuncInfo {
|
class FuncInfo {
|
||||||
public:
|
public:
|
||||||
FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body)
|
FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body);
|
||||||
{
|
|
||||||
func = std::move(_func);
|
|
||||||
scope = std::move(_scope);
|
|
||||||
body = std::move(_body);
|
|
||||||
}
|
|
||||||
|
|
||||||
~FuncInfo();
|
|
||||||
|
|
||||||
ScriptFunc* Func() { return func.get(); }
|
ScriptFunc* Func() { return func.get(); }
|
||||||
ScriptFuncPtr FuncPtr() { return func; }
|
ScriptFuncPtr FuncPtr() { return func; }
|
||||||
ScopePtr Scope() { return scope; }
|
ScopePtr Scope() { return scope; }
|
||||||
StmtPtr Body() { return body; }
|
StmtPtr Body() { return body; }
|
||||||
ProfileFunc* Profile() { return pf; }
|
ProfileFunc* Profile() { return pf.get(); }
|
||||||
const char* SaveFile() { return save_file; }
|
const std::string& SaveFile() { return save_file; }
|
||||||
|
|
||||||
void SetProfile(ProfileFunc* _pf) { pf = _pf; }
|
void SetProfile(std::unique_ptr<ProfileFunc> _pf);
|
||||||
void SetSaveFile(const char* _sf);
|
void SetSaveFile(std::string _sf) { save_file = std::move(_sf); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ScriptFuncPtr func;
|
ScriptFuncPtr func;
|
||||||
ScopePtr scope;
|
ScopePtr scope;
|
||||||
StmtPtr body;
|
StmtPtr body;
|
||||||
ProfileFunc* pf = nullptr;
|
std::unique_ptr<ProfileFunc> pf;
|
||||||
|
|
||||||
// If we're saving this function in a file, this is the name
|
// If we're saving this function in a file, this is the name
|
||||||
// of the file to use.
|
// of the file to use.
|
||||||
char* save_file = nullptr;
|
std::string save_file;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue