稳定测试版
This commit is contained in:
25
main/utils/mem.js
Normal file
25
main/utils/mem.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// main/utils/mem.js
|
||||
const { app } = require('electron')
|
||||
|
||||
function toMB(v) {
|
||||
if (!v || v <= 0) return 0
|
||||
const kbToMB = v / 1024
|
||||
if (kbToMB > 1) return Number(kbToMB.toFixed(1))
|
||||
return Number(v.toFixed(1))
|
||||
}
|
||||
function dumpAllMem() {
|
||||
try {
|
||||
const metrics = app.getAppMetrics()
|
||||
const report = metrics.map(m => {
|
||||
const mem = m.memory || {}
|
||||
const workingSetMB = toMB(mem.workingSetSize ?? mem.workingSet ?? 0)
|
||||
const privateMB = toMB(mem.privateBytes ?? mem.private ?? 0)
|
||||
const sharedMB = toMB(mem.shared ?? 0)
|
||||
return { pid: m.pid, type: m.type, workingSetMB, privateMB, sharedMB }
|
||||
})
|
||||
// console.log(report)
|
||||
} catch (e) {
|
||||
console.warn('getAppMetrics error:', e)
|
||||
}
|
||||
}
|
||||
module.exports = { toMB, dumpAllMem }
|
||||
Reference in New Issue
Block a user