Class: Roby::EventLogging::StackProfEventManager
- Defined in:
- lib/roby/event_logging/stackprof_event_manager.rb
Overview
A simple event logger that displays a textual representation of the events on plain I/O (e.g. log file or stdout)
Constant Summary collapse
- TIMEPOINT_KIND_START =
%I[timepoint timepoint_group_start].freeze
- TIMEPOINT_KIND_END =
%I[timepoint timepoint_group_end].freeze
Instance Attribute Summary collapse
-
#count ⇒ Integer?
How many start/stop cycles until we dump the results.
-
#mode ⇒ Symbol
The stackprof mode.
-
#quit ⇒ Boolean
Quit the application when the profile data has been dumped.
-
#raw ⇒ Boolean
Whether stackprof saves raw samples.
-
#results_path ⇒ Integer?
How many start/stop cycles until we dump the results.
-
#skip ⇒ Integer?
How many start/stop cycles to ignore before we start profiling.
Instance Method Summary collapse
- #close ⇒ Object
- #dump(name, time, args) ⇒ Object
- #dump_time ⇒ Object
- #dump_timepoint(kind, _time, args) ⇒ Object
- #flush_cycle(name, *args) ⇒ Object
-
#initialize ⇒ StackProfEventManager
constructor
A new instance of StackProfEventManager.
- #log_queue_size ⇒ Object
- #log_timepoints? ⇒ Boolean
- #stackprof_dump_results ⇒ Object
-
#stackprof_handle_start_timepoint(timepoint_name) ⇒ Object
private
Start profiling.
-
#stackprof_handle_stop_timepoint(timepoint_name) ⇒ Object
private
Handle the reception of a stop timepoint while stackprof was running.
-
#start_on(matcher) ⇒ Object
Start profiling whenever a timepoint name matches the given matcher.
-
#stop_on(matcher) ⇒ Object
Stop profiling whenever a timepoint name matches the given matcher.
Constructor Details
#initialize ⇒ StackProfEventManager
Returns a new instance of StackProfEventManager.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 44 def initialize @results_path = "/tmp/roby-stackprof-#{Process.pid}" @skip = 0 @count = nil @remaining_count = nil @remaining_skip = nil @mode = :cpu @raw = false @dumped_results = false @quit = false end |
Instance Attribute Details
#count ⇒ Integer?
How many start/stop cycles until we dump the results
37 38 39 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 37 def count @count end |
#mode ⇒ Symbol
The stackprof mode
14 15 16 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 14 def mode @mode end |
#quit ⇒ Boolean
Quit the application when the profile data has been dumped
27 28 29 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 27 def quit @quit end |
#raw ⇒ Boolean
Whether stackprof saves raw samples
They are needed for post-processing like e.g. flamegraph. The default is false
22 23 24 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 22 def raw @raw end |
#results_path ⇒ Integer?
How many start/stop cycles until we dump the results
42 43 44 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 42 def results_path @results_path end |
#skip ⇒ Integer?
How many start/stop cycles to ignore before we start profiling
32 33 34 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 32 def skip @skip end |
Instance Method Details
#close ⇒ Object
136 137 138 139 140 141 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 136 def close return unless StackProf.running? StackProf.stop stackprof_dump_results end |
#dump(name, time, args) ⇒ Object
119 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 119 def dump(name, time, args); end |
#dump_time ⇒ Object
147 148 149 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 147 def dump_time 0 end |
#dump_timepoint(kind, _time, args) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 124 def dump_timepoint(kind, _time, args) tp_name = args[2] if TIMEPOINT_KIND_START.include?(kind) && (@start_matcher === tp_name) stackprof_handle_start_timepoint(tp_name) elsif TIMEPOINT_KIND_END.include?(kind) && (@stop_matcher === tp_name) stackprof_handle_stop_timepoint(tp_name) end nil end |
#flush_cycle(name, *args) ⇒ Object
151 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 151 def flush_cycle(name, *args); end |
#log_queue_size ⇒ Object
143 144 145 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 143 def log_queue_size 0 end |
#log_timepoints? ⇒ Boolean
115 116 117 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 115 def log_timepoints? true end |
#stackprof_dump_results ⇒ Object
110 111 112 113 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 110 def stackprof_dump_results StackProf.results(results_path) Robot.info "stackprof: results dumped on #{results_path}" end |
#stackprof_handle_start_timepoint(timepoint_name) ⇒ 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.
Start profiling
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 75 def stackprof_handle_start_timepoint(timepoint_name) return if StackProf.running? return if @remaining_count && @remaining_count <= 0 @remaining_skip ||= @skip if @remaining_skip > 0 @remaining_skip -= 1 return end Robot.info "stackprof: started on timepoint #{timepoint_name}" StackProf.start(mode: @mode.to_sym, raw: @raw) end |
#stackprof_handle_stop_timepoint(timepoint_name) ⇒ 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.
Handle the reception of a stop timepoint while stackprof was running
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 92 def stackprof_handle_stop_timepoint(timepoint_name) return unless StackProf.running? Robot.info "stackprof: stopped on timepoint #{timepoint_name}" StackProf.stop @remaining_count ||= @count if @remaining_count > 0 @remaining_count -= 1 Robot.info "stackprof: #{@count - @remaining_count} regions profiled" return unless @remaining_count == 0 end stackprof_dump_results Roby.app.quit if @quit end |
#start_on(matcher) ⇒ Object
Start profiling whenever a timepoint name matches the given matcher
60 61 62 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 60 def start_on(matcher) @start_matcher = matcher end |
#stop_on(matcher) ⇒ Object
Stop profiling whenever a timepoint name matches the given matcher
68 69 70 |
# File 'lib/roby/event_logging/stackprof_event_manager.rb', line 68 def stop_on(matcher) @stop_matcher = matcher end |