-
Notifications
You must be signed in to change notification settings - Fork 8
/
plugin.js
73 lines (66 loc) · 2.75 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
if (process.env.QUALIA_PROFILE_FOLDER) {
var fs = Npm.require('fs'),
path = Npm.require('path'),
outputPath = path.resolve(process.env.QUALIA_PROFILE_FOLDER),
mainModule = global.process.mainModule,
absPath = mainModule.filename.split(path.sep).slice(0, -1).join(path.sep),
require = function(filePath) {
return mainModule.require(path.resolve(absPath, filePath));
},
AppRunner = require('./runners/run-app.js').AppRunner,
Bundler = require('./isobuild/bundler.js'),
v8Profiler = Npm.require('v8-profiler-next'),
Profiler = getProfiler(v8Profiler, fs)
;
if (!AppRunner._patched) {
AppRunner._patched = true;
var oldMakePromise = AppRunner.prototype._makePromise;
AppRunner.prototype._makePromise = function(name) {
if (name === 'run') {
Profiler.stopProfile('client-rebuild');
}
return oldMakePromise.apply(this, arguments);
};
var oldResolvePromise = AppRunner.prototype._resolvePromise;
AppRunner.prototype._resolvePromise = function(name, value) {
let outcome = value ? value.outcome : '';
if (name === 'run' && outcome === 'changed') {
Profiler.startProfile('full-rebuild', {
exportPath: path.join(outputPath, 'full-rebuild.cpuprofile'),
});
}
if (name === 'run' && outcome === 'changed-refreshable') {
Profiler.startProfile('client-rebuild', {
exportPath: path.join(outputPath, 'client-rebuild.cpuprofile'),
});
}
else if (name === 'start') {
Profiler.stopProfile('initial-build');
Profiler.stopProfile('full-rebuild');
}
return oldResolvePromise.apply(this, arguments);
};
Bundler._mainJsContents = [
"process.argv.splice(2, 0, 'program.json');",
"process.chdir(require('path').join(__dirname, 'programs', 'server'));",
"",
"var npmRequire = require('./programs/server/npm-require.js').require;",
"var profilerPath = '/node_modules/meteor/qualia:profile/node_modules/v8-profiler-next';",
"var v8Profiler = npmRequire(profilerPath);",
"var fs = require('fs');",
'var Profiler = eval(`(' + getProfiler.toString() + ')`)(v8Profiler, fs);',
"Profiler.startProfile('startup', { exportPath: '" + path.join(outputPath, 'startup.cpuprofile') + "' });",
"",
"require('./programs/server/boot.js');",
"",
"var intervalID = setInterval(() => {",
" if (__meteor_bootstrap__.startupHooks) return;",
" clearInterval(intervalID);",
" Profiler.stopProfile('startup');",
"}, 100);",
].join("\n");
Profiler.startProfile('initial-build', {
exportPath: path.join(outputPath, 'initial-build.cpuprofile'),
});
}
}