Skip to content

Commit 43f39ef

Browse files
Robert Jacksonkrisselden
andcommitted
Add dev script to make tracing easier.
This creates a `./dev` folder (for stashing helpful development scripts/utils/etc). The specific file added here (`dev/trace-multiple-visit.js') can be used for quickly tracing the characteristics of the following: * `require('fastboot')` - Labeled in the trace as `"require fastboot"` * `new FastBoot({ distPath: '...' })` - Labeled in the trace as `"initial setup"` * `await fastboot.visit('/')` - Labeled in the trace as `"first visit"` * `await fastboot.visit('/')` - Labeled in the trace as `"second visit"` * `await fastboot.visit('/')` - Labeled in the trace as `"third visit"` General usage and evaluation steps: 1. run the script (e.g. `node dev/trace-multiple-visit.js`) 2. Navigate Chrome to the `chrome:tracing` 3. Click "load" (in the top left) and navigate to this repo, select the `node_trace.1.log` file 4. Review / evaluate Co-authored-by: Kris Selden <[email protected]>
1 parent 90a378c commit 43f39ef

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

.eslintrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,20 @@ module.exports = {
1212
rules: {
1313
'no-console': ['error', { allow: ['warn', 'error'] }],
1414
},
15+
overrides: [
16+
// override eslint in the dev/* folder to allow features from more recent
17+
// Node versions
18+
{
19+
files: ['dev/**/*.js'],
20+
rules: {
21+
'node/no-unsupported-features/node-builtins': [
22+
'error',
23+
{
24+
version: '>=10.0.0',
25+
ignores: [],
26+
},
27+
],
28+
},
29+
},
30+
],
1531
};

dev/trace-multiple-visit.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)