Module: Thready

Defined in:
lib/thready.rb,
lib/thready/version.rb
more...

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.list_threadsObject

[View source]

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/thready.rb', line 12

def self.list_threads
  threads = Thread.list
  puts "#{Time.now}\t#{threads.size} thread#{'s' if threads.size != 1}:"
  threads.each do |t|
    $stderr.puts

    data = [
      "id: #{t.object_id}",
      "status: #{t.status}",
      #t.backtrace.first
    ]
    puts data.join("\t")

    puts "\t" + t.backtrace.join("\n\t") if t.backtrace

    if t.alive?
      t.set_trace_func(proc do |event, file, line, id, binding, classname|
        #if event == "line"
          printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname

          p binding.eval("local_variables")
          binding.eval("local_variables").each do |var|
            value = binding.eval(var.to_s)
            puts "\t#{var} is #{value.inspect}"
          end

          p binding.eval("instance_variables")
          binding.eval("instance_variables").each do |var|
            value = binding.eval("instance_variable_get(:@#{var})")
            puts "\t@#{var} is #{value.inspect}"
          end
          t.set_trace_func(nil)
        #end
      end)
    end

  end
end