|
Last change
on this file 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 |
|
|---|
| 3 | const PROPERTIES = [ 'rss', 'heapTotal', 'heapUsed', 'external' ]
|
|---|
| 4 |
|
|---|
| 5 | let memory
|
|---|
| 6 |
|
|---|
| 7 | module.exports = {
|
|---|
| 8 | initialise,
|
|---|
| 9 | update,
|
|---|
| 10 | report
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | function 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 |
|
|---|
| 23 | function update () {
|
|---|
| 24 | const currentMemory = process.memoryUsage()
|
|---|
| 25 | PROPERTIES.forEach(name => updateProperty(name, currentMemory))
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | function 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 |
|
|---|
| 37 | function report () {
|
|---|
| 38 | PROPERTIES.forEach(name => reportProperty(name))
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | function 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.