| 59 | } |
| 60 | |
| 61 | std::string LogMsg(const std::string& msg) |
| 62 | { |
| 63 | const auto end_time = GetTime<std::chrono::microseconds>() - m_start_t; |
| 64 | if (m_start_t.count() <= 0) { |
| 65 | return strprintf("%s: %s", m_prefix, msg); |
| 66 | } |
| 67 | |
| 68 | if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) { |
| 69 | return strprintf("%s: %s (%iμs)", m_prefix, msg, end_time.count()); |
| 70 | } else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) { |
| 71 | return strprintf("%s: %s (%.2fms)", m_prefix, msg, end_time.count() * 0.001); |
| 72 | } else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) { |
| 73 | return strprintf("%s: %s (%.2fs)", m_prefix, msg, end_time.count() * 0.000001); |
| 74 | } else { |
| 75 | static_assert(ALWAYS_FALSE<TimeType>, "Error: unexpected time type"); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | std::chrono::microseconds m_start_t{}; |