Class: Evilution::Runner::Diagnostics

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/runner/diagnostics.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, stderr: $stderr) ⇒ Diagnostics

Returns a new instance of Diagnostics.



9
10
11
12
# File 'lib/evilution/runner/diagnostics.rb', line 9

def initialize(config, stderr: $stderr)
  @config = config
  @stderr = stderr
end

Instance Method Details

#aggregate_worker_stats(stats) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/evilution/runner/diagnostics.rb', line 60

def aggregate_worker_stats(stats)
  return stats if stats.empty?

  stats.group_by(&:pid).map do |pid, entries|
    Evilution::Parallel::WorkQueue::WorkerStat.new(
      pid,
      entries.sum(&:items_completed),
      entries.sum(&:busy_time),
      entries.sum(&:wall_time)
    )
  end
end

#log_memory(phase, context = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/evilution/runner/diagnostics.rb', line 14

def log_memory(phase, context = nil)
  return unless verbose?

  rss = Evilution::Memory.rss_mb
  return unless rss

  gc = gc_stats_string
  msg = format("[memory] %<phase>s: %<rss>.1f MB", phase: phase, rss: rss)
  ctx = [context, gc].compact.join(", ")
  msg += " (#{ctx})" unless ctx.empty?
  stderr.write("#{msg}\n")
end

#log_mutation_diagnostics(result) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/evilution/runner/diagnostics.rb', line 33

def log_mutation_diagnostics(result)
  return unless verbose?

  parts = []
  parts << format("child_rss: %<mb>.1f MB", mb: result.child_rss_kb / 1024.0) if result.child_rss_kb

  if result.memory_delta_kb
    sign = result.memory_delta_kb.negative? ? "" : "+"
    parts << format("delta: %<sign>s%<mb>.1f MB", sign: sign, mb: result.memory_delta_kb / 1024.0)
  end

  parts << gc_stats_string

  stderr.write("[verbose] #{result.mutation}: #{parts.join(", ")}\n") unless parts.empty?

  log_mutation_error(result) if result.error?
end

#log_progress(current, status) ⇒ Object



27
28
29
30
31
# File 'lib/evilution/runner/diagnostics.rb', line 27

def log_progress(current, status)
  return unless text_tty?

  stderr.write("mutation #{current} #{status}\n")
end

#log_worker_stats(stats) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/evilution/runner/diagnostics.rb', line 51

def log_worker_stats(stats)
  return unless verbose? && stats.any?

  stats.each do |stat|
    pct = format("%.1f", stat.utilization * 100)
    stderr.write("[verbose] worker #{stat.pid}: #{stat.items_completed} items, utilization #{pct}%\n")
  end
end