Merge remote-tracking branch 'origin/topic/timw/572-deprecate-memoryallocation'

* origin/topic/timw/572-deprecate-memoryallocation:
  GH-572: Mark MemoryAllocation() and related methods deprecated
This commit is contained in:
Tim Wojtulewicz 2021-06-28 11:08:29 -07:00
commit 2e5d1d924f
33 changed files with 163 additions and 7 deletions

View file

@ -1,3 +1,7 @@
4.1.0-dev.816 | 2021-06-28 11:08:29 -0700
* GH-572: Mark MemoryAllocation() and related methods deprecated (Tim Wojtulewicz, Corelight)
4.1.0-dev.814 | 2021-06-28 11:06:39 -0700 4.1.0-dev.814 | 2021-06-28 11:06:39 -0700
* Check for -1 return from FieldOffset() in Val::HasField() * Check for -1 return from FieldOffset() in Val::HasField()

5
NEWS
View file

@ -113,6 +113,11 @@ Deprecated Functionality
- ``supervisor_rotation_format_func`` is renamed to ``archiver_rotation_format_func`` - ``supervisor_rotation_format_func`` is renamed to ``archiver_rotation_format_func``
- The ```MemoryAllocation()``` function implemented by a number of interfaces
is now deprecated. In testing we found that the values returned were mostly
incorrect and weren't useful. The ```val_size``` and ```global_sizes``` BIF
methods have also both been marked deprecated.
Zeek 4.0.0 Zeek 4.0.0
========== ==========

View file

@ -1 +1 @@
4.1.0-dev.814 4.1.0-dev.816

View file

@ -26,6 +26,7 @@ public:
void ReplaceSyms(int_list* new_syms) void ReplaceSyms(int_list* new_syms)
{ delete syms; syms = new_syms; } { delete syms; syms = new_syms; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const; unsigned int MemoryAllocation() const;
protected: protected:

View file

@ -30,6 +30,7 @@ public:
// Given a hash key, recover the values used to create it. // Given a hash key, recover the values used to create it.
ListValPtr RecoverVals(const HashKey& k) const; ListValPtr RecoverVals(const HashKey& k) const;
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const { return padded_sizeof(*this) + util::pad_size(size); } unsigned int MemoryAllocation() const { return padded_sizeof(*this) + util::pad_size(size); }
protected: protected:

View file

@ -381,17 +381,23 @@ void Connection::FlipRoles()
unsigned int Connection::MemoryAllocation() const unsigned int Connection::MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return session::Session::MemoryAllocation() + padded_sizeof(*this) return session::Session::MemoryAllocation() + padded_sizeof(*this)
+ (timers.MemoryAllocation() - padded_sizeof(timers)) + (timers.MemoryAllocation() - padded_sizeof(timers))
+ (conn_val ? conn_val->MemoryAllocation() : 0) + (conn_val ? conn_val->MemoryAllocation() : 0)
+ (adapter ? adapter->MemoryAllocation(): 0) + (adapter ? adapter->MemoryAllocation(): 0)
// primary_PIA is already contained in the analyzer tree. // primary_PIA is already contained in the analyzer tree.
; ;
#pragma GCC diagnostic pop
} }
unsigned int Connection::MemoryAllocationVal() const unsigned int Connection::MemoryAllocationVal() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return conn_val ? conn_val->MemoryAllocation() : 0; return conn_val ? conn_val->MemoryAllocation() : 0;
#pragma GCC diagnostic pop
} }
void Connection::Describe(ODesc* d) const void Connection::Describe(ODesc* d) const

View file

@ -187,7 +187,9 @@ public:
// Statistics. // Statistics.
// Just a lower bound. // Just a lower bound.
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocationVal() const override; unsigned int MemoryAllocationVal() const override;
static uint64_t TotalConnections() static uint64_t TotalConnections()

View file

@ -426,10 +426,13 @@ unsigned int DFA_Machine::MemoryAllocation() const
dfa_state_cache->GetStats(&s); dfa_state_cache->GetStats(&s);
// FIXME: Count *ec? // FIXME: Count *ec?
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) return padded_sizeof(*this)
+ s.mem + s.mem
+ padded_sizeof(*start_state) + padded_sizeof(*start_state)
+ nfa->MemoryAllocation(); + nfa->MemoryAllocation();
#pragma GCC diagnostic pop
} }
bool DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set, bool DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set,

