Class: Roby::App::Debug
- Inherits:
-
Interface::CommandLibrary
- Object
- Interface::CommandLibrary
- Roby::App::Debug
- Defined in:
- lib/roby/app/debug.rb
Overview
A command library that allows to control StackProf to profile a Roby application
Instance Attribute Summary
Attributes inherited from Interface::CommandLibrary
Instance Method Summary collapse
-
#default_path(prefix) ⇒ Object
private
The filename that is used by default in #stackprof_save.
-
#memdump(path: default_path("memdump"), run_gc: true) ⇒ Object
Perform a memory dump.
- #stackprof_active? ⇒ Boolean
-
#stackprof_save(path: default_path("stackprof-%s")) ⇒ Object
Save the current profiling results into the path given to #stackprof_start.
-
#stackprof_start(one_shot: false, cycles: nil, mode: :cpu, interval: nil, raw: false) ⇒ Object
Start profiling.
-
#stackprof_stop ⇒ Object
Stop profiling.
-
#trace_allocations(enable) ⇒ Object
Enable or disable allocation traces for #memdump.
Methods inherited from Interface::CommandLibrary
command, #commands, #each_subcommand, #execution_engine, #initialize, #plan, #refresh_subcommands, #subcommand, subcommand
Constructor Details
This class inherits a constructor from Roby::Interface::CommandLibrary
Instance Method Details
#default_path(prefix) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The filename that is used by default in #stackprof_save.
It is a time tag (down to the milliseconds) followed by the sampling mode and a .dump extension
100 101 102 103 104 |
# File 'lib/roby/app/debug.rb', line 100 def default_path(prefix) path = File.join(app.log_dir, "debug") time = Time.now.strftime("%Y-%m-%d.%H%M%S.%3N") File.join(path, "#{prefix}-#{time}.dump") end |
#memdump(path: default_path("memdump"), run_gc: true) ⇒ Object
Perform a memory dump
123 124 125 126 127 128 129 130 |
# File 'lib/roby/app/debug.rb', line 123 def memdump(path: default_path("memdump"), run_gc: true) FileUtils.mkdir_p File.dirname(path) File.open(path, "wb") do |io| GC.start(full_mark: true, immediate_sweep: true) if run_gc ObjectSpace.dump_all(output: io) end path end |
#stackprof_active? ⇒ Boolean
76 77 78 |
# File 'lib/roby/app/debug.rb', line 76 def stackprof_active? !!@cycle_counter_handler end |
#stackprof_save(path: default_path("stackprof-%s")) ⇒ Object
Save the current profiling results into the path given to #stackprof_start
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/roby/app/debug.rb', line 109 def stackprof_save(path: default_path("stackprof-%s")) if results = StackProf.results path = format(path, results[:mode]) FileUtils.mkdir_p(File.dirname(path)) File.open(path, "wb") do |f| f.write Marshal.dump(results) end path end end |
#stackprof_start(one_shot: false, cycles: nil, mode: :cpu, interval: nil, raw: false) ⇒ Object
Start profiling
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/roby/app/debug.rb', line 29 def stackprof_start(one_shot: false, cycles: nil, mode: :cpu, interval: nil, raw: false) interval ||= if mode == :object then 1 else 1000 end StackProf.start(mode: mode, interval: interval, raw: raw) if one_shot && !cycles cycles = 1 end if cycles remaining_cycles = cycles @cycle_counter_handler = execution_engine.at_cycle_begin do remaining_cycles -= 1 if remaining_cycles == 0 execution_engine.at_cycle_end(once: true) do remaining_cycles = cycles StackProf.stop path = stackprof_save app.notify "profiling", "INFO", "results saved in #{path} after #{cycles} cycles" if one_shot app.notify "profiling", "INFO", "stopped" execution_engine.remove_propagation_handler(@cycle_counter_handler) @cycle_counter_handler = nil else StackProf.start(mode: mode, interval: interval) end end end end nil end end |
#stackprof_stop ⇒ Object
Stop profiling
This does not save the results, call #stackprof_save for this
84 85 86 87 88 89 90 |
# File 'lib/roby/app/debug.rb', line 84 def stackprof_stop StackProf.stop if @cycle_counter_handler execution_engine.remove_propagation_handler(@cycle_counter_handler) @cycle_counter_handler = nil end end |
#trace_allocations(enable) ⇒ Object
Enable or disable allocation traces for #memdump
137 138 139 140 141 142 143 144 |
# File 'lib/roby/app/debug.rb', line 137 def trace_allocations(enable) if enable ObjectSpace.trace_object_allocations_start else ObjectSpace.trace_object_allocations_stop ObjectSpace.trace_object_allocations_clear end end |