mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
added value_footprint() and global_container_footprints() BiFs
This commit is contained in:
parent
02771168f0
commit
16c37034de
5 changed files with 287 additions and 0 deletions
72
src/Val.cc
72
src/Val.cc
|
@ -1322,6 +1322,18 @@ ValPtr ListVal::DoClone(CloneState* state)
|
|||
return lv;
|
||||
}
|
||||
|
||||
unsigned int ListVal::Footprint(bool count_entries) const
|
||||
{
|
||||
unsigned int fp = 0;
|
||||
for ( const auto& val : vals )
|
||||
fp += val->Footprint(count_entries);
|
||||
|
||||
if ( count_entries )
|
||||
fp += vals.size();
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
unsigned int ListVal::MemoryAllocation() const
|
||||
{
|
||||
#pragma GCC diagnostic push
|
||||
|
@ -2673,6 +2685,27 @@ ValPtr TableVal::DoClone(CloneState* state)
|
|||
return tv;
|
||||
}
|
||||
|
||||
unsigned int TableVal::Footprint(bool count_entries) const
|
||||
{
|
||||
unsigned int fp = 0;
|
||||
|
||||
for ( const auto& iter : *table_val )
|
||||
{
|
||||
auto k = iter.GetHashKey();
|
||||
auto vl = table_hash->RecoverVals(*k);
|
||||
auto v = iter.GetValue<TableEntryVal*>()->GetVal();
|
||||
|
||||
fp += vl->Footprint(count_entries);
|
||||
if ( v )
|
||||
fp += v->Footprint(count_entries);
|
||||
}
|
||||
|
||||
if ( count_entries )
|
||||
fp += table_val->Length();
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
unsigned int TableVal::MemoryAllocation() const
|
||||
{
|
||||
unsigned int size = 0;
|
||||
|
@ -3038,6 +3071,27 @@ ValPtr RecordVal::DoClone(CloneState* state)
|
|||
return rv;
|
||||
}
|
||||
|
||||
unsigned int RecordVal::Footprint(bool count_entries) const
|
||||
{
|
||||
unsigned int fp = 0;
|
||||
int n = NumFields();
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
{
|
||||
if ( ! HasField(i) )
|
||||
continue;
|
||||
|
||||
auto f_i = GetField(i);
|
||||
if ( f_i )
|
||||
fp += f_i->Footprint(count_entries);
|
||||
}
|
||||
|
||||
if ( count_entries )
|
||||
fp += n;
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
unsigned int RecordVal::MemoryAllocation() const
|
||||
{
|
||||
unsigned int size = 0;
|
||||
|
@ -3561,6 +3615,24 @@ bool VectorVal::Concretize(const TypePtr& t)
|
|||
return true;
|
||||
}
|
||||
|
||||
unsigned int VectorVal::Footprint(bool count_entries) const
|
||||
{
|
||||
unsigned int fp = 0;
|
||||
auto n = vector_val->size();
|
||||
|
||||
for ( auto i = 0U; i < n; ++i )
|
||||
{
|
||||
auto v = At(i);
|
||||
if ( v )
|
||||
fp += v->Footprint(count_entries);
|
||||
}
|
||||
|
||||
if ( count_entries )
|
||||
fp += n;
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
unsigned int VectorVal::Resize(unsigned int new_num_elements)
|
||||
{
|
||||
unsigned int oldsize = vector_val->size();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue