Module: Hitimes

Defined in:
lib/hitimes.rb,
lib/hitimes/paths.rb,
lib/hitimes/stats.rb,
lib/hitimes/metric.rb,
lib/hitimes/instant.rb,
lib/hitimes/version.rb,
lib/hitimes/interval.rb,
lib/hitimes/initialize.rb,
lib/hitimes/timed_metric.rb,
lib/hitimes/value_metric.rb,
lib/hitimes/mutexed_stats.rb,
lib/hitimes/timed_value_metric.rb

Overview

– Copyright © 2008, 2009 Jeremy Hinegardner All rights reserved. See LICENSE and/or COPYING for details. ++

Defined Under Namespace

Modules: Initialize, Paths Classes: Error, Interval, Metric, Stats, TimedMetric, TimedValueMetric, ValueMetric

Constant Summary collapse

CLOCK_ID =

Public: The clock_id to use in Process.clock_gettime

Initialize.determine_clock_id.freeze
CLOCK_RESOLUTION_NANOSECONDS =

Public: The resolution of the clock

Process.clock_getres(CLOCK_ID, :nanosecond).freeze
NANOSECONDS_PER_SECOND =

Internal: The fraction of second of a nanosecond

1e9
CLOCK_RESOLUTION_SECONDS =

Public: The smallest fraction of a second hitimes can do

CLOCK_RESOLUTION_NANOSECONDS / NANOSECONDS_PER_SECOND
INSTANT_CONVERSION_FACTOR =

Public: The factor used to convert the instant values to fractional seconds

The raw instant values are divided by this value to get float seconds

CLOCK_RESOLUTION_NANOSECONDS * NANOSECONDS_PER_SECOND
VERSION =
"2.0.0"
MutexedStats =

MutexedStats is the start of a threadsafe Stats class. Currently, on MRI Ruby the Stats object is already threadsafe, so there is no need to use MutexedStats.

Stats

Class Method Summary collapse

Class Method Details

.clock_descriptionObject

Internal: The human readable clock description that is used by hitimes

Returns the clock description as a String


61
62
63
# File 'lib/hitimes/instant.rb', line 61

def clock_description
  "#{clock_name} #{clock_resolution_description}"
end

.clock_nameObject

Internal: The human readable clock name of the CLOCK_ID as a string

Returns the clock name as a String


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hitimes/instant.rb', line 37

def clock_name
  case CLOCK_ID
  when Symbol
    CLOCK_ID.to_s
  else
    const = Process.constants.grep(/CLOCK/).find { |c|
      CLOCK_ID == Process.const_get(c)
    }
    "Process::#{const.to_s}"
  end
end

.clock_resolution_descriptionObject

Internal: The human readable clock resolution

Returns the clock resolution as a string


53
54
55
# File 'lib/hitimes/instant.rb', line 53

def clock_resolution_description
  "#{CLOCK_RESOLUTION_NANOSECONDS}ns"
end

.measure(&block) ⇒ Object

Hitimes.measure { } -> Float

Times the execution of the block, returning the number of seconds it took


22
23
24
# File 'lib/hitimes.rb', line 22

def self.measure(&block)
  Hitimes::Interval.measure(&block)
end

.raw_instantObject

Public: Get the raw instant

Examples:

Hitimes.raw_instant

Returns the raw instant value


29
30
31
# File 'lib/hitimes/instant.rb', line 29

def raw_instant
  Process.clock_gettime(::Hitimes::CLOCK_ID, :nanosecond)
end