| 22 | namespace oneflow { |
| 23 | |
| 24 | Maybe<void> LogProgress(const std::string& task_name, bool is_end) { |
| 25 | const bool log_progress = |
| 26 | GetGraphDebugMode() || ThreadLocalEnvBool<ONEFLOW_NNGRAPH_ENABLE_PROGRESS_BAR>(); |
| 27 | if (!log_progress || OF_PREDICT_FALSE(GlobalProcessCtx::Rank() != 0)) { |
| 28 | return Maybe<void>::Ok(); |
| 29 | } |
| 30 | |
| 31 | const static thread_local uint64_t progress_total_num = 60; |
| 32 | static thread_local uint64_t progress_cnt = 1; |
| 33 | static constexpr char clear_line[] = |
| 34 | " \r"; |
| 35 | |
| 36 | auto const& limited_str = task_name.size() > 60 ? task_name.substr(0, 60) : task_name; |
| 37 | std::cout << clear_line << "[" << progress_cnt << "/" << progress_total_num << "]" << limited_str |
| 38 | << "\r" << std::flush; |
| 39 | if (is_end) { |
| 40 | progress_cnt = 0; |
| 41 | std::cout << clear_line << std::endl << std::flush; |
| 42 | } |
| 43 | ++progress_cnt; |
| 44 | return Maybe<void>::Ok(); |
| 45 | } |
| 46 | |
| 47 | } // namespace oneflow |
no test coverage detected