内存检查¶
跟踪 WebKit 的内存使用情况对于确保我们不会占用过多资源至关重要。操作系统(结合 WebKit 工具)提供了多种检查 WebKit 的方法,以发现我们的内存分配位置。
构建设置¶
Malloc 堆分解¶
Malloc 堆分解允许对每个类分配的内存进行细粒度分析。标有 WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ClassName);
的类在使用 footprint
等工具时将被单独标记。
要启用此构建设置,您需要翻转两个标志。一个在 PlatformEnable.h
中,另一个在 BPlatform.h
中。
/* Source/WTF/wtf/PlatformEnable.h */
/*
* Enable this to put each IsoHeap and other allocation categories into their own malloc heaps, so that tools like vmmap can show how big each heap is.
* Turn BENABLE_MALLOC_HEAP_BREAKDOWN on in bmalloc together when using this.
*/
#if !defined(ENABLE_MALLOC_HEAP_BREAKDOWN)
#define ENABLE_MALLOC_HEAP_BREAKDOWN 0
#endif
/* Source/bmalloc/bmalloc/BPlatform.h */
/* Enable this to put each IsoHeap and other allocation categories into their own malloc heaps, so that tools like vmmap can show how big each heap is. */
#define BENABLE_MALLOC_HEAP_BREAKDOWN 0
命令¶
内存占用¶
Footprint 是一个 macOS 特定的工具,允许开发者检查跨区域的内存使用情况。
> footprint WebKit
Found process com.apple.WebKit.WebContent [27416] from partial name WebKit
======================================================================
com.apple.WebKit.WebContent [27416]: 64-bit Footprint: 142 MB (16384 bytes per page)
======================================================================
Dirty Clean Reclaimable Regions Category
--- --- --- --- ---
108 MB 0 B 23 MB 11 WebKit malloc
9664 KB 0 B 0 B 24 MALLOC_TINY
6384 KB 0 B 16 KB 8 MALLOC_SMALL
3904 KB 0 B 0 B 768 JS VM Gigacage
...
--- --- --- --- ---
142 MB 21 MB 23 MB 7001 TOTAL
Auxiliary data:
dirty: N
phys_footprint_peak: 424 MB
phys_footprint: 142 MB
结果¶
请参阅 man footprint
以获取此工具的完整指南。
脏区¶
由进程写入的内存。包括交换内存、非易失性内存和隐式写入的内存。
干净区¶
既不是脏区也不是可回收的内存。
可回收¶
标记为可重复使用的内存。
区域¶
对此行有贡献的 VM 区域数量。
类别¶
此条目的描述性名称。