Chrome堆快照结构解释

Lig*_*eel 2 javascript snapshot heap-memory javascript-objects google-chrome-devtools

使用 selenium,我拍摄了一个网站的内存快照并driver.execute_script(":takeHeapSnapshot")提取了其元数据:

{
    "snapshot": {
        "meta": {
            "node_fields": [
                "type", "name", "id", "self_size", "edge_count", "trace_node_id", "detachedness"
            ],
            "node_types": [
                ["hidden", "array", "string", "object", "code", "closure", "regexp", "number", "native", "synthetic", "concatenated string", "sliced string", "symbol", "bigint"],
                "string", "number", "number", "number", "number", "number"
            ],
            "edge_fields": [
                "type", "name_or_index", "to_node"
            ],
            "edge_types": [
                ["context", "element", "property", "internal", "hidden", "shortcut", "weak"],
                "string_or_number", "node"
            ],
            "trace_function_info_fields": [
                "function_id", "name", "script_name", "script_id", "line", "column"
            ],
            "trace_node_fields": [
                "id", "function_info_index", "count", "size", "children"
            ],
            "sample_fields": [
                "timestamp_us", "last_assigned_id"
            ],
            "location_fields": [
                "object_index", "script_id", "line", "column"
            ]
        },
        "node_count": 6182075,
        "edge_count": 17793245,
        "trace_function_count": 0
    }
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下每个字段的含义以及如何使用该信息来提取数据吗?什么是节点、边、位置字段等。举个例子,假设我在堆上有一个 ArrayBuffer,其大小我知道(并且它是唯一的),并且我想检索该数组。可以用快照来做吗?

loi*_*slo 5

元字段组解释了快照的不同数组的内容。

快照具有节点数组。该数组对于堆中的每个节点都有 7 个数字,node_fields 数组描述了所有这 7 个数字的含义。

同时node_types数组描述了这7个数字的类型。例如,如果节点数组中有接下来的 7 个数字 [ ....., 2, 9, 13, 42, 0, 0, 0, ......

然后是堆中的第 N 个节点

  1. 有“type”字符串,因为node_types[0][2] == 'string',
  2. 有“名称”,隐藏在堆的字符串数组中。即字符串[9],
  3. 有“id”13,
  4. 使用 42 字节的堆
  5. 有 0 个对堆中其他对象的引用
  6. “trace_node_id”= 0,
  7. “分离”= 0,

Edges 数组的每条边都有一个三元组数字,您可以在 Edges_fields 中看到每个数字的名称以及 Edge_types 数组中的类型。例如,edges 数组中偏移量 0 处的三元组 2, 17, 79 表示:

  1. 边缘实际上是对象的属性,因为edge_types[0][2] = 'property'
  2. 属性的名称隐藏在索引为 17 的字符串数组中
  3. 它指向id为79的节点。(其实我忘了,是节点的索引还是节点的id)
  4. 如果nodes数组的第一个节点的edge_count = 2,则edges数组的前2个三元组是从该节点到其他一些节点的边,依此类推。

我希望这个解释可以让您了解如何理解堆快照的内容。