2024-02-25 05:51:52 +00:00
|
|
|
// resource manager
|
|
|
|
//
|
|
|
|
// Date: 2024-02-25
|
|
|
|
//
|
|
|
|
// Resources in monitoring: memory
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <base/utils.h>
|
|
|
|
#include <base/packet.h>
|
|
|
|
|
2024-03-08 02:22:47 +00:00
|
|
|
// #define USE_MONITOR_THREAD
|
|
|
|
|
2024-02-25 05:51:52 +00:00
|
|
|
class resource_mgr
|
|
|
|
{
|
|
|
|
volatile bool run_ = true;
|
|
|
|
volatile bool monitor_ = false;
|
2024-03-08 07:04:10 +00:00
|
|
|
uint64_t mem_limit_ = SIZE_MB(2500);
|
2024-03-08 02:22:47 +00:00
|
|
|
volatile uint64_t mem_now_ = 0;
|
2024-02-25 05:51:52 +00:00
|
|
|
std::unique_ptr<std::thread> thread_;
|
|
|
|
|
|
|
|
void thread_monitor(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
resource_mgr();
|
|
|
|
~resource_mgr();
|
|
|
|
|
|
|
|
static std::string task_type(_task task);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void start(void);
|
|
|
|
void stop(void);
|
|
|
|
void set_memory_limit(uint64_t max_size = SIZE_GB(2));
|
|
|
|
bool is_resource_enable(_task task, bool wait = false, int to_ms = 0);
|
|
|
|
};
|
|
|
|
|