diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/webpackbar/dist/profile.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/webpackbar/dist/profile.js')
| -rw-r--r-- | node_modules/webpackbar/dist/profile.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/node_modules/webpackbar/dist/profile.js b/node_modules/webpackbar/dist/profile.js new file mode 100644 index 00000000..15825568 --- /dev/null +++ b/node_modules/webpackbar/dist/profile.js @@ -0,0 +1,77 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _path = require('path'); + +var _path2 = _interopRequireDefault(_path); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +class Profile { + constructor(name) { + this.name = name; + this.requests = []; + } + + onRequest(request) { + // Measure time for last request + if (this.requests.length) { + const lastReq = this.requests[this.requests.length - 1]; + if (lastReq.start) { + lastReq.time = process.hrtime(lastReq.start); + delete lastReq.start; + } + } + + // Ignore requests without any file or loaders + if (!request.file || !request.loaders.length) { + return; + } + + this.requests.push({ + request, + start: process.hrtime() + }); + } + + getStats() { + const loaderStats = {}; + const extStats = {}; + + const getStat = (stats, name) => { + if (!stats[name]) { + // eslint-disable-next-line no-param-reassign + stats[name] = { + count: 0, + time: [0, 0] + }; + } + return stats[name]; + }; + + const addToStat = (stats, name, count, time) => { + const stat = getStat(stats, name); + stat.count += count; + stat.time[0] += time[0]; + stat.time[1] += time[1]; + }; + + this.requests.forEach(({ request, time = [0, 0] }) => { + request.loaders.forEach(loader => { + addToStat(loaderStats, loader, 1, time); + }); + + const ext = request.file && _path2.default.extname(request.file).substr(1); + addToStat(extStats, ext && ext.length ? ext : 'unknown', 1, time); + }); + + return { + ext: extStats, + loader: loaderStats + }; + } +} +exports.default = Profile;
\ No newline at end of file |
