Class: QAT::Reporter::Times

Inherits:
Object
  • Object
show all
Extended by:
Helpers::TimeFormat
Includes:
Logger
Defined in:
lib/qat/reporter/times.rb,
lib/qat/reporter/times/report.rb,
lib/qat/reporter/times/helpers.rb

Overview

namespace for time report measures

Defined Under Namespace

Modules: Report Classes: NoEndtTimeError, NoLabelInConfig, NoStartTimeError

Constant Summary collapse

Helpers =

Namespace for Times Helpers

QAT::Reporter::Helpers::TimeFormat

Class Method Summary collapse

Methods included from Helpers::TimeFormat

human_formatted_time

Class Method Details

.browser_name=(name) ⇒ String

Defines browser name

Parameters:

  • name (String)

    browser name

Returns:

  • (String)


86
87
88
# File 'lib/qat/reporter/times.rb', line 86

def self.browser_name=(name)
  QAT.store_permanently :browser_name, name
end

.browser_version=(version) ⇒ String

Defines browser version

Parameters:

  • version (String)

    browser version

Returns:

  • (String)


93
94
95
# File 'lib/qat/reporter/times.rb', line 93

def self.browser_version=(version)
  QAT.store_permanently :browser_version, version
end

.generate_time_report(test_id) ⇒ String

Generates the time report of a test using the names stored in QAT

Parameters:

  • test_id (String)

    test ID

Returns:

  • (String)


100
101
102
103
104
105
106
107
108
# File 'lib/qat/reporter/times.rb', line 100

def self.generate_time_report(test_id)
  measures = get_measures

  measures.each do |id, measure|
    log.info build_measure(test_id, id, measure)
  end

  measures
end

.get_duration(name) ⇒ Float

Gets duration execution time

Parameters:

  • name (String)

    measure name

Returns:

  • (Float)


120
121
122
123
124
# File 'lib/qat/reporter/times.rb', line 120

def self.get_duration(name)
  end_key = "#{name}_end".to_sym
  QAT[end_key] ||= Time.now
  QAT[end_key].to_f - QAT["#{name}_start".to_sym].to_f
end

.get_execution_time(name) ⇒ Time

Gets formatted execution time

Parameters:

  • name (String)

    measure name

Returns:

  • (Time)


113
114
115
# File 'lib/qat/reporter/times.rb', line 113

def self.get_execution_time(name)
  human_formatted_time(get_duration(name))
end

.has_times?Boolean

Verifies if QAT Storage has times

Returns:

  • (Boolean)


128
129
130
# File 'lib/qat/reporter/times.rb', line 128

def self.has_times?
  QAT::Core.instance.instance_variable_get(:@storage).keys.any? {|key| key.match(/_start$/)}
end

.measure(name) { ... } ⇒ String

Measures the execution time of a block of code

Parameters:

  • name (String)

    measure name

Yields:

Returns:

  • (String)

    measured execution time

Raises:

  • (ArgumentError)


60
61
62
63
64
65
66
67
# File 'lib/qat/reporter/times.rb', line 60

def self.measure(name)
  raise(ArgumentError, 'No block given') unless block_given?
  start(name)
  result = yield
  stop(name)
  log.debug "Total time at #{name}: #{get_execution_time(name)}"
  result
end

.os_name=(name) ⇒ String

Defines OS name

Parameters:

  • name (String)

    OS name

Returns:

  • (String)


72
73
74
# File 'lib/qat/reporter/times.rb', line 72

def self.os_name=(name)
  QAT.store_permanently :os_name, name
end

.os_version=(version) ⇒ String

Defines OS version

Parameters:

  • version (String)

    OS version

Returns:

  • (String)


79
80
81
# File 'lib/qat/reporter/times.rb', line 79

def self.os_version=(version)
  QAT.store_permanently :os_version, version
end

.start(loading_name, time = Time.now) ⇒ Time

Starts a time measure

Parameters:

  • loading_name (String)

    measure name

  • time (Time) (defaults to: Time.now)

    start time (default: Time.now)

Returns:

  • (Time)


18
19
20
21
22
23
24
25
# File 'lib/qat/reporter/times.rb', line 18

def self.start(loading_name, time = Time.now)
  if QAT::Core.instance.instance_variable_get(:@storage).key?("#{loading_name}_start".to_sym)
    log.warn "Time measurement '#{measure_description(loading_name) rescue loading_name}' already exists..."
    nil
  else
    QAT.store "#{loading_name}_start".to_sym, time
  end
end

.stop(measure_key, time = Time.now) ⇒ Time/Nil

Stops a time measure

Parameters:

  • measure_key (String)

    measure key

  • time (Time) (defaults to: Time.now)

    stop time (default: Time.now)

Returns:

  • (Time/Nil)

    returns time or gives warning message



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/qat/reporter/times.rb', line 31

def self.stop(measure_key, time = Time.now)
  if QAT::Core.instance.instance_variable_get(:@storage).key?("#{measure_key}_start".to_sym)
    if QAT::Core.instance.instance_variable_get(:@storage).key?("#{measure_key}_end".to_sym)
      log.warn "Time measurement '#{measure_description(measure_key) rescue measure_key}' already exists..."
      nil
    else
      QAT.store "#{measure_key}_end".to_sym, time
    end
  else
    log.warn "No Start time was found for '#{measure_description(measure_key) rescue measure_key}'!"
    nil
  end
end

.stop!(measure_key, time = Time.now) ⇒ Time

Stops a time measure

Parameters:

  • measure_key (String)

    measure name

  • time (Time) (defaults to: Time.now)

    stop time (default: Time.now)

Returns:

  • (Time)

Raises:



50
51
52
53
54
# File 'lib/qat/reporter/times.rb', line 50

def self.stop!(measure_key, time = Time.now)
  stop_time = self.stop(measure_key, time)
  raise NoStartTimeError.new 'No Start time was found!' unless stop_time
  stop_time
end