| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #ifndef SOPHIAR2_DEBUG_MACRO_H
- #define SOPHIAR2_DEBUG_MACRO_H
- #include "core/timestamp_helper.hpp"
- #include "third_party/scope_guard.hpp"
- #include "utility/versatile_buffer2.hpp"
- #include <boost/asio/awaitable.hpp>
- #include <boost/asio/high_resolution_timer.hpp>
- #include <boost/asio/this_coro.hpp>
- #include <boost/asio/use_awaitable.hpp>
- #include <boost/core/demangle.hpp>
- #include <spdlog/spdlog.h>
- #include <iostream>
- #define DEBUG_PRINT(msg) \
- std::cout << fmt::format("F:{} L:{} T:{} {}", \
- __FILE__, __LINE__, current_timestamp(), msg) \
- << std::endl
- #define FILE_LINE_TRACE DEBUG_PRINT("");
- #define FILE_LINE_TRACE_WITH_THIS \
- { \
- auto __msg = fmt::format("TH:{}", (void *) this); \
- DEBUG_PRINT(__msg); \
- }
- #define DEBUG_PRINT_ADDRESS(obj) \
- { \
- auto __msg = fmt::format("PTR:{}", (void *) std::addressof(obj)); \
- DEBUG_PRINT(__msg); \
- }
- #define DEBUG_PRINT_TYPE(type) \
- { \
- auto __msg = fmt::format("TYPE:{}", boost::core::demangle(typeid(type).name())); \
- DEBUG_PRINT(__msg); \
- }
- #define ENSURE(func) \
- { \
- bool ok = (func); \
- if (!ok) return false; \
- }
- #define ENSURE_CO(func) \
- { \
- bool ok = (func); \
- if (!ok) co_return false; \
- }
- #define CO_ENSURE(func) \
- { \
- bool ok = co_await (func); \
- if (!ok) { \
- co_return false; \
- } \
- }
- #define RUN_ONCE \
- static bool __is_called = false; \
- if (__is_called) [[likely]] return; \
- __is_called = true;
- namespace sophiar {
- using boost::asio::awaitable;
- using boost::asio::use_awaitable;
- template<typename DurationType>
- inline awaitable<void> coro_sleep(DurationType t) {
- boost::asio::high_resolution_timer timer(co_await boost::asio::this_coro::executor);
- timer.expires_from_now(t);
- co_await timer.async_wait(use_awaitable);
- co_return;
- }
- template<typename BasicObjType>
- void print_variable(const char *var_name, const BasicObjType &var) {
- auto ss = string_writer{};
- var->write_to(ss);
- std::cout << fmt::format("{} = {}", var_name, ss.get_string_and_reset()) << std::endl;
- }
- #define PRINT_VARIABLE(var) print_variable(#var, var)
- }
- #endif //SOPHIAR2_DEBUG_MACRO_H
|