mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
expand profiling to include values to which globals are assigned
This commit is contained in:
parent
dd05beff50
commit
158e82a2c1
2 changed files with 104 additions and 4 deletions
|
@ -476,14 +476,30 @@ void ProfileFuncs::MergeInProfile(ProfileFunc* pf)
|
||||||
if ( ! inserted )
|
if ( ! inserted )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto& v = g->GetVal();
|
TraverseValue(g->GetVal());
|
||||||
if ( v )
|
|
||||||
main_types.push_back(v->GetType().get());
|
const auto& t = g->GetType();
|
||||||
|
if ( t->Tag() == TYPE_TYPE )
|
||||||
|
(void) HashType(t->AsTypeType()->GetType());
|
||||||
|
|
||||||
|
auto& init_exprs = g->GetInitExprs();
|
||||||
|
for ( auto i_e : init_exprs )
|
||||||
|
if ( i_e )
|
||||||
|
{
|
||||||
|
pending_exprs.push_back(i_e.get());
|
||||||
|
|
||||||
|
if ( i_e->Tag() == EXPR_LAMBDA )
|
||||||
|
lambdas.insert(i_e->AsLambdaExpr());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& attrs = g->GetAttrs();
|
||||||
|
if ( attrs )
|
||||||
|
AnalyzeAttrs(attrs.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
constants.insert(pf->Constants().begin(), pf->Constants().end());
|
constants.insert(pf->Constants().begin(), pf->Constants().end());
|
||||||
main_types.insert(main_types.end(),
|
main_types.insert(main_types.end(),
|
||||||
pf->OrderedTypes().begin(), pf->OrderedTypes().end());
|
pf->OrderedTypes().begin(), pf->OrderedTypes().end());
|
||||||
script_calls.insert(pf->ScriptCalls().begin(), pf->ScriptCalls().end());
|
script_calls.insert(pf->ScriptCalls().begin(), pf->ScriptCalls().end());
|
||||||
BiF_globals.insert(pf->BiFGlobals().begin(), pf->BiFGlobals().end());
|
BiF_globals.insert(pf->BiFGlobals().begin(), pf->BiFGlobals().end());
|
||||||
events.insert(pf->Events().begin(), pf->Events().end());
|
events.insert(pf->Events().begin(), pf->Events().end());
|
||||||
|
@ -498,6 +514,86 @@ void ProfileFuncs::MergeInProfile(ProfileFunc* pf)
|
||||||
AnalyzeAttrs(a);
|
AnalyzeAttrs(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileFuncs::TraverseValue(const ValPtr& v)
|
||||||
|
{
|
||||||
|
if ( ! v )
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto& t = v->GetType();
|
||||||
|
(void) HashType(t);
|
||||||
|
|
||||||
|
switch ( t->Tag() ) {
|
||||||
|
case TYPE_ADDR:
|
||||||
|
case TYPE_ANY:
|
||||||
|
case TYPE_BOOL:
|
||||||
|
case TYPE_COUNT:
|
||||||
|
case TYPE_DOUBLE:
|
||||||
|
case TYPE_ENUM:
|
||||||
|
case TYPE_ERROR:
|
||||||
|
case TYPE_FILE:
|
||||||
|
case TYPE_FUNC:
|
||||||
|
case TYPE_INT:
|
||||||
|
case TYPE_INTERVAL:
|
||||||
|
case TYPE_OPAQUE:
|
||||||
|
case TYPE_PATTERN:
|
||||||
|
case TYPE_PORT:
|
||||||
|
case TYPE_STRING:
|
||||||
|
case TYPE_SUBNET:
|
||||||
|
case TYPE_TIME:
|
||||||
|
case TYPE_TIMER:
|
||||||
|
case TYPE_UNION:
|
||||||
|
case TYPE_VOID:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_RECORD:
|
||||||
|
{
|
||||||
|
auto r = cast_intrusive<RecordVal>(v);
|
||||||
|
auto n = r->NumFields();
|
||||||
|
|
||||||
|
for ( auto i = 0; i < n; ++i )
|
||||||
|
TraverseValue(r->GetField(i));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_TABLE:
|
||||||
|
{
|
||||||
|
auto tv = cast_intrusive<TableVal>(v);
|
||||||
|
auto tv_map = tv->ToMap();
|
||||||
|
|
||||||
|
for ( auto& tv_i : tv_map )
|
||||||
|
{
|
||||||
|
TraverseValue(tv_i.first);
|
||||||
|
TraverseValue(tv_i.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_LIST:
|
||||||
|
{
|
||||||
|
auto lv = cast_intrusive<ListVal>(v);
|
||||||
|
auto n = lv->Length();
|
||||||
|
|
||||||
|
for ( auto i = 0; i < n; ++i )
|
||||||
|
TraverseValue(lv->Idx(i));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_VECTOR:
|
||||||
|
{
|
||||||
|
auto vv = cast_intrusive<VectorVal>(v);
|
||||||
|
auto n = vv->Size();
|
||||||
|
|
||||||
|
for ( auto i = 0; i < n; ++i )
|
||||||
|
TraverseValue(vv->ValAt(i));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_TYPE:
|
||||||
|
(void) HashType(t->AsTypeType()->GetType());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ProfileFuncs::DrainPendingExprs()
|
void ProfileFuncs::DrainPendingExprs()
|
||||||
{
|
{
|
||||||
while ( pending_exprs.size() > 0 )
|
while ( pending_exprs.size() > 0 )
|
||||||
|
|
|
@ -339,6 +339,10 @@ protected:
|
||||||
// Incorporate the given function profile into the global profile.
|
// Incorporate the given function profile into the global profile.
|
||||||
void MergeInProfile(ProfileFunc* pf);
|
void MergeInProfile(ProfileFunc* pf);
|
||||||
|
|
||||||
|
// Recursively traverse a (possibly aggregate) value to extract
|
||||||
|
// all of the types its elements use.
|
||||||
|
void TraverseValue(const ValPtr& v);
|
||||||
|
|
||||||
// When traversing types, Zeek records can have attributes that in
|
// When traversing types, Zeek records can have attributes that in
|
||||||
// turn have expressions associated with them. The expressions can
|
// turn have expressions associated with them. The expressions can
|
||||||
// in turn have types, which might be records with further attribute
|
// in turn have types, which might be records with further attribute
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue