Skip to content

Commit d3e8e7f

Browse files
committed
fix: use steady_clock instead of system_lock to measure replay duration
1 parent e8f60b4 commit d3e8e7f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/zc/replay.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ static int prev_debug_y;
8282
static bool gfx_got_mismatch;
8383
static std::array<int, 4> prev_mouse_state;
8484
static std::array<int, 4> current_mouse_state;
85-
static std::chrono::time_point<std::chrono::system_clock> time_started;
86-
static std::chrono::time_point<std::chrono::system_clock> time_result_saved;
85+
static std::chrono::time_point<std::chrono::steady_clock> time_started;
86+
static std::chrono::time_point<std::chrono::system_clock> time_started_system;
87+
static std::chrono::time_point<std::chrono::steady_clock> time_result_saved;
8788

8889
struct FramebufHistoryEntry
8990
{
@@ -888,9 +889,9 @@ static std::string segments_to_string(const std::vector<std::pair<int, int>>& se
888889

889890
static void save_result(bool stopped = false, bool changed = false)
890891
{
891-
time_result_saved = std::chrono::system_clock::now();
892+
time_result_saved = std::chrono::steady_clock::now();
892893
std::chrono::duration<double, std::milli> elapsed = time_result_saved - time_started;
893-
std::time_t time_started_c = std::chrono::system_clock::to_time_t(time_started);
894+
std::time_t time_started_c = std::chrono::system_clock::to_time_t(time_started_system);
894895
int fps = (double)frame_count / elapsed.count() * 1000;
895896

896897
// Write to temporary file and then move it, because run_replay_tests.py will constantly
@@ -1157,7 +1158,8 @@ void replay_start(ReplayMode mode_, std::filesystem::path path, int frame)
11571158
{
11581159
ASSERT(mode == ReplayMode::Off);
11591160
ASSERT(mode_ != ReplayMode::Off && mode_ != ReplayMode::ManualTakeover);
1160-
time_started = std::chrono::system_clock::now();
1161+
time_started = std::chrono::steady_clock::now();
1162+
time_started_system = std::chrono::system_clock::now();
11611163
mode = mode_;
11621164
debug = false;
11631165
sync_rng = false;
@@ -1345,7 +1347,7 @@ void replay_poll()
13451347

13461348
if (frame_count == 0)
13471349
save_result();
1348-
if (std::chrono::system_clock::now() - time_result_saved > 1s)
1350+
if (std::chrono::steady_clock::now() - time_result_saved > 1s)
13491351
save_result();
13501352

13511353
if (mode == ReplayMode::Assert || mode == ReplayMode::Record)

0 commit comments

Comments
 (0)