
memory inspector จะคอยดูการใช้งานหน่วยความจำ/พฤติกรรมของเว็บแอปพลิเคชัน ปัจจุบันทำงานบน Puppeteer ซึ่งเป็น API เพื่อควบคุม Chrome หรือ Chromium ที่ไม่มีส่วนหัวผ่าน DevTools Protocol
yarn add --dev memory-inspector const memoryInspector = require ( 'memory-inspector' )
const config = {
url : 'http://localhost:3000' ,
maxMemoryLimit : 20 * 1048576 , // should not pass of 20MB
maxMemoryPercentThreshold : 90 , // should not pass 90% of total memory
}
memoryInspector ( config ) . then ( ( info ) => console . log ( info ) )
/*
{ "exceededMemoryMaximum": 1528951424,
"exceededMemoryUsagePercent": true,
"jsHeapSizeLimit": "2.19 GB",
"memoryUsagePercent": 21900000,
"totalJSHeapSize": "1.53 GB",
"usedJSHeapSize": "1.53 GB" }
*/ const memoryInspector = require ( 'memory-inspector' )
const config = {
url : 'http://127.0.0.1:8080' ,
delay : 300 ,
formatted : false , // default is true
maxMemoryLimit : 20 * 1048576 , // should not pass of 20MB
maxMemoryPercentThreshold : 90 , // should not pass 90% of total memory
waitUntil : [ 'domContentLoaded' ] , // wait for browser events
}
memoryInspector ( config ) . then ( ( info ) => console . log ( info ) )
/*
{ usedJSHeapSize: 10000000,
totalJSHeapSize: 11900000,
jsHeapSizeLimit: 2190000000,
memoryUsagePercent: 438000000,
exceededMemoryMaximum: -10971520,
exceededMemoryUsagePercent: false }
*/ <string> URL ที่จะนำทางไปยังเพจ URL ควรมีรูปแบบ เช่น https://
<boolean> กำหนดว่าจะจัดรูปแบบไบต์เป็นขนาด เช่น: 2190000000 ถึง 2.19 GB โดยค่าเริ่มต้น มันเป็น true
<number> ทำให้รายงานช้าลงตามจำนวนมิลลิวินาทีที่ระบุ
<number> ตั้งค่าขีดจำกัดหน่วยความจำสูงสุดที่แอปพลิเคชันสามารถใช้ได้ โดยจะสะท้อนให้เห็นรายงาน exceededMemoryMaximum
<number> ตั้งค่าเกณฑ์เปอร์เซ็นต์หน่วยความจำสูงสุดบนแอปพลิเคชัน โดยจะสะท้อนให้เห็นในรายงาน exceededMemoryUsagePercent
<string|array<string>> เมื่อใดจึงจะถือว่าการนำทางสำเร็จ เมื่อพิจารณาอาร์เรย์ของสตริงเหตุการณ์ การนำทางจะถือว่าสำเร็จหลังจากเหตุการณ์ทั้งหมดเริ่มทำงานแล้ว
ขอบคุณ Puppeteer
จัดทำโดย Raphael Amorim ได้รับอนุญาตจาก MIT