#include "managers/inspector_manager.h"
#include "managers/module_manager.h"
#include "managers/plugin_manager.h"
+#include "memory/memory_cap.h"
#include "packet_io/sfdaq.h"
#include "packet_io/sfdaq_config.h"
#include "packet_io/sfdaq_instance.h"
return 0;
}
+
+int main_dump_heap_stats(lua_State* L)
+{
+ ControlConn* ctrlcon = ControlConn::query_from_lua(L);
+ memory::MemoryCap::dump_mem_stats(ctrlcon);
+ return 0;
+}
+
int main_reset_stats(lua_State* L)
{
ControlConn* ctrlcon = ControlConn::query_from_lua(L);
// commands provided by the snort module
int main_delete_inspector(lua_State* = nullptr);
int main_dump_stats(lua_State* = nullptr);
+int main_dump_heap_stats(lua_State* = nullptr);
int main_reset_stats(lua_State* = nullptr);
int main_set_watchdog_params(lua_State* = nullptr);
int main_rotate_stats(lua_State* = nullptr);
"delete an inspector from the default policy" },
{ "dump_stats", main_dump_stats, nullptr, "show summary statistics" },
+ { "dump_heap_stats", main_dump_heap_stats, nullptr, "show heap statistics" },
{ "reset_stats", main_reset_stats, nullptr, "clear summary statistics" },
{ "rotate_stats", main_rotate_stats, nullptr, "roll perfmonitor log files" },
{ "reload_config", main_reload_config, s_reload_w_path, "load new configuration" },
#include "heap_interface.h"
#include <cassert>
+#include <cstring>
#ifdef HAVE_JEMALLOC
#include <jemalloc/jemalloc.h>
#endif
+#include "control/control.h"
+#include "log/messages.h"
#include "main/thread.h"
namespace memory
void get_process_total(uint64_t&, uint64_t&) override;
void get_thread_allocs(uint64_t&, uint64_t&) override;
+
+ void print_stats(ControlConn*) override;
+
};
static size_t stats_mib[2], mib_len = 2;
static THREAD_LOCAL uint64_t* alloc_ptr = nullptr;
static THREAD_LOCAL uint64_t* dealloc_ptr = nullptr;
+static ControlConn* s_ctrlconn = nullptr;
+static void log_jem_stats(void *,const char *buf)
+{
+ if (s_ctrlconn)
+ {
+ char tmp[STD_BUF];
+ const char* end = buf + strlen(buf);
+ for(const char* p = buf; p < end ;)
+ {
+ int n = (end - p > (STD_BUF - 1)) ? (STD_BUF - 1) : (end - p);
+ std::memcpy(tmp, p, n);
+ tmp[n] = '\0';
+ s_ctrlconn->respond("%s", tmp);
+ p += n;
+ }
+ }
+}
+
void JemallocInterface::main_init()
{
mallctlnametomib("stats.allocated", stats_mib, &mib_len);
dealloc = *dealloc_ptr;
}
+void JemallocInterface::print_stats(ControlConn* ctrlcon)
+{
+ s_ctrlconn = ctrlcon;
+ malloc_stats_print(log_jem_stats, nullptr, nullptr);
+}
+
//--------------------------------------------------------------------------
#else // disabled interface
//--------------------------------------------------------------------------
#include <cstdint>
+class ControlConn;
namespace memory
{
virtual void get_process_total(uint64_t& epoch, uint64_t& total) = 0;
virtual void get_thread_allocs(uint64_t& alloc, uint64_t& dealloc) = 0;
+ virtual void print_stats(ControlConn*) { }
static HeapInterface* get_instance();
protected:
}
}
+void MemoryCap::dump_mem_stats(ControlConn* ctrlcon)
+{
+ heap->print_stats(ctrlcon);
+}
} // namespace memory
#include "main/snort_types.h"
struct MemoryConfig;
+class ControlConn;
namespace memory
{
// main thread - shutdown
static void update_pegs(PegCount*);
+ static void dump_mem_stats(ControlConn*);
#if defined(REG_TEST) || defined(UNIT_TEST)
static void test_main_check();
#endif