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,其大小我知道(并且它是唯一的),并且我想检索该数组。可以用快照来做吗?
元字段组解释了快照的不同数组的内容。
快照具有节点数组。该数组对于堆中的每个节点都有 7 个数字,node_fields 数组描述了所有这 7 个数字的含义。
同时node_types数组描述了这7个数字的类型。例如,如果节点数组中有接下来的 7 个数字 [ ....., 2, 9, 13, 42, 0, 0, 0, ......
然后是堆中的第 N 个节点
Edges 数组的每条边都有一个三元组数字,您可以在 Edges_fields 中看到每个数字的名称以及 Edge_types 数组中的类型。例如,edges 数组中偏移量 0 处的三元组 2, 17, 79 表示:
我希望这个解释可以让您了解如何理解堆快照的内容。