Passed
Push — master ( 0feaa2...c02782 )
by Dmytro
02:35
created

src/counters/ProcessMemory.js   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 30
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 30
rs 10
c 0
b 0
f 0
mnd 0
bc 0
fnc 5
bpm 0
cpm 1
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A ProcessMemoryCountrer.bench 0 3 1
A ProcessMemoryCountrer.diff 0 13 2
A ProcessMemoryCountrer.prettify 0 4 1
A ProcessMemory.js ➔ safeGetKey 0 3 1
1
import Counter from './Counter';
2
3
function safeGetKey(report, key) {
4
    return report[key] || 0;
5
}
6
7
export default class ProcessMemoryCountrer extends Counter {
8
    bench() {
9
        return process.memoryUsage();
10
    }
11
12
    static prettify(data) {
13
        // eslint-disable-next-line no-magic-numbers
14
        return `${Math.round(data / 1024 / 1024 * 100) / 100}MB`;
15
    }
16
17
    diff(start, end) {
18
        const res = {};
19
        const keys = new Set([
20
            ...Object.keys(start),
21
            ...Object.keys(end)
22
        ]);
23
24
        keys.forEach(key => {
25
            res[key] = safeGetKey(end, key) - safeGetKey(start, key);
26
        });
27
28
        return res;
29
    }
30
}
31