Class: Hone::Profilers::StackProf
- Includes:
- MethodMatching
- Defined in:
- lib/hone/profilers/stackprof.rb
Instance Method Summary collapse
-
#cpu_percent_for(method_info) ⇒ Object
Returns CPU percentage for a method (0.0-100.0) method_info can be a Hash with :name and/or :file keys, or a String method name.
-
#hotspots(threshold: 1.0) ⇒ Object
Returns array of HotspotInfo for frames above threshold.
-
#initialize(profile_path) ⇒ StackProf
constructor
A new instance of StackProf.
Constructor Details
#initialize(profile_path) ⇒ StackProf
Returns a new instance of StackProf.
8 9 10 11 12 13 14 |
# File 'lib/hone/profilers/stackprof.rb', line 8 def initialize(profile_path) super # Prefer ruby_samples (excludes C frames) for more accurate Ruby percentages @total_samples = @data["ruby_samples"] || @data["samples"] || calculate_total_samples parse_frames end |
Instance Method Details
#cpu_percent_for(method_info) ⇒ Object
Returns CPU percentage for a method (0.0-100.0) method_info can be a Hash with :name and/or :file keys, or a String method name
18 19 20 21 22 23 |
# File 'lib/hone/profilers/stackprof.rb', line 18 def cpu_percent_for(method_info) frame = find_matching_frame(method_info) return nil unless frame frame[:cpu_percent] end |
#hotspots(threshold: 1.0) ⇒ Object
Returns array of HotspotInfo for frames above threshold
26 27 28 29 30 31 |
# File 'lib/hone/profilers/stackprof.rb', line 26 def hotspots(threshold: 1.0) @frames .select { |frame| frame[:cpu_percent] >= threshold } .sort_by { |frame| -frame[:cpu_percent] } .map { |frame| build_hotspot_info(frame) } end |