Class: Hone::Profilers::MemoryProfiler
- Includes:
- MethodMatching
- Defined in:
- lib/hone/profilers/memory_profiler.rb
Instance Method Summary collapse
-
#alloc_percent_for(method_info) ⇒ Object
Returns allocation 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.
-
#cpu_percent_for(_method_info) ⇒ Object
Returns CPU percentage for a method (0.0-100.0) Always returns nil for MemoryProfiler since it tracks allocations, not CPU.
-
#hotspots(threshold: 1.0) ⇒ Object
Returns array of HotspotInfo for frames above threshold For MemoryProfiler, threshold applies to allocation percentage.
-
#initialize(profile_path) ⇒ MemoryProfiler
constructor
A new instance of MemoryProfiler.
Constructor Details
#initialize(profile_path) ⇒ MemoryProfiler
Returns a new instance of MemoryProfiler.
8 9 10 11 12 |
# File 'lib/hone/profilers/memory_profiler.rb', line 8 def initialize(profile_path) super parse_allocations end |
Instance Method Details
#alloc_percent_for(method_info) ⇒ Object
Returns allocation 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
22 23 24 25 26 27 |
# File 'lib/hone/profilers/memory_profiler.rb', line 22 def alloc_percent_for(method_info) frame = find_matching_frame(method_info) return nil unless frame frame[:alloc_percent] end |
#cpu_percent_for(_method_info) ⇒ Object
Returns CPU percentage for a method (0.0-100.0) Always returns nil for MemoryProfiler since it tracks allocations, not CPU
16 17 18 |
# File 'lib/hone/profilers/memory_profiler.rb', line 16 def cpu_percent_for(_method_info) nil end |
#hotspots(threshold: 1.0) ⇒ Object
Returns array of HotspotInfo for frames above threshold For MemoryProfiler, threshold applies to allocation percentage
31 32 33 34 35 36 |
# File 'lib/hone/profilers/memory_profiler.rb', line 31 def hotspots(threshold: 1.0) @frames .select { |frame| frame[:alloc_percent] >= threshold } .sort_by { |frame| -frame[:alloc_percent] } .map { |frame| build_hotspot_info(frame) } end |