Class: Vernier::ThreadNames

Inherits:
Object
  • Object
show all
Defined in:
lib/vernier/thread_names.rb

Overview

Collects names of all seen threads

Instance Method Summary collapse

Constructor Details

#initialize ⇒ ThreadNames

Returns a new instance of ThreadNames.



4
5
6
7
8
9
10
11
# File 'lib/vernier/thread_names.rb', line 4

def initialize
  @names = {}
  @anonymous = {}
  @tp = TracePoint.new(:thread_end) do |e|
    collect_thread(e.self)
  end
  @tp.enable
end

Instance Method Details

#[](object_id) ⇒ Object



13
14
15
# File 'lib/vernier/thread_names.rb', line 13

def [](object_id)
  @names[object_id] || "thread obj_id:#{object_id}"
end

#anonymous?(object_id) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vernier/thread_names.rb', line 17

def anonymous?(object_id)
  @anonymous[object_id]
end

#finish ⇒ Object



21
22
23
24
# File 'lib/vernier/thread_names.rb', line 21

def finish
  collect_running
  @tp.disable
end