From e0d17781b7e4873f5ec6308496475421db151ff8 Mon Sep 17 00:00:00 2001 From: Aria Li Date: Wed, 17 Jul 2024 13:50:01 -0700 Subject: [PATCH] (PUP-7520) Update Puppet profiling timers to use monotonic clock This commit updates Puppet::Util::Profiler::WallClock and Puppet::Util::Profiler::Aggregate to use Process.clock_gettime(Process::CLOCK_MONOTONIC) instead of Time.now. Time.now returns a value from the OS REALTIME clock which can be affected by events like NTP updates. Process.clock_gettime(Process::CLOCK_MONOTONIC) uses a monotonic clock which isn't affected by things like NTP updates. --- lib/puppet/util/profiler/aggregate.rb | 4 ++-- lib/puppet/util/profiler/wall_clock.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/puppet/util/profiler/aggregate.rb b/lib/puppet/util/profiler/aggregate.rb index 20b568ce4e7..f18f52bcde0 100644 --- a/lib/puppet/util/profiler/aggregate.rb +++ b/lib/puppet/util/profiler/aggregate.rb @@ -72,11 +72,11 @@ def add_time(time) class Timer def initialize - @start = Time.now + @start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) end def stop - Time.now - @start + Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) - @start end end end diff --git a/lib/puppet/util/profiler/wall_clock.rb b/lib/puppet/util/profiler/wall_clock.rb index 090c20476a5..8277cba78f9 100644 --- a/lib/puppet/util/profiler/wall_clock.rb +++ b/lib/puppet/util/profiler/wall_clock.rb @@ -21,11 +21,11 @@ class Timer FOUR_DECIMAL_DIGITS = '%0.4f' def initialize - @start = Time.now + @start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) end def stop - @time = Time.now - @start + @time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) - @start @time end