mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
memory management fixes for loggers
This commit is contained in:
parent
41aee03c17
commit
fbe33d4ee9
3 changed files with 15 additions and 16 deletions
|
@ -251,7 +251,7 @@ void dispatch_packet(Packet* pkt, iosource::PktSrc* pkt_src)
|
||||||
// charged against this sample.
|
// charged against this sample.
|
||||||
event_mgr.Drain();
|
event_mgr.Drain();
|
||||||
|
|
||||||
zeek::detail::sample_logger = new zeek::detail::SampleLogger();
|
zeek::detail::sample_logger = std::make_shared<zeek::detail::SampleLogger>();
|
||||||
sp = new zeek::detail::SegmentProfiler(zeek::detail::sample_logger, "load-samp");
|
sp = new zeek::detail::SegmentProfiler(zeek::detail::sample_logger, "load-samp");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,6 @@ void dispatch_packet(Packet* pkt, iosource::PktSrc* pkt_src)
|
||||||
if ( sp )
|
if ( sp )
|
||||||
{
|
{
|
||||||
delete sp;
|
delete sp;
|
||||||
delete zeek::detail::sample_logger;
|
|
||||||
zeek::detail::sample_logger = nullptr;
|
zeek::detail::sample_logger = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
src/Stats.h
17
src/Stats.h
|
@ -8,6 +8,7 @@
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace zeek
|
namespace zeek
|
||||||
{
|
{
|
||||||
|
@ -41,15 +42,15 @@ class SegmentProfiler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// The constructor takes some way of identifying the segment.
|
// The constructor takes some way of identifying the segment.
|
||||||
SegmentProfiler(SegmentStatsReporter* arg_reporter, const char* arg_name)
|
SegmentProfiler(std::shared_ptr<SegmentStatsReporter> arg_reporter, const char* arg_name)
|
||||||
: reporter(arg_reporter), name(arg_name), loc(), initial_rusage()
|
: reporter(std::move(arg_reporter)), name(arg_name), loc(), initial_rusage()
|
||||||
{
|
{
|
||||||
if ( reporter )
|
if ( reporter )
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentProfiler(SegmentStatsReporter* arg_reporter, const Location* arg_loc)
|
SegmentProfiler(std::shared_ptr<SegmentStatsReporter> arg_reporter, const Location* arg_loc)
|
||||||
: reporter(arg_reporter), name(), loc(arg_loc), initial_rusage()
|
: reporter(std::move(arg_reporter)), name(), loc(arg_loc), initial_rusage()
|
||||||
{
|
{
|
||||||
if ( reporter )
|
if ( reporter )
|
||||||
Init();
|
Init();
|
||||||
|
@ -65,7 +66,7 @@ protected:
|
||||||
void Init();
|
void Init();
|
||||||
void Report();
|
void Report();
|
||||||
|
|
||||||
SegmentStatsReporter* reporter;
|
std::shared_ptr<SegmentStatsReporter> reporter;
|
||||||
const char* name;
|
const char* name;
|
||||||
const Location* loc;
|
const Location* loc;
|
||||||
struct rusage initial_rusage;
|
struct rusage initial_rusage;
|
||||||
|
@ -106,9 +107,9 @@ protected:
|
||||||
TableVal* load_samples;
|
TableVal* load_samples;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ProfileLogger* profiling_logger;
|
extern std::shared_ptr<ProfileLogger> profiling_logger;
|
||||||
extern ProfileLogger* segment_logger;
|
extern std::shared_ptr<ProfileLogger> segment_logger;
|
||||||
extern SampleLogger* sample_logger;
|
extern std::shared_ptr<SampleLogger> sample_logger;
|
||||||
|
|
||||||
// Connection statistics.
|
// Connection statistics.
|
||||||
extern uint64_t killed_by_inactivity;
|
extern uint64_t killed_by_inactivity;
|
||||||
|
|
|
@ -193,9 +193,9 @@ zeek::detail::trigger::Manager* zeek::detail::trigger_mgr = nullptr;
|
||||||
std::vector<std::string> zeek::detail::zeek_script_prefixes;
|
std::vector<std::string> zeek::detail::zeek_script_prefixes;
|
||||||
zeek::detail::Stmt* zeek::detail::stmts = nullptr;
|
zeek::detail::Stmt* zeek::detail::stmts = nullptr;
|
||||||
zeek::EventRegistry* zeek::event_registry = nullptr;
|
zeek::EventRegistry* zeek::event_registry = nullptr;
|
||||||
zeek::detail::ProfileLogger* zeek::detail::profiling_logger = nullptr;
|
std::shared_ptr<zeek::detail::ProfileLogger> zeek::detail::profiling_logger;
|
||||||
zeek::detail::ProfileLogger* zeek::detail::segment_logger = nullptr;
|
std::shared_ptr<zeek::detail::ProfileLogger> zeek::detail::segment_logger;
|
||||||
zeek::detail::SampleLogger* zeek::detail::sample_logger = nullptr;
|
std::shared_ptr<zeek::detail::SampleLogger> zeek::detail::sample_logger;
|
||||||
|
|
||||||
zeek::detail::FragmentManager* zeek::detail::fragment_mgr = nullptr;
|
zeek::detail::FragmentManager* zeek::detail::fragment_mgr = nullptr;
|
||||||
|
|
||||||
|
@ -403,8 +403,6 @@ static void terminate_zeek()
|
||||||
// allocation code when killing Zeek. Disabling this for now.
|
// allocation code when killing Zeek. Disabling this for now.
|
||||||
if ( ! (signal_val == SIGTERM || signal_val == SIGINT) )
|
if ( ! (signal_val == SIGTERM || signal_val == SIGINT) )
|
||||||
profiling_logger->Log();
|
profiling_logger->Log();
|
||||||
|
|
||||||
delete profiling_logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event_mgr.Drain();
|
event_mgr.Drain();
|
||||||
|
@ -976,7 +974,8 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
if ( profiling_interval > 0 )
|
if ( profiling_interval > 0 )
|
||||||
{
|
{
|
||||||
const auto& profiling_file = id::find_val("profiling_file");
|
const auto& profiling_file = id::find_val("profiling_file");
|
||||||
profiling_logger = new ProfileLogger(profiling_file->AsFile(), profiling_interval);
|
profiling_logger = std::make_shared<ProfileLogger>(profiling_file->AsFile(),
|
||||||
|
profiling_interval);
|
||||||
|
|
||||||
if ( segment_profiling )
|
if ( segment_profiling )
|
||||||
segment_logger = profiling_logger;
|
segment_logger = profiling_logger;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue