|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const cp = require('child_process'); |
| 5 | +const fs = require('fs'); |
| 6 | +const path = require('path'); |
| 7 | +const tmpdir = require('../common/tmpdir'); |
| 8 | + |
| 9 | +if (!common.hasCrypto) |
| 10 | + common.skip('missing crypto'); |
| 11 | + |
| 12 | +const { hkdf } = require('crypto'); |
| 13 | +const { deflate } = require('zlib'); |
| 14 | +const { Blob } = require('buffer'); |
| 15 | + |
| 16 | +if (process.env.isChild === '1') { |
| 17 | + hkdf('sha512', 'key', 'salt', 'info', 64, () => {}); |
| 18 | + deflate('hello', () => {}); |
| 19 | + // Make async call |
| 20 | + const blob = new Blob(['h'.repeat(4096 * 2)]); |
| 21 | + blob.arrayBuffer(); |
| 22 | + return; |
| 23 | +} |
| 24 | + |
| 25 | +tmpdir.refresh(); |
| 26 | +const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log'); |
| 27 | + |
| 28 | +cp.spawnSync(process.execPath, |
| 29 | + [ |
| 30 | + '--trace-events-enabled', |
| 31 | + '--trace-event-categories', |
| 32 | + 'node.threadpoolwork.sync,node.threadpoolwork.async', |
| 33 | + __filename, |
| 34 | + ], |
| 35 | + { |
| 36 | + cwd: tmpdir.path, |
| 37 | + env: { |
| 38 | + ...process.env, |
| 39 | + isChild: '1', |
| 40 | + }, |
| 41 | + }); |
| 42 | + |
| 43 | +assert(fs.existsSync(FILE_NAME)); |
| 44 | +const data = fs.readFileSync(FILE_NAME); |
| 45 | +const traces = JSON.parse(data.toString()).traceEvents; |
| 46 | + |
| 47 | +assert(traces.length > 0); |
| 48 | + |
| 49 | +let blobCount = 0; |
| 50 | +let zlibCount = 0; |
| 51 | +let cryptoCount = 0; |
| 52 | + |
| 53 | +traces.forEach((item) => { |
| 54 | + if ([ |
| 55 | + 'node,node.threadpoolwork,node.threadpoolwork.sync', |
| 56 | + 'node,node.threadpoolwork,node.threadpoolwork.async', |
| 57 | + ].includes(item.cat)) { |
| 58 | + if (item.name === 'blob') { |
| 59 | + blobCount++; |
| 60 | + } else if (item.name === 'zlib') { |
| 61 | + zlibCount++; |
| 62 | + } else if (item.name === 'crypto') { |
| 63 | + cryptoCount++; |
| 64 | + } |
| 65 | + } |
| 66 | +}); |
| 67 | + |
| 68 | +// There are three types, each type has two async events and sync events at least |
| 69 | +assert.ok(blobCount >= 4); |
| 70 | +assert.ok(zlibCount >= 4); |
| 71 | +assert.ok(cryptoCount >= 4); |
0 commit comments