-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathcpu_profiler.js
More file actions
56 lines (47 loc) · 1.35 KB
/
cpu_profiler.js
File metadata and controls
56 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const {
MathFloor,
} = primordials;
const {
validateNumber,
validateObject,
} = require('internal/validators');
const kMicrosPerMilli = 1_000;
const kMaxSamplingIntervalUs = 0x7FFFFFFF;
const kMaxSamplingIntervalMs = kMaxSamplingIntervalUs / kMicrosPerMilli;
const kMaxSamplesUnlimited = 0xFFFF_FFFF;
function normalizeCpuProfileOptions(options = {}) {
validateObject(options, 'options');
// TODO(ishabi): add support for 'mode' and 'filterContext' options
const {
sampleInterval,
maxBufferSize,
} = options;
let samplingIntervalMicros = 0;
if (sampleInterval !== undefined) {
validateNumber(sampleInterval,
'options.sampleInterval',
0,
kMaxSamplingIntervalMs);
samplingIntervalMicros = MathFloor(sampleInterval * kMicrosPerMilli);
if (sampleInterval > 0 && samplingIntervalMicros === 0) {
samplingIntervalMicros = 1;
}
}
const size = maxBufferSize;
let normalizedMaxSamples = kMaxSamplesUnlimited;
if (size !== undefined) {
validateNumber(size,
'options.maxBufferSize',
1,
kMaxSamplesUnlimited);
normalizedMaxSamples = MathFloor(size);
}
return {
samplingIntervalMicros,
maxSamples: normalizedMaxSamples,
};
}
module.exports = {
normalizeCpuProfileOptions,
};