diff options
author | James M Snell <jasnell@gmail.com> | 2018-05-14 09:25:50 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-07-22 07:36:27 -0700 |
commit | f7454a53f1318837ea2ca8f2ad495a9869b80e81 (patch) | |
tree | 309e7f3b9d3662a16dd2ecfcbc615a10aaf31b46 /benchmark | |
parent | a706456f71e28d4317beb0bf9da7a31adbf11ca5 (diff) | |
download | node-new-f7454a53f1318837ea2ca8f2ad495a9869b80e81.tar.gz |
trace_events: add support for builtin trace
PR-URL: https://github.com/nodejs/node/pull/21899
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/misc/trace.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/benchmark/misc/trace.js b/benchmark/misc/trace.js new file mode 100644 index 0000000000..75c87d363a --- /dev/null +++ b/benchmark/misc/trace.js @@ -0,0 +1,75 @@ +'use strict'; + +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + n: [100000], + method: ['trace', 'emit', 'isTraceCategoryEnabled', 'categoryGroupEnabled'] +}, { + flags: ['--expose-internals', '--trace-event-categories', 'foo'] +}); + +const { + trace, + isTraceCategoryEnabled, + emit, + categoryGroupEnabled +} = process.binding('trace_events'); + +const { + TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent +} = process.binding('constants').trace; + +function doEmit(n) { + bench.start(); + for (var i = 0; i < n; i++) { + emit(kBeforeEvent, 'foo', 'test', 0, 'arg1', 1); + } + bench.end(n); +} + +function doTrace(n) { + bench.start(); + for (var i = 0; i < n; i++) { + trace(kBeforeEvent, 'foo', 'test', 0, 'test'); + } + bench.end(n); +} + +function doIsTraceCategoryEnabled(n) { + bench.start(); + for (var i = 0; i < n; i++) { + isTraceCategoryEnabled('foo'); + isTraceCategoryEnabled('bar'); + } + bench.end(n); +} + +function doCategoryGroupEnabled(n) { + bench.start(); + for (var i = 0; i < n; i++) { + categoryGroupEnabled('foo'); + categoryGroupEnabled('bar'); + } + bench.end(n); +} + +function main({ n, method }) { + switch (method) { + case '': + case 'trace': + doTrace(n); + break; + case 'emit': + doEmit(n); + break; + case 'isTraceCategoryEnabled': + doIsTraceCategoryEnabled(n); + break; + case 'categoryGroupEnabled': + doCategoryGroupEnabled(n); + break; + default: + throw new Error(`Unexpected method "${method}"`); + } +} |