Class: BetterRailsDebugger::GroupInstance
- Inherits:
-
Object
- Object
- BetterRailsDebugger::GroupInstance
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/better_rails_debugger/group_instance.rb
Instance Method Summary collapse
- #allocations_per_file_hash ⇒ Object
-
#big_classes(max_size = 1.megabytes) ⇒ Object
Return an array of hashed that contains some information about the classes that consume more than
max_sizebytess. -
#big_files(max_size = 10.megabytes) ⇒ Object
Return an array of hash file => mem that consume more than 10 MB(default) or ram aprox TODO: The amount of consumed ram must be configurable.
- #count_methods ⇒ Object
- #files_that_use_more_memory(n) ⇒ Object
- #files_with_more_allocations(n) ⇒ Object
-
#memsize_per_file_hash ⇒ Object
Memory methods.
- #most_used_methods(n) ⇒ Object
-
#track_allocation_of?(path) ⇒ Boolean
Trace point methods.
Instance Method Details
#allocations_per_file_hash ⇒ Object
32 33 34 35 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 32 def allocations_per_file_hash return @allocations_per_file if @allocations_per_file.present? @allocations_per_file = JSON.parse(allocations_per_file.to_s) rescue {} end |
#big_classes(max_size = 1.megabytes) ⇒ Object
Return an array of hashed that contains some information about the classes that consume more than max_size bytess
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 72 def big_classes(max_size=1.megabytes) return @big_classes if @big_classes @big_classes = {} ObjectInformation.where(:group_instance_id => self.id, :memsize.gt => max_size).all.each do |object| @big_classes[object.class_name] ||= {total_mem: 0, average: 0, count: 0} @big_classes[object.class_name][:total_mem] += object.memsize @big_classes[object.class_name][:count] += 1 end @big_classes.each_pair do |klass, hash| @big_classes[klass][:average] = @big_classes[klass][:total_mem] / @big_classes[klass][:count] end @big_classes end |
#big_files(max_size = 10.megabytes) ⇒ Object
Return an array of hash file => mem that consume more than 10 MB(default) or ram aprox TODO: The amount of consumed ram must be configurable
64 65 66 67 68 69 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 64 def big_files(max_size=10.megabytes) return @big_files if @big_files @big_files = (memsize_per_file_hash || {}).select do |key, size| size >= max_size end end |
#count_methods ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 45 def count_methods return @count_methods if @count_methods @count_methods = Hash.new trace_point_items.each do |item| @count_methods["#{item.source_file}:#{item.source_line}"] ||= { item: item, count: 0 } @count_methods["#{item.source_file}:#{item.source_line}"][:count] += 1 end @count_methods end |
#files_that_use_more_memory(n) ⇒ Object
37 38 39 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 37 def files_that_use_more_memory(n) memsize_per_file_hash.to_a.sort_by do |a| a[1] end.reverse[0..n] end |
#files_with_more_allocations(n) ⇒ Object
41 42 43 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 41 def files_with_more_allocations(n) allocations_per_file_hash.to_a.sort_by do |a| a[1] end.reverse[0..n] end |
#memsize_per_file_hash ⇒ Object
Memory methods
27 28 29 30 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 27 def memsize_per_file_hash return @memsize_per_file_hash if @memsize_per_file_hash.present? @memsize_per_file_hash = JSON.parse(memsize_per_file.to_s) rescue {} end |
#most_used_methods(n) ⇒ Object
58 59 60 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 58 def most_used_methods(n) count_methods.to_a.sort_by do |a| a[1][:count] end.reverse[0..n].to_h end |
#track_allocation_of?(path) ⇒ Boolean
Trace point methods
88 89 90 91 |
# File 'app/models/better_rails_debugger/group_instance.rb', line 88 def track_allocation_of?(path) return true if match_file_list?(path) or called_from_caller_file?(path) false end |