- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用程式
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送電子郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用程式擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 資料限制
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用工具模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
NodeJS - v8.getHeapStatistics() 方法
NodeJS v8.getHeapStatistics() 方法用於檢索從 v8 版本派生的堆統計資訊。此方法返回有關堆的統計資訊,例如總堆大小、已用堆大小、堆大小限制、總可用大小等。
getHeapSpaceStatistics() 返回基於系統空間的統計資訊,而 getHeapStatistics() 方法檢索整個系統的統計資訊。
語法
以下是 NodeJS v8.getHeapStatistics() 方法 的語法:
v8.getHeapStatistics()
引數
此方法不接受任何引數。
返回值
此方法返回一個包含從 v8 派生的堆統計資訊的 物件。
以下是返回物件中包含的屬性。
total_heap_size - 此屬性指定總堆空間大小。
total_heap_size_executable - 此屬性指定可用於執行的總堆大小。
total_physical_size - 此屬性指定磁碟上可用的總物理大小。
total_available_size - 此屬性指定系統可用的總大小。
used_heap_size - 此屬性指定已使用的堆大小。
heap_size_limit - 此屬性指定使用者/應用程式的堆大小限制。
malloced_memory - 此屬性指定分配給應用程式的記憶體。
peak_malloced_memory - 此屬性指定應用程式可用的最大記憶體限制。
does_zap_garbage - 這是一個布林值 0/1,它告訴系統是否啟用了 --zap_code_space 選項。
number_of_native_contexts - 這是當前活動的最頂層上下文數。此數字增加表明可能存在記憶體洩漏。
number_of_detached_contexts - 這些是由垃圾收集器分離但尚未收集的上下文數。如果此數字不為零,則表示潛在的記憶體洩漏。
示例
在以下示例中,我們嘗試使用 NodeJS getHeapStatistics() 方法獲取從 v8 派生的所有堆統計資訊。
const v8 = require('v8');
console.log(v8.getHeapStatistics());
輸出
{
total_heap_size: 5369856,
total_heap_size_executable: 524288,
total_physical_size: 4298984,
total_available_size: 17226372488,
used_heap_size: 2855168,
heap_size_limit: 17230200832,
malloced_memory: 8192,
peak_malloced_memory: 418904,
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0
}
示例
在下面的示例中,我們嘗試獲取 v8 堆的統計資訊,例如總堆大小、已用堆大小和堆大小限制。
const v8 = require('v8');
let statistics = v8.getHeapStatistics();
console.log("total_heap_size: " + statistics['total_heap_size']);
console.log("used_heap_size: " + statistics['used_heap_size']);
console.log("heap_size_limit: " + statistics['heap_size_limit']);
輸出
total_heap_size: 6086656 used_heap_size: 3769624 heap_size_limit: 17213423616 does_zap_garbage: 0
