Module: Rordash::DebugUtil

Defined in:
lib/rordash/debug_util.rb

Class Method Summary collapse

Class Method Details

.calculate_duration(tag: nil, &block) ⇒ Object

rubocop:disable Metrics/AbcSize

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rordash/debug_util.rb', line 7

def calculate_duration(tag: nil, &block)
  tag = :default unless tag.present?
  started_at = Time.now.to_f
  raise ArgumentError, 'Missing block' unless block

  yield
  ended_at = Time.now.to_f

  duration_with_ms = ended_at - started_at
  duration_in_seconds = duration_with_ms.floor

  seconds = format("%.1f", duration_with_ms)
  minutes = (duration_in_seconds / 60) % 60
  hours = duration_in_seconds / (60 * 60)
  puts "tag: `#{tag}` - total duration - #{hours} hours #{minutes} minutes and #{seconds} seconds".light_blue
end

.wrap_stack_prof(tag: nil, out: nil, &block) ⇒ Object

rubocop:enable Metrics/AbcSize



25
26
27
28
29
30
31
32
33
# File 'lib/rordash/debug_util.rb', line 25

def wrap_stack_prof(tag: nil, out: nil, &block)
  tag = :default unless tag.present?
  out = 'tmp/stackprof.dump' unless out.present?

  calculate_duration(tag: tag) do
    StackProf.run(mode: :wall, out: out, raw: true, interval: 1000, &block)
    puts "\n\nStackProf output file: #{out}".yellow
  end
end