forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.js
53 lines (46 loc) · 1.08 KB
/
trace.js
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
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [100000],
method: ['trace', 'isTraceCategoryEnabled']
}, {
flags: [
'--expose-internals',
'--no-warnings',
'--trace-event-categories', 'foo',
]
});
const {
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
} = common.binding('constants').trace;
function doTrace(n, trace) {
bench.start();
for (let i = 0; i < n; i++) {
trace(kBeforeEvent, 'foo', 'test', 0, 'test');
}
bench.end(n);
}
function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
bench.start();
for (let i = 0; i < n; i++) {
isTraceCategoryEnabled('foo');
isTraceCategoryEnabled('bar');
}
bench.end(n);
}
function main({ n, method }) {
const {
trace,
isTraceCategoryEnabled
} = common.binding('trace_events');
switch (method) {
case 'trace':
doTrace(n, trace);
break;
case 'isTraceCategoryEnabled':
doIsTraceCategoryEnabled(n, isTraceCategoryEnabled);
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
}