aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpackbar/dist/profile.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webpackbar/dist/profile.js')
-rw-r--r--node_modules/webpackbar/dist/profile.js77
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