zeek/src/Stats.h
Arne Welzel 3f7881a57b segment_profiling: Remove SegmentProfiler and load_sample event
While it seems interesting functionality, this hasn't been documented,
maintained or knowingly leveraged for many years.

There are various other approaches today, too:

* We track the number of event handler invocations regardless of
  profiling. It's possible to approximate a load_sample event by
  comparing the result of two get_event_stats() calls. Or, visualize
  the corresponding counters in a Prometheus setup to get an idea of
  event/s broken down by event names.

* HookCallFunction() allows to intercept script execution, including
  measuring the time execution takes.

* The global call_stack and g_frame_stack can be used from plugins
  (and even external processes) to walk the Zeek script stack at certain
  points to implement a sampling profiler.

* USDT probes or more plugin hooks will likely be preferred over Zeek
  builtin functionality in the future.

Relates to #3458
2024-01-03 11:55:54 +01:00

65 lines
1.3 KiB
C++

// Classes that collect and report statistics.
#pragma once
#include "zeek/zeek-config.h"
#include <cstdint>
#include <memory>
namespace zeek {
class File;
namespace detail {
class Location;
class ProfileLogger final {
public:
ProfileLogger(zeek::File* file, double interval);
~ProfileLogger();
void Log();
zeek::File* File() { return file; }
private:
zeek::File* file;
unsigned int log_count;
};
extern std::shared_ptr<ProfileLogger> profiling_logger;
// Connection statistics.
extern uint64_t killed_by_inactivity;
// Content gap statistics.
extern uint64_t tot_ack_events;
extern uint64_t tot_ack_bytes;
extern uint64_t tot_gap_events;
extern uint64_t tot_gap_bytes;
class PacketProfiler {
public:
PacketProfiler(unsigned int mode, double freq, File* arg_file);
~PacketProfiler();
static const unsigned int MODE_TIME = 1;
static const unsigned int MODE_PACKET = 2;
static const unsigned int MODE_VOLUME = 3;
void ProfilePkt(double t, unsigned int bytes);
protected:
File* file;
unsigned int update_mode;
double update_freq;
double last_Utime, last_Stime, last_Rtime;
double last_timestamp, time;
uint64_t last_mem;
uint64_t pkt_cnt;
uint64_t byte_cnt;
};
} // namespace detail
} // namespace zeek