|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +/** |
| 4 | + * This script is used for quickly tracing the characteristics of the following: |
| 5 | + * |
| 6 | + * - `require('fastboot')` - Labeled in the trace as `"require fastboot"` |
| 7 | + * - `new FastBoot({ distPath: '...' })` - Labeled in the trace as `"initial setup"` |
| 8 | + * - `await fastboot.visit('/')` - Labeled in the trace as `"first visit"` |
| 9 | + * - `await fastboot.visit('/')` - Labeled in the trace as `"second visit"` |
| 10 | + * - `await fastboot.visit('/')` - Labeled in the trace as `"third visit"` |
| 11 | + * |
| 12 | + * General usage and evaluation steps: |
| 13 | + * |
| 14 | + * 1. run the script (e.g. `node dev/trace-multiple-visit.js`) |
| 15 | + * 2. Navigate Chrome to the `chrome:tracing` |
| 16 | + * 3. Click "load" (in the top left) and navigate to this repo, select the `node_trace.1.log` file |
| 17 | + * 4. Review / evaluate |
| 18 | + */ |
| 19 | +const path = require('path'); |
| 20 | +const { performance } = require('perf_hooks'); |
| 21 | + |
| 22 | +// can also enable these via `node --trace-event-categories` |
| 23 | +// enabling here via the JS API to make invocation and testing |
| 24 | +// of this script a bit easier |
| 25 | +/* eslint-disable node/no-missing-require */ |
| 26 | +const trace_events = require('trace_events'); |
| 27 | +const tracing = trace_events.createTracing({ |
| 28 | + categories: ['v8', 'node.perf', 'node.console', 'node.vm.script'], |
| 29 | +}); |
| 30 | + |
| 31 | +async function main() { |
| 32 | + tracing.enable(); |
| 33 | + |
| 34 | + performance.mark('require fastboot start'); |
| 35 | + const FastBoot = require('../src/index'); |
| 36 | + performance.mark('require fastboot end'); |
| 37 | + performance.measure('require fastboot', 'require fastboot start', 'require fastboot end'); |
| 38 | + |
| 39 | + const distPath = path.join(__dirname, '../test/fixtures/basic-app'); |
| 40 | + performance.mark('setup start'); |
| 41 | + const fastboot = new FastBoot({ |
| 42 | + distPath, |
| 43 | + }); |
| 44 | + performance.mark('setup end'); |
| 45 | + performance.measure('initial setup', 'setup start', 'setup end'); |
| 46 | + |
| 47 | + performance.mark('visit start'); |
| 48 | + let result = await fastboot.visit('/'); |
| 49 | + await result.html(); |
| 50 | + performance.mark('visit end'); |
| 51 | + performance.measure('first visit', 'visit start', 'visit end'); |
| 52 | + |
| 53 | + performance.mark('visit start'); |
| 54 | + result = await fastboot.visit('/'); |
| 55 | + await result.html(); |
| 56 | + performance.mark('visit end'); |
| 57 | + performance.measure('second visit', 'visit start', 'visit end'); |
| 58 | + |
| 59 | + performance.mark('visit start'); |
| 60 | + result = await fastboot.visit('/'); |
| 61 | + await result.html(); |
| 62 | + performance.mark('visit end'); |
| 63 | + performance.measure('third visit', 'visit start', 'visit end'); |
| 64 | +} |
| 65 | + |
| 66 | +main(); |
0 commit comments