diff --git a/src/test.cpp b/src/test.cpp index dd0a08e..6b4dafe 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1,3 +1,5 @@ +// follow with +// strace -o log -ff -tt #include "../include/stdafx.h" #include "../include/rtlog/Formatter.hpp" #include "../include/rtlog/Consumer.hpp" @@ -16,6 +18,13 @@ bool is_logged(LogLevel level) return static_cast(level) >= loglevel.load(std::memory_order_relaxed); } +template +fmt::BasicWriter& operator<<(fmt::BasicWriter& os, Argument const& arg); + +#if defined(BOOST_LIB_C_GNU) && defined(BOOST_OS_LINUX) && defined(USE_INTERNAL_GETTID) +size_t __thread_id_offset_linux_glibc = rtlog::__find_thread_id_offset(); +#endif + } // namespace rtlog @@ -31,28 +40,33 @@ int main(int argc, char* argv[]) std::default_random_engine e1(r()); std::uniform_int_distribution uniform_dist(10, 200); - - for (int i{0}; i < 100; i++) { - for (int j{0}; j < 10; j++) { - std::chrono::microseconds sleep_time(uniform_dist(e1)); - LOG_INFO("User message", (i*10)+j, sleep_time.count()); - std::this_thread::sleep_for(sleep_time); - } - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + unsigned int max_threads(std::thread::hardware_concurrency()); + std::vector> thread_futures; + for (unsigned int thread_index(0); thread_index < max_threads; thread_index++) { + thread_futures.push_back( + std::move( + std::async( + [&uniform_dist, &e1, thread_index] () + { + for (int i{0}; i < 100; i++) { + for (int j{0}; j < 10; j++) { + std::chrono::microseconds sleep_time(uniform_dist(e1)); + LOG_INFO("Thread idx", thread_index, (i*10)+j, sleep_time.count()); + std::this_thread::sleep_for(sleep_time); + } + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + } // lambda + ) // async + ) // move + ); // push_back } - consumer.stop(); - + LOG_INFO("Base thread wait"); + for (auto& f : thread_futures) + f.wait(); - //~ consumer_thread.join(); - //~ std::cout << rtlog::CLogger::get().format(); - - //~ CFormatter l; - //~ l.write("asd {}", "CCC"); - //~ l.format(); - //~ l.write("asd {}", -13, 13u); - //~ l.format(); - //~ l.write("asd {}"); - //~ l.format(); + LOG_INFO("Children joined"); + consumer.stop(); return 0; }