void BenchmarkRunnerThread::run() { set_current_thread_name("benchmarks"); auto_release_ptr<XMLFileBenchmarkListener> xmlfile_listener( create_xmlfile_benchmark_listener()); const string xmlfile_name = "benchmark." + get_time_stamp_string() + ".xml"; const bf::path xmlfile_path = bf::path(Application::get_tests_root_path()) / "unit benchmarks" / "results" / xmlfile_name; if (!xmlfile_listener->open(xmlfile_path.string().c_str())) { emit signal_cannot_create_benchmark_file(); return; } BenchmarkResult result; result.add_listener(xmlfile_listener.get()); const bf::path old_current_path = Application::change_current_directory_to_tests_root_path(); BenchmarkSuiteRepository::instance().run(result); bf::current_path(old_current_path); emit signal_finished(); }
void ThreadPool::start(ThreadInit fct) { if (running_) { return; } int i = 0; std::generate_n(std::back_inserter(works_), nb_services_, [this, &i] { return std::unique_ptr<boost::asio::io_service::work>( new boost::asio::io_service::work(*services_[i++])); }); threads_.reserve(nb_thread_); for (size_t i = 0; i < nb_thread_; ++i) { threads_.emplace_back( &ThreadPool::run, this, std::ref(getService(i % nb_services_)), [this, fct, i] { auto suffix = "#" + std::to_string(i) + "|S#" + std::to_string(i % nb_services_); if (name_.empty()) { std::string default_name = "PTH" + suffix; set_current_thread_name(default_name); } else { set_current_thread_name(name_ + suffix); } if (fct) { fct(); } }); } while (running_threads_ != nb_thread_) { std::this_thread::yield(); } running_ = true; }
const std::string& get_current_thread_name() { #if HAVE_THREAD_LOCAL_SPECIFIER if (!current_name.empty()) { return current_name; } #else if (current_name.get()) { return *current_name; } #endif std::ostringstream out; out << std::this_thread::get_id(); set_current_thread_name(out.str()); return get_current_thread_name(); }
void TestRunnerThread::run() { set_current_thread_name("tests"); QtTestListener listener(m_output_widget, m_result_widget); TestResult result; global_logger().set_enabled(false); const filesystem::path old_current_path = Application::change_current_directory_to_tests_root_path(); m_repository.run(listener, result); filesystem::current_path(old_current_path); global_logger().set_enabled(true); const int failed_count = static_cast<int>(result.get_case_failure_count()); const int passed_count = static_cast<int>(result.get_case_execution_count()) - failed_count; emit signal_finished(passed_count, failed_count); }
void WorkerThread::set_thread_name() { char thread_name[16]; portable_snprintf(thread_name, sizeof(thread_name), "worker_%03lu", (long unsigned int)m_index); set_current_thread_name(thread_name); }