Class: Rbkit::Profiler
- Inherits:
-
Object
- Object
- Rbkit::Profiler
- Defined in:
- lib/rbkit.rb
Instance Attribute Summary collapse
-
#pub_port ⇒ Object
Returns the value of attribute pub_port.
-
#request_port ⇒ Object
Returns the value of attribute request_port.
Instance Method Summary collapse
-
#initialize(pub_port, request_port) ⇒ Profiler
constructor
A new instance of Profiler.
- #make_clean_exit ⇒ Object
- #process_incoming_request(incoming_request) ⇒ Object
- #start_server(enable_profiling: false) ⇒ Object
- #stop_server ⇒ Object
Constructor Details
#initialize(pub_port, request_port) ⇒ Profiler
Returns a new instance of Profiler.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbkit.rb', line 10 def initialize(pub_port, request_port) @pub_port = pub_port @request_port = request_port @profiler_thread = nil @stop_thread = false @server_running = false @gc_stats_timer = Rbkit::Timer.new(5) do data = GC.stat no_of_allocated_pages = data[:heap_length] max_objects_per_page = GC::INTERNAL_CONSTANTS[:HEAP_OBJ_LIMIT] size_of_one_obj = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] data[:total_heap_size] = no_of_allocated_pages * max_objects_per_page * size_of_one_obj data[:total_memsize] = ObjectSpace.memsize_of_all Rbkit.send_hash_as_event(data, "gc_stats") end = Rbkit::Timer.new(1) do Rbkit. end end |
Instance Attribute Details
#pub_port ⇒ Object
Returns the value of attribute pub_port.
8 9 10 |
# File 'lib/rbkit.rb', line 8 def pub_port @pub_port end |
#request_port ⇒ Object
Returns the value of attribute request_port.
8 9 10 |
# File 'lib/rbkit.rb', line 8 def request_port @request_port end |
Instance Method Details
#make_clean_exit ⇒ Object
68 69 70 71 |
# File 'lib/rbkit.rb', line 68 def make_clean_exit @stop_thread = true stop_server end |
#process_incoming_request(incoming_request) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rbkit.rb', line 49 def process_incoming_request(incoming_request) case incoming_request when "start_memory_profile" Rbkit.start_stat_tracing when "stop_memory_profile" Rbkit.stop_stat_tracing when "trigger_gc" GC.start when "objectspace_snapshot" Rbkit.send_objectspace_dump end end |
#start_server(enable_profiling: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rbkit.rb', line 31 def start_server(enable_profiling: false) return if @server_running @profiler_thread = Thread.new do Rbkit.start_stat_server(pub_port, request_port) Rbkit.start_stat_tracing if enable_profiling loop do break if @stop_thread incoming_request = Rbkit.poll_for_request process_incoming_request(incoming_request) @gc_stats_timer.run .run # Let us sleep this thread for a bit, so as other things can run. sleep(0.05) end end @server_running = true end |
#stop_server ⇒ Object
62 63 64 65 66 |
# File 'lib/rbkit.rb', line 62 def stop_server return if !@server_running Rbkit.stop_stat_server @server_running = false end |