Move Stats and related classes to zeek::detail

This commit is contained in:
Tim Wojtulewicz 2020-07-21 17:18:21 -07:00
parent c9ab1f93e7
commit fdcb2760b2
12 changed files with 75 additions and 41 deletions

View file

@ -285,7 +285,7 @@ void Connection::InactivityTimer(double t)
{
Event(connection_timeout, nullptr);
sessions->Remove(this);
++killed_by_inactivity;
++zeek::detail::killed_by_inactivity;
}
else
ADD_TIMER(&Connection::InactivityTimer,

View file

@ -160,7 +160,7 @@ void EventMgr::Drain()
if ( event_queue_flush_point )
Enqueue(event_queue_flush_point, zeek::Args{});
SegmentProfiler prof(segment_logger, "draining-events");
zeek::detail::SegmentProfiler prof(zeek::detail::segment_logger, "draining-events");
PLUGIN_HOOK_VOID(HOOK_DRAIN_EVENTS, HookDrainEvents());

View file

@ -212,7 +212,7 @@ void net_init(const std::optional<std::string>& interface,
void expire_timers(iosource::PktSrc* src_ps)
{
SegmentProfiler prof(segment_logger, "expiring-timers");
zeek::detail::SegmentProfiler prof(zeek::detail::segment_logger, "expiring-timers");
current_dispatched +=
zeek::detail::timer_mgr->Advance(network_time,
@ -238,7 +238,7 @@ void net_packet_dispatch(double t, const zeek::Packet* pkt, iosource::PktSrc* sr
expire_timers(src_ps);
SegmentProfiler* sp = nullptr;
zeek::detail::SegmentProfiler* sp = nullptr;
if ( load_sample )
{
@ -253,8 +253,8 @@ void net_packet_dispatch(double t, const zeek::Packet* pkt, iosource::PktSrc* sr
// charged against this sample.
zeek::event_mgr.Drain();
sample_logger = new SampleLogger();
sp = new SegmentProfiler(sample_logger, "load-samp");
zeek::detail::sample_logger = new zeek::detail::SampleLogger();
sp = new zeek::detail::SegmentProfiler(zeek::detail::sample_logger, "load-samp");
}
}
@ -264,8 +264,8 @@ void net_packet_dispatch(double t, const zeek::Packet* pkt, iosource::PktSrc* sr
if ( sp )
{
delete sp;
delete sample_logger;
sample_logger = nullptr;
delete zeek::detail::sample_logger;
zeek::detail::sample_logger = nullptr;
}
processing_start_time = 0.0; // = "we're not processing now"

View file

@ -84,7 +84,7 @@ NetSessions::NetSessions()
static auto pkt_profile_file = zeek::id::find_val("pkt_profile_file");
if ( pkt_profile_mode && pkt_profile_freq > 0 && pkt_profile_file )
pkt_profiler = new PacketProfiler(pkt_profile_mode,
pkt_profiler = new zeek::detail::PacketProfiler(pkt_profile_mode,
pkt_profile_freq, pkt_profile_file->AsFile());
else
pkt_profiler = nullptr;
@ -121,7 +121,7 @@ void NetSessions::Done()
void NetSessions::NextPacket(double t, const zeek::Packet* pkt)
{
SegmentProfiler prof(segment_logger, "dispatching-packet");
zeek::detail::SegmentProfiler prof(zeek::detail::segment_logger, "dispatching-packet");
if ( raw_packet )
zeek::event_mgr.Enqueue(raw_packet, pkt->ToRawPktHdrVal());

View file

@ -15,7 +15,7 @@
ZEEK_FORWARD_DECLARE_NAMESPACED(EncapsulationStack, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(EncapsulatingConn, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(Packet, zeek);
class PacketProfiler;
ZEEK_FORWARD_DECLARE_NAMESPACED(PacketProfiler, zeek::detail);
class Connection;
class ConnCompressor;
struct ConnID;
@ -235,7 +235,7 @@ protected:
zeek::detail::Discarder* discarder;
zeek::detail::PacketFilter* packet_filter;
uint64_t num_packets_processed;
PacketProfiler* pkt_profiler;
zeek::detail::PacketProfiler* pkt_profiler;
bool dump_this_packet; // if true, current packet should be recorded
};

View file

@ -15,13 +15,19 @@
#include "input.h"
#include "Func.h"
uint64_t killed_by_inactivity = 0;
uint64_t zeek::detail::killed_by_inactivity = 0;
uint64_t& killed_by_inactivity = zeek::detail::killed_by_inactivity;
uint64_t tot_ack_events = 0;
uint64_t tot_ack_bytes = 0;
uint64_t tot_gap_events = 0;
uint64_t tot_gap_bytes = 0;
uint64_t zeek::detail::tot_ack_events = 0;
uint64_t& tot_ack_events = zeek::detail::tot_ack_events;
uint64_t zeek::detail::tot_ack_bytes = 0;
uint64_t& tot_ack_bytes = zeek::detail::tot_ack_bytes;
uint64_t zeek::detail::tot_gap_events = 0;
uint64_t& tot_gap_events = zeek::detail::tot_gap_events;
uint64_t zeek::detail::tot_gap_bytes = 0;
uint64_t& tot_gap_bytes = zeek::detail::tot_gap_bytes;
namespace zeek::detail {
class ProfileTimer final : public zeek::detail::Timer {
public:
@ -482,3 +488,5 @@ void PacketProfiler::ProfilePkt(double t, unsigned int bytes)
byte_cnt += bytes;
time = t;
}
} // namespace zeek::detail

View file

@ -16,6 +16,8 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(TableVal, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(Location, zeek::detail);
namespace zeek::detail {
// Object called by SegmentProfiler when it is done and reports its
// cumulative CPU/memory statistics.
class SegmentStatsReporter {
@ -140,3 +142,24 @@ protected:
uint64_t pkt_cnt;
uint64_t byte_cnt;
};
} // namespace zeek::detail
using SegmentStatsReporter [[deprecated("Remove in v4.1. Use zeek::detail::SegmentStatsReporter.")]] = zeek::detail::SegmentStatsReporter;
using SegmentProfiler [[deprecated("Remove in v4.1. Use zeek::detail::SegmentProfiler.")]] = zeek::detail::SegmentProfiler;
using ProfileLogger [[deprecated("Remove in v4.1. Use zeek::detail::ProfileLogger.")]] = zeek::detail::ProfileLogger;
using SampleLogger [[deprecated("Remove in v4.1. Use zeek::detail::SampleLogger.")]] = zeek::detail::SampleLogger;
using PacketProfiler [[deprecated("Remove in v4.1. Use zeek::detail::PacketProfiler.")]] = zeek::detail::PacketProfiler;
extern zeek::detail::ProfileLogger*& profiling_logger [[deprecated("Remove in v4.1. Use zeek::detail::profiling_logger.")]];
extern zeek::detail::ProfileLogger*& segment_logger [[deprecated("Remove in v4.1. Use zeek::detail::segment_logger.")]];
extern zeek::detail::SampleLogger*& sample_logger [[deprecated("Remove in v4.1. Use zeek::detail::sample_logger.")]];
// Connection statistics.
extern uint64_t& killed_by_inactivity [[deprecated("Remove in v4.1. Use zeek::detail::killed_by_inactivity.")]];
// Content gap statistics.
extern uint64_t& tot_ack_events [[deprecated("Remove in v4.1. Use zeek::detail::tot_ack_events.")]];
extern uint64_t& tot_ack_bytes [[deprecated("Remove in v4.1. Use zeek::detail::tot_ack_bytes.")]];
extern uint64_t& tot_gap_events [[deprecated("Remove in v4.1. Use zeek::detail::tot_gap_events.")]];
extern uint64_t& tot_gap_bytes [[deprecated("Remove in v4.1. Use zeek::detail::tot_gap_bytes.")]];

View file

@ -542,13 +542,13 @@ void TCP_Reassembler::AckReceived(uint64_t seq)
if ( test_active )
{
++tot_ack_events;
tot_ack_bytes += seq - trim_seq;
++zeek::detail::tot_ack_events;
zeek::detail::tot_ack_bytes += seq - trim_seq;
if ( num_missing > 0 )
{
++tot_gap_events;
tot_gap_bytes += num_missing;
++zeek::detail::tot_gap_events;
zeek::detail::tot_gap_bytes += num_missing;
}
}

View file

@ -22,8 +22,8 @@ int main(int argc, char** argv)
if ( do_net_run )
{
if ( profiling_logger )
profiling_logger->Log();
if ( zeek::detail::profiling_logger )
zeek::detail::profiling_logger->Log();
#ifdef USE_PERFTOOLS_DEBUG
if ( perftools_leaks )

View file

@ -110,7 +110,7 @@ function get_conn_stats%(%): ConnStats
ADD_STAT(s.max_ICMP_conns);
ADD_STAT(s.cumulative_ICMP_conns);
r->Assign(n++, zeek::val_mgr->Count(killed_by_inactivity));
r->Assign(n++, zeek::val_mgr->Count(zeek::detail::killed_by_inactivity));
return r;
%}
@ -365,10 +365,10 @@ function get_gap_stats%(%): GapStats
auto r = zeek::make_intrusive<zeek::RecordVal>(GapStats);
int n = 0;
r->Assign(n++, zeek::val_mgr->Count(tot_ack_events));
r->Assign(n++, zeek::val_mgr->Count(tot_ack_bytes));
r->Assign(n++, zeek::val_mgr->Count(tot_gap_events));
r->Assign(n++, zeek::val_mgr->Count(tot_gap_bytes));
r->Assign(n++, zeek::val_mgr->Count(zeek::detail::tot_ack_events));
r->Assign(n++, zeek::val_mgr->Count(zeek::detail::tot_ack_bytes));
r->Assign(n++, zeek::val_mgr->Count(zeek::detail::tot_gap_events));
r->Assign(n++, zeek::val_mgr->Count(zeek::detail::tot_gap_bytes));
return r;
%}

View file

@ -116,9 +116,12 @@ std::vector<std::string> zeek_script_prefixes;
zeek::detail::Stmt* stmts;
zeek::EventRegistry* zeek::event_registry = nullptr;
zeek::EventRegistry*& event_registry = zeek::event_registry;
ProfileLogger* profiling_logger = nullptr;
ProfileLogger* segment_logger = nullptr;
SampleLogger* sample_logger = nullptr;
zeek::detail::ProfileLogger* zeek::detail::profiling_logger = nullptr;
zeek::detail::ProfileLogger*& profiling_logger = zeek::detail::profiling_logger;
zeek::detail::ProfileLogger* zeek::detail::segment_logger = nullptr;
zeek::detail::ProfileLogger*& segment_logger = zeek::detail::segment_logger;
zeek::detail::SampleLogger* zeek::detail::sample_logger = nullptr;
zeek::detail::SampleLogger*& sample_logger = zeek::detail::sample_logger;
int signal_val = 0;
extern char version[];
const char* command_line_policy = nullptr;
@ -236,8 +239,8 @@ void done_with_network()
true);
}
if ( profiling_logger )
profiling_logger->Log();
if ( zeek::detail::profiling_logger )
zeek::detail::profiling_logger->Log();
terminating = true;
@ -287,14 +290,14 @@ void terminate_bro()
zeek::detail::timer_mgr->Expire();
zeek::event_mgr.Drain();
if ( profiling_logger )
if ( zeek::detail::profiling_logger )
{
// FIXME: There are some occasional crashes in the memory
// allocation code when killing Bro. Disabling this for now.
if ( ! (signal_val == SIGTERM || signal_val == SIGINT) )
profiling_logger->Log();
zeek::detail::profiling_logger->Log();
delete profiling_logger;
delete zeek::detail::profiling_logger;
}
zeek::event_mgr.Drain();
@ -794,11 +797,11 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
if ( profiling_interval > 0 )
{
const auto& profiling_file = zeek::id::find_val("profiling_file");
profiling_logger = new ProfileLogger(profiling_file->AsFile(),
profiling_interval);
zeek::detail::profiling_logger = new ProfileLogger(profiling_file->AsFile(),
profiling_interval);
if ( segment_profiling )
segment_logger = profiling_logger;
zeek::detail::segment_logger = zeek::detail::profiling_logger;
}
if ( ! reading_live && ! reading_traces )

View file

@ -2030,8 +2030,8 @@ function record_fields%(rec: any%): record_field_table
## get_timer_stats
function do_profiling%(%) : any
%{
if ( profiling_logger )
profiling_logger->Log();
if ( zeek::detail::profiling_logger )
zeek::detail::profiling_logger->Log();
return nullptr;
%}