|
|
@ -135,59 +135,109 @@ struct mapped_buffer { |
|
|
|
[[nodiscard]] size_t size() const { return _size; } |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy type directing how buffers are allocated. This directs the buffer strategy to use a standard container to allocate. |
|
|
|
*/ |
|
|
|
struct BufferStrategyInternal { |
|
|
|
using buffer_type = std::vector<char>; |
|
|
|
static_assert(BufferLike<buffer_type>); |
|
|
|
buffer_type build_buffer(size_t); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that employs a memory mapped buffer to manage its memory. Said buffer is expected to be read from the same process. |
|
|
|
*/ |
|
|
|
struct BufferStrategyShared { |
|
|
|
using buffer_type = mapped_buffer; |
|
|
|
static_assert(BufferLike<buffer_type>); |
|
|
|
buffer_type build_buffer(size_t); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that employs a memory mapped buffer to manage its memory. Said buffer is expected to be read from a different process. |
|
|
|
*/ |
|
|
|
struct BufferStrategyExternal { |
|
|
|
using buffer_type = mapped_buffer; |
|
|
|
static_assert(BufferLike<buffer_type>); |
|
|
|
buffer_type build_buffer(size_t); |
|
|
|
}; |
|
|
|
|
|
|
|
/* * ... * */ |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that makes the sink flush at every write, making the IO to disk as soon as possible. |
|
|
|
*/ |
|
|
|
struct SinkStrategyDirect { |
|
|
|
void write(int fd, std::string_view data); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that makes the sink write with the settings that have the highest throughput. |
|
|
|
*/ |
|
|
|
struct SinkStrategyFastest { |
|
|
|
void write(int fd, std::string_view data); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that makes the sink write using memory mapped IO, making the IO always commit to system pages before returning. |
|
|
|
*/ |
|
|
|
struct SinkStrategyMmaped { |
|
|
|
void write(int fd, std::string_view data); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that makes the sink do nothing, expecting another process to handle the process. |
|
|
|
*/ |
|
|
|
struct SinkStrategyExternal { |
|
|
|
void write(int fd, std::string_view data); |
|
|
|
}; |
|
|
|
|
|
|
|
/* * ... * */ |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that makes overflowing waiting. The waiting is handled by exponential backoff of factor 1.5 |
|
|
|
*/ |
|
|
|
struct OverflowStrategyWait { |
|
|
|
static constexpr overflow_response_t on_overflow = overflow_response_t::must_wait; |
|
|
|
void wait(); |
|
|
|
}; |
|
|
|
/** |
|
|
|
* @brief a strategy that makes overflowing overwrite the data, possibly corrupting the generated log, without waiting. |
|
|
|
*/ |
|
|
|
struct OverflowStrategyContinue { |
|
|
|
static constexpr overflow_response_t on_overflow = overflow_response_t::must_overflow; |
|
|
|
void wait(); |
|
|
|
}; |
|
|
|
|
|
|
|
/* * ... * */ |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that controls how often new log files are generated. Logs are spaced by making them writable for only a certain amount of time. |
|
|
|
*/ |
|
|
|
struct OutputStrategyTimed { |
|
|
|
std::chrono::seconds interval; |
|
|
|
std::chrono::time_point<std::chrono::file_clock> last_change; |
|
|
|
std::string_view directory; |
|
|
|
std::optional<std::chrono::time_point<std::chrono::file_clock> > last_change = std::nullopt; |
|
|
|
|
|
|
|
std::pair<std::string_view, std::string_view> chunk(std::string_view); |
|
|
|
int on_write_completed_event(std::string_view, int); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that controls how often new log files are generated. Logs are spaced by making them at most one line longer that the amount of bytes specified. |
|
|
|
*/ |
|
|
|
struct OutputStrategySized { |
|
|
|
uint64_t interval; |
|
|
|
uint64_t written_bytes; |
|
|
|
std::string_view directory; |
|
|
|
uint64_t written_bytes = 0; |
|
|
|
|
|
|
|
std::pair<std::string_view, std::string_view> chunk(std::string_view); |
|
|
|
int on_write_completed_event(std::string_view, int); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief a strategy that makes the logs be generated in the same file all the time. |
|
|
|
*/ |
|
|
|
struct OutputStrategySimple { |
|
|
|
std::pair<std::string_view, std::string_view> chunk(std::string_view); |
|
|
|
int on_write_completed_event(std::string_view, int); |
|
|
|