Class: ThreadDump::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/thread-dump.rb

Class Method Summary collapse

Class Method Details

.start(time_between_dumps = 60) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/thread-dump.rb', line 35

def self.start(time_between_dumps = 60)
  Thread.start(time_between_dumps) do |sleep_time|
    loop do
      ThreadDump::Monitor.write_threads
      sleep sleep_time
    end
  end
end

.write_threadsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/thread-dump.rb', line 44

def self.write_threads
  out_arr = []

  ThreadDump::Dumper.dump.each do |thread_info|
    if ThreadDump::Config.output_format == :html
      out_arr << "<dt>#{thread_info[1]}</dt><dd>#{thread_info[0]}</dd>"
    else
      out_arr << "Thread #{thread_info[0]}: #{thread_info[1]}"
    end
  end
  max_l_out_arr = out_arr.map { |out| out.size }.max
  fout = STDERR

  if ThreadDump::Config.dump_target == :file
    fout = File.open("/tmp/#{$$}.ruby_threads.html", "w")
  end

  out_arr.each do |out|
    fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
    fout << out + "\n"
  end

  fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
  fout.flush

  if fout != STDERR
    fout.close
  end
end