View file

@ -123,6 +123,7 @@ public:
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
void Dump(FILE* f); void Dump(FILE* f);
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const; unsigned int MemoryAllocation() const;
protected: protected:

View file

@ -772,7 +772,10 @@ void Dictionary::DumpKeys() const
if ( binary ) if ( binary )
{ {
char key = char(random() % 26) + 'A'; char key = char(random() % 26) + 'A';
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
sprintf(key_file, "%d.%d.%zu-%c.key", Length(), max_distance, MemoryAllocation()/Length(), key); sprintf(key_file, "%d.%d.%zu-%c.key", Length(), max_distance, MemoryAllocation()/Length(), key);
#pragma GCC diagnostic pop
std::ofstream f(key_file, std::ios::binary|std::ios::out|std::ios::trunc); std::ofstream f(key_file, std::ios::binary|std::ios::out|std::ios::trunc);
for ( int idx = 0; idx < Capacity(); idx++ ) for ( int idx = 0; idx < Capacity(); idx++ )
if ( ! table[idx].Empty() ) if ( ! table[idx].Empty() )
@ -785,7 +788,10 @@ void Dictionary::DumpKeys() const
else else
{ {
char key = char(random() % 26) + 'A'; char key = char(random() % 26) + 'A';
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
sprintf(key_file, "%d.%d.%zu-%d.ckey",Length(), max_distance, MemoryAllocation()/Length(), key); sprintf(key_file, "%d.%d.%zu-%d.ckey",Length(), max_distance, MemoryAllocation()/Length(), key);
#pragma GCC diagnostic pop
std::ofstream f(key_file, std::ios::out|std::ios::trunc); std::ofstream f(key_file, std::ios::out|std::ios::trunc);
for ( int idx = 0; idx < Capacity(); idx++ ) for ( int idx = 0; idx < Capacity(); idx++ )
if ( ! table[idx].Empty() ) if ( ! table[idx].Empty() )
@ -833,10 +839,13 @@ void Dictionary::Dump(int level) const
int distances[DICT_NUM_DISTANCES]; int distances[DICT_NUM_DISTANCES];
int max_distance = 0; int max_distance = 0;
DistanceStats(max_distance, distances, DICT_NUM_DISTANCES); DistanceStats(max_distance, distances, DICT_NUM_DISTANCES);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
printf("cap %'7d ent %'7d %'-7d load %.2f max_dist %2d mem %10zu mem/ent %3zu key/ent %3d lg %2d remaps %1d remap_end %4d ", printf("cap %'7d ent %'7d %'-7d load %.2f max_dist %2d mem %10zu mem/ent %3zu key/ent %3d lg %2d remaps %1d remap_end %4d ",
Capacity(), Length(), MaxLength(), (double)Length()/(table? Capacity() : 1), Capacity(), Length(), MaxLength(), (double)Length()/(table? Capacity() : 1),
max_distance, MemoryAllocation(), (MemoryAllocation())/(Length()?Length():1), key_size / (Length()?Length():1), max_distance, MemoryAllocation(), (MemoryAllocation())/(Length()?Length():1), key_size / (Length()?Length():1),
log2_buckets, remaps, remap_end); log2_buckets, remaps, remap_end);
#pragma GCC diagnostic pop
if ( Length() > 0 ) if ( Length() > 0 )
{ {
for (int i = 0; i < DICT_NUM_DISTANCES-1; i++) for (int i = 0; i < DICT_NUM_DISTANCES-1; i++)

View file

@ -337,6 +337,7 @@ public:
// Remove all entries. // Remove all entries.
void Clear(); void Clear();
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
size_t MemoryAllocation() const; size_t MemoryAllocation() const;
/// The capacity of the table, Buckets + Overflow Size. /// The capacity of the table, Buckets + Overflow Size.

View file

@ -83,6 +83,7 @@ public:
size_t Size() const { return fragments.size(); } size_t Size() const { return fragments.size(); }
size_t MaxFragments() const { return max_fragments; } size_t MaxFragments() const { return max_fragments; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
uint32_t MemoryAllocation() const; uint32_t MemoryAllocation() const;
private: private:

View file

@ -261,6 +261,7 @@ public:
int Size() const { return size; } int Size() const { return size; }
hash_t Hash() const { return hash; } hash_t Hash() const { return hash; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const { return padded_sizeof(*this) + util::pad_size(size); } unsigned int MemoryAllocation() const { return padded_sizeof(*this) + util::pad_size(size); }
static hash_t HashBytes(const void* bytes, int size); static hash_t HashBytes(const void* bytes, int size);

View file

@ -384,6 +384,7 @@ public:
*/ */
void ConvertToThreadingValue(threading::Value::addr_t* v) const; void ConvertToThreadingValue(threading::Value::addr_t* v) const;
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const { return padded_sizeof(*this); } unsigned int MemoryAllocation() const { return padded_sizeof(*this); }
/** /**
@ -646,6 +647,7 @@ public:
prefix.ConvertToThreadingValue(&v->prefix); prefix.ConvertToThreadingValue(&v->prefix);
} }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const { return padded_sizeof(*this); } unsigned int MemoryAllocation() const { return padded_sizeof(*this); }
/** /**

View file

@ -158,6 +158,7 @@ public:
return max_entries; return max_entries;
} }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
int MemoryAllocation() const int MemoryAllocation() const
{ return padded_sizeof(*this) + util::pad_size(max_entries * sizeof(T)); } { return padded_sizeof(*this) + util::pad_size(max_entries * sizeof(T)); }

View file

@ -157,9 +157,12 @@ void NFA_State::Dump(FILE* f)
unsigned int NFA_State::TotalMemoryAllocation() const unsigned int NFA_State::TotalMemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) return padded_sizeof(*this)
+ xtions.MemoryAllocation() - padded_sizeof(xtions) + xtions.MemoryAllocation() - padded_sizeof(xtions)
+ (epsclosure ? epsclosure->MemoryAllocation() : 0); + (epsclosure ? epsclosure->MemoryAllocation() : 0);
#pragma GCC diagnostic pop
} }
NFA_Machine::NFA_Machine(NFA_State* first, NFA_State* final) NFA_Machine::NFA_Machine(NFA_State* first, NFA_State* final)

View file

@ -62,6 +62,7 @@ public:
void Dump(FILE* f); void Dump(FILE* f);
// Recursivly count all the reachable states. // Recursivly count all the reachable states.
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int TotalMemoryAllocation() const; unsigned int TotalMemoryAllocation() const;
protected: protected:
@ -118,8 +119,14 @@ public:
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
void Dump(FILE* f); void Dump(FILE* f);
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const unsigned int MemoryAllocation() const
{ return padded_sizeof(*this) + first_state->TotalMemoryAllocation(); } {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) + first_state->TotalMemoryAllocation();
#pragma GCC diagnostic pop
}
protected: protected:
NFA_State* first_state; NFA_State* first_state;

View file

@ -416,14 +416,20 @@ unsigned int Specific_RE_Matcher::MemoryAllocation() const
{ {
unsigned int size = 0; unsigned int size = 0;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
for ( int i = 0; i < ccl_list.length(); ++i ) for ( int i = 0; i < ccl_list.length(); ++i )
size += ccl_list[i]->MemoryAllocation(); size += ccl_list[i]->MemoryAllocation();
#pragma GCC diagnostic pop
size += util::pad_size(sizeof(CCL*) * ccl_dict.size()); size += util::pad_size(sizeof(CCL*) * ccl_dict.size());
for ( const auto& entry : ccl_dict ) for ( const auto& entry : ccl_dict )
{ {
size += padded_sizeof(std::string) + util::pad_size(sizeof(std::string::value_type) * entry.first.size()); size += padded_sizeof(std::string) + util::pad_size(sizeof(std::string::value_type) * entry.first.size());
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
size += entry.second->MemoryAllocation(); size += entry.second->MemoryAllocation();
#pragma GCC diagnostic pop
} }
for ( const auto& entry : defs ) for ( const auto& entry : defs )
@ -432,6 +438,8 @@ unsigned int Specific_RE_Matcher::MemoryAllocation() const
size += padded_sizeof(std::string) + util::pad_size(sizeof(std::string::value_type) * entry.second.size()); size += padded_sizeof(std::string) + util::pad_size(sizeof(std::string::value_type) * entry.second.size());
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return size + padded_sizeof(*this) return size + padded_sizeof(*this)
+ (pattern_text ? util::pad_size(strlen(pattern_text) + 1) : 0) + (pattern_text ? util::pad_size(strlen(pattern_text) + 1) : 0)
+ ccl_list.MemoryAllocation() - padded_sizeof(ccl_list) + ccl_list.MemoryAllocation() - padded_sizeof(ccl_list)
@ -440,6 +448,7 @@ unsigned int Specific_RE_Matcher::MemoryAllocation() const
+ padded_sizeof(*any_ccl) + padded_sizeof(*any_ccl)
+ padded_sizeof(*accepted) // NOLINT(bugprone-sizeof-container) + padded_sizeof(*accepted) // NOLINT(bugprone-sizeof-container)
+ accepted->size() * padded_sizeof(AcceptingSet::key_type); + accepted->size() * padded_sizeof(AcceptingSet::key_type);
#pragma GCC diagnostic pop
} }
static RE_Matcher* matcher_merge(const RE_Matcher* re1, const RE_Matcher* re2, static RE_Matcher* matcher_merge(const RE_Matcher* re1, const RE_Matcher* re2,

View file

@ -115,6 +115,7 @@ public:
void Dump(FILE* f); void Dump(FILE* f);
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const; unsigned int MemoryAllocation() const;
protected: protected:
@ -232,11 +233,15 @@ public:
// the main ("explicit") constructor was used. // the main ("explicit") constructor was used.
const char* OrigText() const { return orig_text.c_str(); } const char* OrigText() const { return orig_text.c_str(); }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const unsigned int MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) return padded_sizeof(*this)
+ (re_anywhere ? re_anywhere->MemoryAllocation() : 0) + (re_anywhere ? re_anywhere->MemoryAllocation() : 0)
+ (re_exact ? re_exact->MemoryAllocation() : 0); + (re_exact ? re_exact->MemoryAllocation() : 0);
#pragma GCC diagnostic pop
} }
protected: protected:

View file

@ -282,9 +282,11 @@ public:
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
// Sum over all data buffered in some reassembler. // Sum over all data buffered in some reassembler.
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
static uint64_t TotalMemoryAllocation() { return total_size; } static uint64_t TotalMemoryAllocation() { return total_size; }
// Data buffered by type of reassembler. // Data buffered by type of reassembler.
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
static uint64_t MemoryAllocation(ReassemblerType rtype); static uint64_t MemoryAllocation(ReassemblerType rtype);
void SetMaxOldBlocks(uint32_t count) { max_old_blocks = count; } void SetMaxOldBlocks(uint32_t count) { max_old_blocks = count; }

View file

@ -127,7 +127,10 @@ void ProfileLogger::Log()
run_state::network_time, (utime + stime) - (first_utime + first_stime), run_state::network_time, (utime + stime) - (first_utime + first_stime),
utime - first_utime, stime - first_stime, rtime - first_rtime)); utime - first_utime, stime - first_stime, rtime - first_rtime));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int conn_mem_use = expensive ? session_mgr->SessionMemoryUsage() : 0; int conn_mem_use = expensive ? session_mgr->SessionMemoryUsage() : 0;
#pragma GCC diagnostic pop
double avg_conn_mem_use = 0; double avg_conn_mem_use = 0;
if ( expensive && session_mgr->CurrentSessions() != 0 ) if ( expensive && session_mgr->CurrentSessions() != 0 )
@ -135,6 +138,8 @@ void ProfileLogger::Log()
// TODO: This previously output the number of connections, but now that we're storing sessions // TODO: This previously output the number of connections, but now that we're storing sessions
// as well as connections, this might need to be renamed. // as well as connections, this might need to be renamed.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
file->Write(util::fmt("%.06f Conns: total=%" PRIu64 " current=%" PRIu64 "/%" PRIi32 " mem=%" PRIi32 "K avg=%.1f table=%" PRIu32 "K connvals=%" PRIu32 "K\n", file->Write(util::fmt("%.06f Conns: total=%" PRIu64 " current=%" PRIu64 "/%" PRIi32 " mem=%" PRIi32 "K avg=%.1f table=%" PRIu32 "K connvals=%" PRIu32 "K\n",
run_state::network_time, run_state::network_time,
Connection::TotalConnections(), Connection::TotalConnections(),
@ -145,6 +150,7 @@ void ProfileLogger::Log()
expensive ? session_mgr->MemoryAllocation() / 1024 : 0, expensive ? session_mgr->MemoryAllocation() / 1024 : 0,
expensive ? session_mgr->SessionMemoryUsageVals() / 1024 : 0 expensive ? session_mgr->SessionMemoryUsageVals() / 1024 : 0
)); ));
#pragma GCC diagnostic pop
session::Stats s; session::Stats s;
session_mgr->GetStats(s); session_mgr->GetStats(s);
@ -178,8 +184,11 @@ void ProfileLogger::Log()
file->Write(util::fmt("%.06f Connections expired due to inactivity: %" PRIu64 "\n", file->Write(util::fmt("%.06f Connections expired due to inactivity: %" PRIu64 "\n",
run_state::network_time, killed_by_inactivity)); run_state::network_time, killed_by_inactivity));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
file->Write(util::fmt("%.06f Total reassembler data: %" PRIu64 "K\n", run_state::network_time, file->Write(util::fmt("%.06f Total reassembler data: %" PRIu64 "K\n", run_state::network_time,
Reassembler::TotalMemoryAllocation() / 1024)); Reassembler::TotalMemoryAllocation() / 1024));
#pragma GCC diagnostic pop
// Signature engine. // Signature engine.
if ( expensive && rule_matcher ) if ( expensive && rule_matcher )
@ -274,7 +283,10 @@ void ProfileLogger::Log()
{ {
const auto& v = id->GetVal(); const auto& v = id->GetVal();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
size = v->MemoryAllocation(); size = v->MemoryAllocation();
#pragma GCC diagnostic pop
mem += size; mem += size;
bool print = false; bool print = false;

View file

@ -335,6 +335,8 @@ unsigned int TypeList::MemoryAllocation() const
{ {
unsigned int size = 0; unsigned int size = 0;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
for ( const auto& t : types ) for ( const auto& t : types )
size += t->MemoryAllocation(); size += t->MemoryAllocation();
@ -343,6 +345,7 @@ unsigned int TypeList::MemoryAllocation() const
return Type::MemoryAllocation() return Type::MemoryAllocation()
+ padded_sizeof(*this) - padded_sizeof(Type) + padded_sizeof(*this) - padded_sizeof(Type)
+ size; + size;
#pragma GCC diagnostic pop
} }
int IndexType::MatchesIndex(detail::ListExpr* const index) const int IndexType::MatchesIndex(detail::ListExpr* const index) const

View file

@ -250,6 +250,7 @@ public:
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
virtual void DescribeReST(ODesc* d, bool roles_only = false) const; virtual void DescribeReST(ODesc* d, bool roles_only = false) const;
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
virtual unsigned MemoryAllocation() const; virtual unsigned MemoryAllocation() const;
void SetName(const std::string& arg_name) { name = arg_name; } void SetName(const std::string& arg_name) { name = arg_name; }
@ -347,6 +348,7 @@ public:
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:

View file

@ -816,7 +816,10 @@ AddrVal::~AddrVal()
unsigned int AddrVal::MemoryAllocation() const unsigned int AddrVal::MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) + addr_val->MemoryAllocation(); return padded_sizeof(*this) + addr_val->MemoryAllocation();
#pragma GCC diagnostic pop
} }
ValPtr AddrVal::SizeVal() const ValPtr AddrVal::SizeVal() const
@ -881,7 +884,10 @@ int SubNetVal::Width() const
unsigned int SubNetVal::MemoryAllocation() const unsigned int SubNetVal::MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) + subnet_val->MemoryAllocation(); return padded_sizeof(*this) + subnet_val->MemoryAllocation();
#pragma GCC diagnostic pop
} }
ValPtr SubNetVal::SizeVal() const ValPtr SubNetVal::SizeVal() const
@ -1003,7 +1009,10 @@ void StringVal::ValDescribe(ODesc* d) const
unsigned int StringVal::MemoryAllocation() const unsigned int StringVal::MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) + string_val->MemoryAllocation(); return padded_sizeof(*this) + string_val->MemoryAllocation();
#pragma GCC diagnostic pop
} }
StringValPtr StringVal::Replace( StringValPtr StringVal::Replace(
@ -1213,7 +1222,10 @@ void PatternVal::ValDescribe(ODesc* d) const
unsigned int PatternVal::MemoryAllocation() const unsigned int PatternVal::MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return padded_sizeof(*this) + re_val->MemoryAllocation(); return padded_sizeof(*this) + re_val->MemoryAllocation();
#pragma GCC diagnostic pop
} }
ValPtr PatternVal::DoClone(CloneState* state) ValPtr PatternVal::DoClone(CloneState* state)
@ -1326,12 +1338,15 @@ ValPtr ListVal::DoClone(CloneState* state)
unsigned int ListVal::MemoryAllocation() const unsigned int ListVal::MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
unsigned int size = 0; unsigned int size = 0;
for ( const auto& val : vals ) for ( const auto& val : vals )
size += val->MemoryAllocation(); size += val->MemoryAllocation();
size += util::pad_size(vals.capacity() * sizeof(decltype(vals)::value_type)); size += util::pad_size(vals.capacity() * sizeof(decltype(vals)::value_type));
return size + padded_sizeof(*this) + type->MemoryAllocation(); return size + padded_sizeof(*this) + type->MemoryAllocation();
#pragma GCC diagnostic pop
} }
TableEntryVal* TableEntryVal::Clone(Val::CloneState* state) TableEntryVal* TableEntryVal::Clone(Val::CloneState* state)
@ -2764,6 +2779,8 @@ unsigned int TableVal::MemoryAllocation() const
{ {
unsigned int size = 0; unsigned int size = 0;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
for ( const auto& ve : *table_val ) for ( const auto& ve : *table_val )
{ {
auto* tv = ve.GetValue<TableEntryVal*>(); auto* tv = ve.GetValue<TableEntryVal*>();
@ -2774,6 +2791,7 @@ unsigned int TableVal::MemoryAllocation() const
return size + padded_sizeof(*this) + table_val->MemoryAllocation() return size + padded_sizeof(*this) + table_val->MemoryAllocation()
+ table_hash->MemoryAllocation(); + table_hash->MemoryAllocation();
#pragma GCC diagnostic pop
} }
std::unique_ptr<detail::HashKey> TableVal::MakeHashKey(const Val& index) const std::unique_ptr<detail::HashKey> TableVal::MakeHashKey(const Val& index) const
@ -3139,7 +3157,10 @@ unsigned int RecordVal::MemoryAllocation() const
{ {
auto f_i = GetField(i); auto f_i = GetField(i);
if ( f_i ) if ( f_i )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
size += f_i->MemoryAllocation(); size += f_i->MemoryAllocation();
#pragma GCC diagnostic pop
} }
size += util::pad_size(record_val->capacity() * sizeof(ZVal)); size += util::pad_size(record_val->capacity() * sizeof(ZVal));

View file

@ -112,6 +112,7 @@ public:
virtual ValPtr SizeVal() const; virtual ValPtr SizeVal() const;
// Bytes in total value object. // Bytes in total value object.
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
virtual unsigned int MemoryAllocation() const; virtual unsigned int MemoryAllocation() const;
// Add this value to the given value (if appropriate). // Add this value to the given value (if appropriate).
@ -486,6 +487,7 @@ public:
const IPAddr& Get() const { return *addr_val; } const IPAddr& Get() const { return *addr_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
@ -515,6 +517,7 @@ public:
const IPPrefix& Get() const { return *subnet_val; } const IPPrefix& Get() const { return *subnet_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
@ -549,6 +552,7 @@ public:
const String* Get() const { return string_val; } const String* Get() const { return string_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
StringValPtr Replace(RE_Matcher* re, const String& repl, StringValPtr Replace(RE_Matcher* re, const String& repl,
@ -610,6 +614,7 @@ public:
const RE_Matcher* Get() const { return re_val; } const RE_Matcher* Get() const { return re_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
@ -659,6 +664,7 @@ public:
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
@ -932,6 +938,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);
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
void ClearTimer(detail::Timer* t) void ClearTimer(detail::Timer* t)
@ -1399,6 +1406,7 @@ public:
RecordValPtr CoerceTo(RecordTypePtr other, RecordValPtr CoerceTo(RecordTypePtr other,
bool allow_orphaning = false); bool allow_orphaning = false);
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
void DescribeReST(ODesc* d) const override; void DescribeReST(ODesc* d) const override;

View file

@ -130,6 +130,7 @@ public:
// XXX and to_upper; the latter doesn't use String::ToUpper(). // XXX and to_upper; the latter doesn't use String::ToUpper().
void ToUpper(); void ToUpper();
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const; unsigned int MemoryAllocation() const;
// Returns new string containing the substring of this string, // Returns new string containing the substring of this string,

View file

@ -764,6 +764,8 @@ void Analyzer::AppendNewChildren()
unsigned int Analyzer::MemoryAllocation() const unsigned int Analyzer::MemoryAllocation() const
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
unsigned int mem = padded_sizeof(*this) unsigned int mem = padded_sizeof(*this)
+ (timers.MemoryAllocation() - padded_sizeof(timers)); + (timers.MemoryAllocation() - padded_sizeof(timers));
@ -777,6 +779,7 @@ unsigned int Analyzer::MemoryAllocation() const
mem += a->MemoryAllocation(); mem += a->MemoryAllocation();
return mem; return mem;
#pragma GCC diagnostic pop
} }
void Analyzer::UpdateConnVal(RecordVal *conn_val) void Analyzer::UpdateConnVal(RecordVal *conn_val)

View file

@ -595,6 +595,7 @@ public:
/** /**
* Internal method. * Internal method.
*/ */
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
virtual unsigned int MemoryAllocation() const; virtual unsigned int MemoryAllocation() const;
protected: protected:

View file

@ -293,7 +293,10 @@ unsigned int Manager::SessionMemoryUsage()
return 0; return 0;
for ( const auto& entry : session_map ) for ( const auto& entry : session_map )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
mem += entry.second->MemoryAllocation(); mem += entry.second->MemoryAllocation();
#pragma GCC diagnostic pop
return mem; return mem;
} }
@ -307,7 +310,10 @@ unsigned int Manager::SessionMemoryUsageVals()
return 0; return 0;
for ( const auto& entry : session_map ) for ( const auto& entry : session_map )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
mem += entry.second->MemoryAllocationVal(); mem += entry.second->MemoryAllocationVal();
#pragma GCC diagnostic pop
return mem; return mem;
} }
@ -318,12 +324,15 @@ unsigned int Manager::MemoryAllocation()
// Connections have been flushed already. // Connections have been flushed already.
return 0; return 0;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return SessionMemoryUsage() return SessionMemoryUsage()
+ padded_sizeof(*this) + padded_sizeof(*this)
+ (session_map.size() * (sizeof(SessionMap::key_type) + sizeof(SessionMap::value_type))) + (session_map.size() * (sizeof(SessionMap::key_type) + sizeof(SessionMap::value_type)))
+ zeek::detail::fragment_mgr->MemoryAllocation(); + zeek::detail::fragment_mgr->MemoryAllocation();
// FIXME: MemoryAllocation() not implemented for rest. // FIXME: MemoryAllocation() not implemented for rest.
; ;
#pragma GCC diagnostic pop
} }
void Manager::InsertSession(detail::Key key, Session* session) void Manager::InsertSession(detail::Key key, Session* session)

View file

@ -92,14 +92,29 @@ public:
[[deprecated("Remove in v5.1. Use CurrentSessions().")]] [[deprecated("Remove in v5.1. Use CurrentSessions().")]]
unsigned int CurrentConnections() { return CurrentSessions(); } unsigned int CurrentConnections() { return CurrentSessions(); }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int SessionMemoryUsage(); unsigned int SessionMemoryUsage();
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int SessionMemoryUsageVals(); unsigned int SessionMemoryUsageVals();
[[deprecated("Remove in v5.1. Use SessionMemoryUsage().")]] [[deprecated("Remove in v5.1. Use SessionMemoryUsage().")]]
unsigned int ConnectionMemoryUsage() { return SessionMemoryUsage(); } unsigned int ConnectionMemoryUsage()
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return SessionMemoryUsage();
#pragma GCC diagnostic pop
}
[[deprecated("Remove in v5.1. Use SessionMemoryUsageVals().")]] [[deprecated("Remove in v5.1. Use SessionMemoryUsageVals().")]]
unsigned int ConnectionMemoryUsageConnVals() { return SessionMemoryUsageVals(); } unsigned int ConnectionMemoryUsageConnVals()
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return SessionMemoryUsageVals();
#pragma GCC diagnostic pop
}
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation(); unsigned int MemoryAllocation();
private: private:

