Sha256: 7e01fc54bf32bd4a11cd58688a70461a74fce7d4ab5e3a9ec34c6050e2ff46e1

Contents?: true

Size: 926 Bytes

Versions: 8

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true

require_relative '../../../puppet/util/profiler/logging'

# A profiler implementation that measures the number of seconds a segment of
# code takes to execute and provides a callback with a string representation of
# the profiling information.
#
# @api private
class Puppet::Util::Profiler::WallClock < Puppet::Util::Profiler::Logging
  def do_start(description, metric_id)
    Timer.new
  end

  def do_finish(context, description, metric_id)
    { :time => context.stop,
      :msg => _("took %{context} seconds") % { context: context } }
  end

  class Timer
    FOUR_DECIMAL_DIGITS = '%0.4f'

    def initialize
      @start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
    end

    def stop
      @time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) - @start
      @time
    end

    def to_s
      format(FOUR_DECIMAL_DIGITS, @time)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/util/profiler/wall_clock.rb
puppet-8.10.0-x86-mingw32 lib/puppet/util/profiler/wall_clock.rb
puppet-8.10.0-x64-mingw32 lib/puppet/util/profiler/wall_clock.rb
puppet-8.10.0-universal-darwin lib/puppet/util/profiler/wall_clock.rb
puppet-8.9.0 lib/puppet/util/profiler/wall_clock.rb
puppet-8.9.0-x86-mingw32 lib/puppet/util/profiler/wall_clock.rb
puppet-8.9.0-x64-mingw32 lib/puppet/util/profiler/wall_clock.rb
puppet-8.9.0-universal-darwin lib/puppet/util/profiler/wall_clock.rb