Skip to content

Commit 3445d95

Browse files
authored
Update format string for formatting chrono duration (#12684)
* Update format string for formatting chrono duration * normalize cast to long long * Alias duration case type
1 parent a399830 commit 3445d95

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/iocore/eventsystem/Watchdog.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ Monitor::~Monitor()
5757
void
5858
Monitor::monitor_loop() const
5959
{
60+
// this ensures `long long` duration for older compilers to match format specifiers
61+
using printable_micro = std::chrono::duration<long long, std::micro>;
62+
using printable_milli = std::chrono::duration<long long, std::milli>;
63+
6064
// Divide by a floating point 2 to avoid truncation to zero.
6165
auto sleep_time = _timeout / 2.0;
6266
ink_release_assert(sleep_time.count() > 0);
63-
Dbg(dbg_ctl_watchdog, "Starting watchdog with timeout %" PRIu64 " ms on %zu threads. sleep_time = %" PRIu64 " us",
64-
_timeout.count(), _threads.size(), std::chrono::duration_cast<std::chrono::microseconds>(sleep_time).count());
67+
Dbg(dbg_ctl_watchdog, "Starting watchdog with timeout %lld ms on %zu threads. sleep_time = %lld us",
68+
std::chrono::duration_cast<printable_milli>(_timeout).count(), _threads.size(),
69+
std::chrono::duration_cast<printable_micro>(sleep_time).count());
6570

6671
ink_set_thread_name("[WATCHDOG]");
6772

@@ -90,8 +95,8 @@ Monitor::monitor_loop() const
9095
uint64_t warned_seq = t->heartbeat_state.warned_seq.load(std::memory_order_relaxed);
9196
if (warned_seq < seq) {
9297
// Warn once per loop iteration
93-
Warning("Watchdog: [ET_NET %zu] has been awake for %" PRIu64 " ms", i,
94-
std::chrono::duration_cast<std::chrono::milliseconds>(awake_duration).count());
98+
Warning("Watchdog: [ET_NET %zu] has been awake for %lld ms", i,
99+
std::chrono::duration_cast<printable_milli>(awake_duration).count());
95100
t->heartbeat_state.warned_seq.store(seq, std::memory_order_relaxed);
96101
}
97102
}

0 commit comments

Comments
 (0)