lib/memdump/memory_dump.rb
# Replace all objects in dump by a single "group" object
Replace all objects in dump by a single "group" object
Replace all objects in dump by a single " group " object
def group(name, dump, attributes = Hash.new)
            group_addresses   = Set.new
            group_references  = Set.new
            dump.each_record do |r|
                group_addresses << r['address']
                group_references.merge(r['references'])
            end
            group_record = attributes.dup
            group_record['address']    = name
            group_record['references'] = group_references - group_addresses
            updated = Hash[name => group_record]
            each_record do |record|
                next if group_addresses.include?(record['address'])
                updated_record = record.dup
                updated_record['references'] -= group_addresses
                if updated_record['references'].size != record['references'].size
                    updated_record['references'] << name
                end
                if group_addresses.include?(updated_record['class_address'])
                    updated_record['class_address'] = name
                end
                if group_addresses.include?(updated_record['class'])
                    updated_record['class'] = name
                end
                updated[updated_record['address']] = updated_record
            end
            MemoryDump.new(updated)
        end
def group ( name , dump , attributes = Hash . new ) group_addresses = Set . new group_references = Set . new dump . each_record do | r | group_addresses << r [ 'address' ] group_references . merge ( r [ 'references' ] ) end group_record = attributes . dup group_record [ 'address' ] = name group_record [ 'references' ] = group_references - group_addresses updated = Hash [ name => group_record ] each_record do | record | next if group_addresses . include? ( record [ 'address' ] ) updated_record = record . dup updated_record [ 'references' ] -= group_addresses if updated_record [ 'references' ] . size != record [ 'references' ] . size updated_record [ 'references' ] << name end if group_addresses . include? ( updated_record [ 'class_address' ] ) updated_record [ 'class_address' ] = name end if group_addresses . include? ( updated_record [ 'class' ] ) updated_record [ 'class' ] = name end updated [ updated_record [ 'address' ] ] = updated_record end MemoryDump . new ( updated ) end
Replace all objects in dump by a single "group" object
Replace all objects in dump by a single " group " object
name
dump
attributes
new