mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
make including count of container elements non-optional
This commit is contained in:
parent
b670046a69
commit
edf276520a
5 changed files with 62 additions and 128 deletions
39
src/Val.cc
39
src/Val.cc
|
@ -1322,14 +1322,12 @@ ValPtr ListVal::DoClone(CloneState* state)
|
||||||
return lv;
|
return lv;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ListVal::Footprint(bool count_entries) const
|
unsigned int ListVal::Footprint() const
|
||||||
{
|
{
|
||||||
unsigned int fp = 0;
|
unsigned int fp = vals.size();
|
||||||
for ( const auto& val : vals )
|
|
||||||
fp += val->Footprint(count_entries);
|
|
||||||
|
|
||||||
if ( count_entries )
|
for ( const auto& val : vals )
|
||||||
fp += vals.size();
|
fp += val->Footprint();
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
@ -2685,9 +2683,9 @@ ValPtr TableVal::DoClone(CloneState* state)
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int TableVal::Footprint(bool count_entries) const
|
unsigned int TableVal::Footprint() const
|
||||||
{
|
{
|
||||||
unsigned int fp = 0;
|
unsigned int fp = table_val->Length();
|
||||||
|
|
||||||
for ( const auto& iter : *table_val )
|
for ( const auto& iter : *table_val )
|
||||||
{
|
{
|
||||||
|
@ -2695,14 +2693,11 @@ unsigned int TableVal::Footprint(bool count_entries) const
|
||||||
auto vl = table_hash->RecoverVals(*k);
|
auto vl = table_hash->RecoverVals(*k);
|
||||||
auto v = iter.GetValue<TableEntryVal*>()->GetVal();
|
auto v = iter.GetValue<TableEntryVal*>()->GetVal();
|
||||||
|
|
||||||
fp += vl->Footprint(count_entries);
|
fp += vl->Footprint();
|
||||||
if ( v )
|
if ( v )
|
||||||
fp += v->Footprint(count_entries);
|
fp += v->Footprint();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count_entries )
|
|
||||||
fp += table_val->Length();
|
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3071,7 +3066,7 @@ ValPtr RecordVal::DoClone(CloneState* state)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int RecordVal::Footprint(bool count_entries) const
|
unsigned int RecordVal::Footprint() const
|
||||||
{
|
{
|
||||||
// Which records we're in the process of analyzing - used to
|
// Which records we're in the process of analyzing - used to
|
||||||
// avoid infinite recursion for circular types (which can only
|
// avoid infinite recursion for circular types (which can only
|
||||||
|
@ -3084,8 +3079,8 @@ unsigned int RecordVal::Footprint(bool count_entries) const
|
||||||
|
|
||||||
pending_records.insert(this);
|
pending_records.insert(this);
|
||||||
|
|
||||||
unsigned int fp = 0;
|
|
||||||
int n = NumFields();
|
int n = NumFields();
|
||||||
|
unsigned int fp = n;
|
||||||
|
|
||||||
for ( auto i = 0; i < n; ++i )
|
for ( auto i = 0; i < n; ++i )
|
||||||
{
|
{
|
||||||
|
@ -3094,12 +3089,9 @@ unsigned int RecordVal::Footprint(bool count_entries) const
|
||||||
|
|
||||||
auto f_i = GetField(i);
|
auto f_i = GetField(i);
|
||||||
if ( f_i )
|
if ( f_i )
|
||||||
fp += f_i->Footprint(count_entries);
|
fp += f_i->Footprint();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count_entries )
|
|
||||||
fp += n;
|
|
||||||
|
|
||||||
pending_records.erase(this);
|
pending_records.erase(this);
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
|
@ -3628,21 +3620,18 @@ bool VectorVal::Concretize(const TypePtr& t)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int VectorVal::Footprint(bool count_entries) const
|
unsigned int VectorVal::Footprint() const
|
||||||
{
|
{
|
||||||
unsigned int fp = 0;
|
|
||||||
auto n = vector_val->size();
|
auto n = vector_val->size();
|
||||||
|
unsigned int fp = n;
|
||||||
|
|
||||||
for ( auto i = 0U; i < n; ++i )
|
for ( auto i = 0U; i < n; ++i )
|
||||||
{
|
{
|
||||||
auto v = At(i);
|
auto v = At(i);
|
||||||
if ( v )
|
if ( v )
|
||||||
fp += v->Footprint(count_entries);
|
fp += v->Footprint();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count_entries )
|
|
||||||
fp += n;
|
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
src/Val.h
22
src/Val.h
|
@ -122,16 +122,14 @@ public:
|
||||||
virtual ValPtr SizeVal() const;
|
virtual ValPtr SizeVal() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Val's "footprint", i.e., how many atomic (non-container)
|
* Returns the Val's "footprint", i.e., how many elements / Val
|
||||||
* values it includes, either directly or indirectly.
|
* objects the value includes, either directly or indirectly.
|
||||||
|
* The number is not meant to be precise, but rather comparable:
|
||||||
|
* larger footprint correlates with more memory consumption.
|
||||||
*
|
*
|
||||||
* @param count_entries If true, (recursively) include in the
|
* @return The total footprint.
|
||||||
* footprint the count of the number of container elements as well
|
|
||||||
* as each element's footprint.
|
|
||||||
*
|
|
||||||
* @return The total footprint, optionally including element counts.
|
|
||||||
*/
|
*/
|
||||||
virtual unsigned int Footprint(bool count_entries) const { return 1; }
|
virtual unsigned int Footprint() const { return 1; }
|
||||||
|
|
||||||
// Bytes in total value object.
|
// Bytes in total value object.
|
||||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||||
|
@ -678,7 +676,7 @@ public:
|
||||||
|
|
||||||
void Describe(ODesc* d) const override;
|
void Describe(ODesc* d) const override;
|
||||||
|
|
||||||
unsigned int Footprint(bool count_entries) const override;
|
unsigned int Footprint() const override;
|
||||||
|
|
||||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||||
"GHI-572.")]] unsigned int
|
"GHI-572.")]] unsigned int
|
||||||
|
@ -955,7 +953,7 @@ public:
|
||||||
// the function in the frame allowing it to capture its closure.
|
// the function in the frame allowing it to capture its closure.
|
||||||
void InitDefaultFunc(detail::Frame* f);
|
void InitDefaultFunc(detail::Frame* f);
|
||||||
|
|
||||||
unsigned int Footprint(bool count_entries) const override;
|
unsigned int Footprint() const override;
|
||||||
|
|
||||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||||
"GHI-572.")]] unsigned int
|
"GHI-572.")]] unsigned int
|
||||||
|
@ -1383,7 +1381,7 @@ public:
|
||||||
}
|
}
|
||||||
RecordValPtr CoerceTo(RecordTypePtr other, bool allow_orphaning = false);
|
RecordValPtr CoerceTo(RecordTypePtr other, bool allow_orphaning = false);
|
||||||
|
|
||||||
unsigned int Footprint(bool count_entries) const override;
|
unsigned int Footprint() const override;
|
||||||
|
|
||||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||||
"GHI-572.")]] unsigned int
|
"GHI-572.")]] unsigned int
|
||||||
|
@ -1642,7 +1640,7 @@ public:
|
||||||
const auto& RawYieldType() const { return yield_type; }
|
const auto& RawYieldType() const { return yield_type; }
|
||||||
const auto& RawYieldTypes() const { return yield_types; }
|
const auto& RawYieldTypes() const { return yield_types; }
|
||||||
|
|
||||||
unsigned int Footprint(bool count_entries) const override;
|
unsigned int Footprint() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
|
25
src/zeek.bif
25
src/zeek.bif
|
@ -1985,15 +1985,16 @@ function global_sizes%(%): var_sizes &deprecated="Remove in v5.1. MemoryAllocati
|
||||||
return sizes;
|
return sizes;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Generates a table of the footprint of all global container variables.
|
## Generates a table of the "footprint" of all global container variables.
|
||||||
|
## This is (approximately) the number of objects the global contains either
|
||||||
|
## directly or indirectly. The number is not meant to be precise, but
|
||||||
|
## rather comparable: larger footprint correlates with more memory consumption.
|
||||||
## The table index is the variable name and the value is the footprint.
|
## The table index is the variable name and the value is the footprint.
|
||||||
## The argument specifies whether the footprint should (recursively) include
|
|
||||||
## the number of entries in each global.
|
|
||||||
##
|
##
|
||||||
## Returns: A table that maps variable names to their footprints.
|
## Returns: A table that maps variable names to their footprints.
|
||||||
##
|
##
|
||||||
## .. zeek:see:: value_footprint
|
## .. zeek:see:: value_footprint
|
||||||
function global_container_footprints%(count_entries: bool%): var_sizes
|
function global_container_footprints%(%): var_sizes
|
||||||
%{
|
%{
|
||||||
auto sizes = zeek::make_intrusive<zeek::TableVal>(IntrusivePtr{zeek::NewRef{}, var_sizes});
|
auto sizes = zeek::make_intrusive<zeek::TableVal>(IntrusivePtr{zeek::NewRef{}, var_sizes});
|
||||||
const auto& globals = zeek::detail::global_scope()->Vars();
|
const auto& globals = zeek::detail::global_scope()->Vars();
|
||||||
|
@ -2007,25 +2008,23 @@ function global_container_footprints%(count_entries: bool%): var_sizes
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto id_name = zeek::make_intrusive<zeek::StringVal>(id->Name());
|
auto id_name = zeek::make_intrusive<zeek::StringVal>(id->Name());
|
||||||
auto fp = zeek::val_mgr->Count(v->Footprint(count_entries));
|
auto fp = zeek::val_mgr->Count(v->Footprint());
|
||||||
sizes->Assign(std::move(id_name), std::move(fp));
|
sizes->Assign(std::move(id_name), std::move(fp));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sizes;
|
return sizes;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Computes a value's "footprint" (number of atomic elements included, either
|
## Computes a value's "footprint": the number of objects the value contains
|
||||||
## directly or indirectly). The argument, if true, specifies that the
|
## either directly or indirectly. The number is not meant to be precise, but
|
||||||
## footprint should also include the number of entries in each included
|
## rather comparable: larger footprint correlates with more memory consumption.
|
||||||
## container.
|
|
||||||
##
|
##
|
||||||
## Returns: the total number of atomic elements plus (optionally) the
|
## Returns: the footprint.
|
||||||
## number of entries in included containers.
|
|
||||||
##
|
##
|
||||||
## .. zeek:see:: global_container_footprints
|
## .. zeek:see:: global_container_footprints
|
||||||
function value_footprint%(v: any, count_entries: bool%): count
|
function value_footprint%(v: any%): count
|
||||||
%{
|
%{
|
||||||
return zeek::val_mgr->Count(v->Footprint(count_entries));
|
return zeek::val_mgr->Count(v->Footprint());
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Generates a table with information about all global identifiers. The table
|
## Generates a table with information about all global identifiers. The table
|
||||||
|
|
|
@ -1,53 +1,27 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
bool, 1
|
bool, 1
|
||||||
bool, 1
|
|
||||||
count, 1
|
|
||||||
count, 1
|
count, 1
|
||||||
int, 1
|
int, 1
|
||||||
int, 1
|
|
||||||
double, 1
|
|
||||||
double, 1
|
double, 1
|
||||||
string, 1
|
string, 1
|
||||||
string, 1
|
|
||||||
pattern, 1
|
|
||||||
pattern, 1
|
pattern, 1
|
||||||
addr, 1
|
addr, 1
|
||||||
addr, 1
|
|
||||||
subnet, 1
|
|
||||||
subnet, 1
|
subnet, 1
|
||||||
port, 1
|
port, 1
|
||||||
port, 1
|
|
||||||
l1, 0
|
|
||||||
l1, 3
|
l1, 3
|
||||||
l1b, 3
|
|
||||||
l1b, 6
|
l1b, 6
|
||||||
l2, 2
|
|
||||||
l2, 7
|
l2, 7
|
||||||
l2b, 4
|
|
||||||
l2b, 9
|
l2b, 9
|
||||||
v1, 4
|
|
||||||
v1, 8
|
v1, 8
|
||||||
v2, 8
|
|
||||||
v2, 18
|
v2, 18
|
||||||
v3, 3
|
|
||||||
v3, 11
|
v3, 11
|
||||||
t1, 6
|
|
||||||
t1, 12
|
t1, 12
|
||||||
t2, 9
|
|
||||||
t2, 18
|
t2, 18
|
||||||
t3, 20
|
|
||||||
t3, 46
|
t3, 46
|
||||||
t4, 7
|
|
||||||
t4, 19
|
t4, 19
|
||||||
s1, 3
|
|
||||||
s1, 9
|
s1, 9
|
||||||
s2, 6
|
|
||||||
s2, 15
|
s2, 15
|
||||||
s3, 8
|
|
||||||
s3, 20
|
s3, 20
|
||||||
s4, 3
|
|
||||||
s4, 9
|
s4, 9
|
||||||
1
|
|
||||||
3
|
3
|
||||||
1
|
|
||||||
3
|
3
|
||||||
|
|
|
@ -29,89 +29,65 @@ redef record X += {
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
print "bool", value_footprint(T, F);
|
print "bool", val_footprint(T);
|
||||||
print "bool", value_footprint(T, T);
|
print "count", val_footprint(4);
|
||||||
print "count", value_footprint(3, F);
|
print "int", val_footprint(-4);
|
||||||
print "count", value_footprint(4, T);
|
print "double", val_footprint(4e99);
|
||||||
print "int", value_footprint(-3, F);
|
print "string", val_footprint("longlonglong");
|
||||||
print "int", value_footprint(-4, T);
|
print "pattern", val_footprint(/longlonglong/);
|
||||||
print "double", value_footprint(-3.0, F);
|
print "addr", val_footprint([ffff::ffff]);
|
||||||
print "double", value_footprint(4e99, T);
|
print "subnet", val_footprint([ffff::ffff]/99);
|
||||||
print "string", value_footprint("short", F);
|
print "port", val_footprint(9999/udp);
|
||||||
print "string", value_footprint("longlonglong", T);
|
|
||||||
print "pattern", value_footprint(/short/, F);
|
|
||||||
print "pattern", value_footprint(/longlonglong/, T);
|
|
||||||
print "addr", value_footprint(1.2.3.4, F);
|
|
||||||
print "addr", value_footprint([ffff::ffff], T);
|
|
||||||
print "subnet", value_footprint(1.2.3.4/22, F);
|
|
||||||
print "subnet", value_footprint([ffff::ffff]/99, T);
|
|
||||||
print "port", value_footprint(123/tcp, F);
|
|
||||||
print "port", value_footprint(9999/udp, T);
|
|
||||||
|
|
||||||
local l1: r1;
|
local l1: r1;
|
||||||
print "l1", value_footprint(l1, F);
|
print "l1", val_footprint(l1);
|
||||||
print "l1", value_footprint(l1, T);
|
|
||||||
|
|
||||||
local l1b = r1($a=3, $b=3.0, $c="3");
|
local l1b = r1($a=3, $b=3.0, $c="3");
|
||||||
print "l1b", value_footprint(l1b, F);
|
print "l1b", val_footprint(l1b);
|
||||||
print "l1b", value_footprint(l1b, T);
|
|
||||||
|
|
||||||
local l2: r2;
|
local l2: r2;
|
||||||
print "l2", value_footprint(l2, F);
|
print "l2", val_footprint(l2);
|
||||||
print "l2", value_footprint(l2, T);
|
|
||||||
|
|
||||||
local l2b = r2($a=3, $b1=99.0, $c="I'm here");
|
local l2b = r2($a=3, $b1=99.0, $c="I'm here");
|
||||||
print "l2b", value_footprint(l2b, F);
|
print "l2b", val_footprint(l2b);
|
||||||
print "l2b", value_footprint(l2b, T);
|
|
||||||
|
|
||||||
local v1 = vector(9, 7, 3, 1);
|
local v1 = vector(9, 7, 3, 1);
|
||||||
print "v1", value_footprint(v1, F);
|
print "v1", val_footprint(v1);
|
||||||
print "v1", value_footprint(v1, T);
|
|
||||||
|
|
||||||
local v2 = vector(v1, v1);
|
local v2 = vector(v1, v1);
|
||||||
print "v2", value_footprint(v2, F);
|
print "v2", val_footprint(v2);
|
||||||
print "v2", value_footprint(v2, T);
|
|
||||||
|
|
||||||
local v3 = vector(l1, l1b);
|
local v3 = vector(l1, l1b);
|
||||||
print "v3", value_footprint(v3, F);
|
print "v3", val_footprint(v3);
|
||||||
print "v3", value_footprint(v3, T);
|
|
||||||
|
|
||||||
local t1 = table([1] = 1, [2] = 4, [3] = 9);
|
local t1 = table([1] = 1, [2] = 4, [3] = 9);
|
||||||
print "t1", value_footprint(t1, F);
|
|
||||||
# Note, table and set footprint values using count_entries=T because
|
# Note, table and set footprint values using count_entries=T because
|
||||||
# table indices are ListVal's, so those add their own container
|
# table indices are ListVal's, so those add their own container
|
||||||
# entry counts into the sum.
|
# entry counts into the sum.
|
||||||
print "t1", value_footprint(t1, T);
|
print "t1", val_footprint(t1);
|
||||||
|
|
||||||
local t2 = table([1, 3] = 1, [2, 3] = 4, [3, 3] = 9);
|
local t2 = table([1, 3] = 1, [2, 3] = 4, [3, 3] = 9);
|
||||||
print "t2", value_footprint(t2, F);
|
print "t2", val_footprint(t2);
|
||||||
print "t2", value_footprint(t2, T);
|
|
||||||
|
|
||||||
local t3 = table([1, 3] = v2, [2, 3] = v2);
|
local t3 = table([1, 3] = v2, [2, 3] = v2);
|
||||||
print "t3", value_footprint(t3, F);
|
print "t3", val_footprint(t3);
|
||||||
print "t3", value_footprint(t3, T);
|
|
||||||
|
|
||||||
local t4 = table([1, 3] = l1, [2, 3] = l1b);
|
local t4 = table([1, 3] = l1, [2, 3] = l1b);
|
||||||
print "t4", value_footprint(t4, F);
|
print "t4", val_footprint(t4);
|
||||||
print "t4", value_footprint(t4, T);
|
|
||||||
|
|
||||||
local s1 = set(1, 4, 9);
|
local s1 = set(1, 4, 9);
|
||||||
print "s1", value_footprint(s1, F);
|
print "s1", val_footprint(s1);
|
||||||
print "s1", value_footprint(s1, T);
|
|
||||||
|
|
||||||
local s2 = set([1, 3], [2, 3], [3, 3]);
|
local s2 = set([1, 3], [2, 3], [3, 3]);
|
||||||
print "s2", value_footprint(s2, F);
|
print "s2", val_footprint(s2);
|
||||||
print "s2", value_footprint(s2, T);
|
|
||||||
|
|
||||||
local s3: set[r1, count];
|
local s3: set[r1, count];
|
||||||
add s3[l1b, 9];
|
add s3[l1b, 9];
|
||||||
add s3[l1b, 12];
|
add s3[l1b, 12];
|
||||||
print "s3", value_footprint(s3, F);
|
print "s3", val_footprint(s3);
|
||||||
print "s3", value_footprint(s3, T);
|
|
||||||
|
|
||||||
local s4 = set(vector(l1b), vector(l1b), vector(l1b));
|
local s4 = set(vector(l1b), vector(l1b), vector(l1b));
|
||||||
print "s4", value_footprint(s4, F);
|
print "s4", val_footprint(s4);
|
||||||
print "s4", value_footprint(s4, T);
|
|
||||||
|
|
||||||
local x: X;
|
local x: X;
|
||||||
local y: Y;
|
local y: Y;
|
||||||
|
@ -119,8 +95,6 @@ event zeek_init()
|
||||||
x$y = y;
|
x$y = y;
|
||||||
y$x = x;
|
y$x = x;
|
||||||
|
|
||||||
print value_footprint(x, F);
|
print val_footprint(x);
|
||||||
print value_footprint(x, T);
|
print val_footprint(y);
|
||||||
print value_footprint(y, F);
|
|
||||||
print value_footprint(y, T);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue