Project

General

Profile

Actions

Feature #11599

open

Dump entries of hash in ObjectSpace

Added by yosiat (Yosi Attias) over 8 years ago. Updated over 8 years ago.

Status:
Open
Target version:
-
[ruby-core:71099]

Description

Hi,

This is my first c code contribution :)

I am helping developing heap-analyzer (github.com/tenderlove/heap-analyzer), and currently the dumps lacks of "type metadata" information, like:

  • Hash entries - the keys and value
  • Array items - the items of the array

etc.

In the included patch, I have changed the dump of hash to add entries of hash.
For example, given the next hash:

hash = {
    int_key: 1,
    str_key: "This is my string",
    inner_hash: { b: 2 }
}

The dump result (ObjectSpace.dump(hash)) will be:

{
    "address": "0x007fbc01110340",
    "type": "HASH",
    "class": "0x007fbc0109b400",
    "size": 3,
    "entries": [
        {
            "is_key_address": false,
            "key": ":int_key",
            "is_value_address": false,
            "value": "1"
        },
        {
            "is_key_address": false,
            "key": ":str_key",
            "is_value_address": true,
            "value": "0x007fbc01110390"
        },
        {
            "is_key_address": false,
            "key": ":inner_hash",
            "is_value_address": true,
            "value": "0x007fbc01110368"
        }
    ],
    "references": [
        "0x007fbc01110390",
        "0x007fbc01110368"
    ],
    "memsize": 232,
    "flags": {
        "wb_protected": true
    }
}

As you can see, I have the "entries" array, where each entry contains: "is_key_address", "is_value_address" - if the key/value are special consts the inspected value will be printed in the "key"/"value" properties, other their address will be print.

Hope you will accept the patch (and I can submit another one for arrays),
Yosi.


Files

objspace_dump_hash_entries.patch (4.8 KB) objspace_dump_hash_entries.patch Patch yosiat (Yosi Attias), 10/17/2015 12:05 PM
objspace_dump.patch (4.53 KB) objspace_dump.patch yosiat (Yosi Attias), 10/19/2015 06:49 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0