View file

@ -105,14 +105,22 @@ public:
* Return the memory allocation required by the session record. This requires at * Return the memory allocation required by the session record. This requires at
* least one call to Get() first in order to setup the record object. * least one call to Get() first in order to setup the record object.
*/ */
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
virtual unsigned int MemoryAllocationVal() const = 0; virtual unsigned int MemoryAllocationVal() const = 0;
[[deprecated("Remove in v5.1. Use MemoryAllocationVal().")]] [[deprecated("Remove in v5.1. Use MemoryAllocationVal().")]]
unsigned int MemoryAllocationConnVal() const { return MemoryAllocationVal(); } unsigned int MemoryAllocationConnVal() const
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return MemoryAllocationVal();
#pragma GCC diagnostic pop
}
/** /**
* A lower-bound calculation of how much memory a session object is using. * A lower-bound calculation of how much memory a session object is using.
*/ */
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
virtual unsigned int MemoryAllocation() const; virtual unsigned int MemoryAllocation() const;
/** /**

View file

@ -220,10 +220,13 @@ function get_reassembler_stats%(%): ReassemblerStats
auto r = zeek::make_intrusive<zeek::RecordVal>(ReassemblerStats); auto r = zeek::make_intrusive<zeek::RecordVal>(ReassemblerStats);
int n = 0; int n = 0;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_FILE)); r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_FILE));
r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_FRAG)); r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_FRAG));
r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_TCP)); r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_TCP));
r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_UNKNOWN)); r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_UNKNOWN));
#pragma GCC diagnostic pop
return r; return r;
%} %}

View file

@ -1256,9 +1256,12 @@ function same_object%(o1: any, o2: any%): bool
## v: The value ## v: The value
## ##
## Returns: The number of bytes that *v* occupies. ## Returns: The number of bytes that *v* occupies.
function val_size%(v: any%): count function val_size%(v: any%): count &deprecated="Remove in v5.1. MemoryAllocation() is deprecated and will be removed."
%{ %{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return zeek::val_mgr->Count(v->MemoryAllocation()); return zeek::val_mgr->Count(v->MemoryAllocation());
#pragma GCC diagnostic pop
%} %}
## Resizes a vector. ## Resizes a vector.
@ -1946,7 +1949,7 @@ function packet_source%(%): PacketSource
## Returns: A table that maps variable names to their sizes. ## Returns: A table that maps variable names to their sizes.
## ##
## .. zeek:see:: global_ids ## .. zeek:see:: global_ids
function global_sizes%(%): var_sizes function global_sizes%(%): var_sizes &deprecated="Remove in v5.1. MemoryAllocation() is deprecated and will be removed."
%{ %{
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();
@ -1957,7 +1960,10 @@ function global_sizes%(%): var_sizes
if ( id->HasVal() ) if ( id->HasVal() )
{ {
auto id_name = zeek::make_intrusive<zeek::StringVal>(id->Name()); auto id_name = zeek::make_intrusive<zeek::StringVal>(id->Name());
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
auto id_size = zeek::val_mgr->Count(id->GetVal()->MemoryAllocation()); auto id_size = zeek::val_mgr->Count(id->GetVal()->MemoryAllocation());
#pragma GCC diagnostic pop
sizes->Assign(std::move(id_name), std::move(id_size)); sizes->Assign(std::move(id_name), std::move(id_size));
} }
} }