source: frontend/node_modules/bfj/src/memory.js@ cdcff72

Last change on this file since cdcff72 was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 856 bytes
Line 
1'use strict'
2
3const PROPERTIES = [ 'rss', 'heapTotal', 'heapUsed', 'external' ]
4
5let memory
6
7module.exports = {
8 initialise,
9 update,
10 report
11}
12
13function initialise () {
14 memory = PROPERTIES.reduce((result, name) => {
15 result[name] = {
16 sum: 0,
17 hwm: 0
18 }
19 return result
20 }, { count: 0 })
21}
22
23function update () {
24 const currentMemory = process.memoryUsage()
25 PROPERTIES.forEach(name => updateProperty(name, currentMemory))
26}
27
28function updateProperty (name, currentMemory) {
29 const m = memory[name]
30 const c = currentMemory[name]
31 m.sum += c
32 if (c > m.hwm) {
33 m.hwm = c
34 }
35}
36
37function report () {
38 PROPERTIES.forEach(name => reportProperty(name))
39}
40
41function reportProperty (name) {
42 const m = memory[name]
43 // eslint-disable-next-line no-console
44 console.log(`mean ${name}: ${m.sum / memory.count}; hwm: ${m.hwm}`)
45}
Note: See TracBrowser for help on using the repository browser.