|
1 | 1 | const fs = require("fs"); |
2 | 2 | const Trace = require("chrome-trace-event").Tracer; |
| 3 | +const validateOptions = require("schema-utils"); |
| 4 | +const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json"); |
3 | 5 | let inspector = undefined; |
4 | 6 |
|
5 | 7 | try { |
|
8 | 10 | console.log("Unable to CPU profile in < node 8.0"); |
9 | 11 | } |
10 | 12 |
|
11 | | -// TODO: Add this to webpack.js.org docs for this plugin, and for profiling build times |
12 | | -/** |
13 | | - * How this plugin works: (placeholder until in docs) |
14 | | - * |
15 | | - * In chrome, open the `Profile Tab`, when you run webpack, |
16 | | - * this plugin will output an events.json file that you |
17 | | - * can drag and drop into the profiler. It will then display timeline stats and calls per plugin! |
18 | | - * |
19 | | - * Example: https://chromedevtools.github.io/timeline-viewer/?url=https%3A%2F%2Fgist.githubusercontent.com%2FTheLarkInn%2Fb94b728fa5e22f62c312e110a9944768%2Fraw%2Fcb672fb3f661a17576803e41db6030382b1a0fc9%2Fevents.json&loadTimelineFromURL=drive://163GY-H0wvF9rSrlwjJcrdTL-YLnppp55 |
20 | | - */ |
21 | | - |
22 | 13 | class Profiler { |
23 | 14 | constructor(inspector) { |
24 | 15 | this.session = undefined; |
@@ -81,18 +72,18 @@ class Profiler { |
81 | 72 | } |
82 | 73 |
|
83 | 74 | /** |
84 | | - * @param {string} outPath The location where to write the log. |
| 75 | + * @param {string} outputPath The location where to write the log. |
85 | 76 | * @returns {{trace: ?, counter: number, profiler: Profiler}} The trace object |
86 | 77 | */ |
87 | | -function createTrace(outPath) { |
| 78 | +function createTrace(outputPath) { |
88 | 79 | const trace = new Trace({ |
89 | 80 | noStream: true |
90 | 81 | }); |
91 | 82 | const profiler = new Profiler(inspector); |
92 | 83 |
|
93 | 84 | let counter = 0; |
94 | 85 |
|
95 | | - trace.pipe(fs.createWriteStream(outPath)); |
| 86 | + trace.pipe(fs.createWriteStream(outputPath)); |
96 | 87 | // These are critical events that need to be inserted so that tools like |
97 | 88 | // chrome dev tools can load the profile. |
98 | 89 | trace.instantEvent({ |
@@ -133,14 +124,14 @@ function createTrace(outPath) { |
133 | 124 | const pluginName = "ProfilingPlugin"; |
134 | 125 |
|
135 | 126 | class ProfilingPlugin { |
136 | | - // TODO: Add plugin schema validation here since there are options. |
137 | 127 | constructor(opts) { |
| 128 | + validateOptions(schema, opts || {}, "Profiling plugin"); |
138 | 129 | opts = opts || {}; |
139 | | - this.outPath = opts.outPath || "events.json"; |
| 130 | + this.outputPath = opts.outputPath || "events.json"; |
140 | 131 | } |
141 | 132 |
|
142 | 133 | apply(compiler) { |
143 | | - const tracer = createTrace(this.outPath); |
| 134 | + const tracer = createTrace(this.outputPath); |
144 | 135 | tracer.profiler.startProfiling(); |
145 | 136 |
|
146 | 137 | // Compiler Hooks |
|
0 commit comments