Код: Выделить всё
namespace Tool {
static std::mutex timer_mutex{};
static std::map timers{};
struct Timer {
Timer(const std::string &name);
~Timer();
std::string funcName;
std::chrono::high_resolution_clock::time_point time;
};
}
Tool::Timer::Timer(const std::string &name): funcName(name),
time(std::chrono::high_resolution_clock::now()){}
{
std::lock_guard lock(timer_mutex);
if (timers[std::this_thread::get_id()] < std::numeric_limits::max())
timers[std::this_thread::get_id()]++;
}
Tool::Timer::~Timer()
{
std::lock_guard lock(timer_mutex);
if (timers[std::this_thread::get_id()] > 0)
{
timers[std::this_thread::get_id()]--;
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78543363/write-a-c-thread-safe-macro-to-time-functions[/url]