From bb5e4454fee1e01d4c18b27e957a6f759e3f0880 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 16 Sep 2024 21:41:52 +0200 Subject: [PATCH] putil: Add debug for oversleeping/undersleeping with M_limited clock --- panda/src/putil/clockObject.cxx | 16 ++++++++++++++++ panda/src/putil/config_putil.cxx | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/panda/src/putil/clockObject.cxx b/panda/src/putil/clockObject.cxx index 8fa128616f..1add57a6e1 100644 --- a/panda/src/putil/clockObject.cxx +++ b/panda/src/putil/clockObject.cxx @@ -499,6 +499,8 @@ wait_until(double want_time) { double wait_interval = (want_time - _actual_frame_time) - sleep_precision; + double now = get_real_time(); + if (wait_interval > 0.0) { Thread::sleep(wait_interval); } @@ -507,6 +509,20 @@ wait_until(double want_time) { (*_start_clock_busy_wait)(); #endif + _actual_frame_time = get_real_time(); + if (_actual_frame_time > want_time) { + if (util_cat.is_debug()) { + util_cat.debug() + << "Overslept by " << (int)((_actual_frame_time - want_time) * 1000000) + << " us while waiting for next frame, consider raising sleep-precision.\n"; + } + } + else if (util_cat.is_spam()) { + util_cat.spam() + << "Busy waiting for " << (int)((want_time - _actual_frame_time) * 1000000) + << " us.\n"; + } + // Now busy-wait until the actual time elapses. while (_actual_frame_time < want_time) { _actual_frame_time = get_real_time(); diff --git a/panda/src/putil/config_putil.cxx b/panda/src/putil/config_putil.cxx index 93694b3d30..9849cd5b84 100644 --- a/panda/src/putil/config_putil.cxx +++ b/panda/src/putil/config_putil.cxx @@ -129,9 +129,9 @@ get_plugin_path() { ConfigVariableDouble sleep_precision ("sleep-precision", 0.01, - PRC_DESC("This is the accuracy within which we can expect select() to " - "return precisely. That is, if we use select() to request a " - "timeout of 1.0 seconds, we can expect to actually sleep for " + PRC_DESC("This is the accuracy within which we can expect the operating " + "system sleep call to return precisely. That is, if we request " + "a timeout of 1.0 seconds, we can expect to actually sleep for " "somewhere between 1.0 and 1.0 + sleep-precision seconds.")); ConfigVariableBool preload_textures