UNPKG

1.85 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8class ModuleProfile {
9 constructor() {
10 this.startTime = Date.now();
11 this.factory = 0;
12 this.restoring = 0;
13 this.integration = 0;
14 this.building = 0;
15 this.storing = 0;
16 this.additionalFactories = 0;
17 this.additionalIntegration = 0;
18 }
19
20 markFactoryStart() {
21 this.factoryStartTime = Date.now();
22 }
23
24 markFactoryEnd() {
25 this.factoryEndTime = Date.now();
26 this.factory = this.factoryEndTime - this.factoryStartTime;
27 }
28
29 markRestoringStart() {
30 this.restoringStartTime = Date.now();
31 }
32
33 markRestoringEnd() {
34 this.restoringEndTime = Date.now();
35 this.restoring = this.restoringEndTime - this.restoringStartTime;
36 }
37
38 markIntegrationStart() {
39 this.integrationStartTime = Date.now();
40 }
41
42 markIntegrationEnd() {
43 this.integrationEndTime = Date.now();
44 this.integration = this.integrationEndTime - this.integrationStartTime;
45 }
46
47 markBuildingStart() {
48 this.buildingStartTime = Date.now();
49 }
50
51 markBuildingEnd() {
52 this.buildingEndTime = Date.now();
53 this.building = this.buildingEndTime - this.buildingStartTime;
54 }
55
56 markStoringStart() {
57 this.storingStartTime = Date.now();
58 }
59
60 markStoringEnd() {
61 this.storingEndTime = Date.now();
62 this.storing = this.storingEndTime - this.storingStartTime;
63 }
64
65 // This depends on timing so we ignore it for coverage
66 /* istanbul ignore next */
67 /**
68 * Merge this profile into another one
69 * @param {ModuleProfile} realProfile the profile to merge into
70 * @returns {void}
71 */
72 mergeInto(realProfile) {
73 if (this.factory > realProfile.additionalFactories)
74 realProfile.additionalFactories = this.factory;
75 if (this.integration > realProfile.additionalIntegration)
76 realProfile.additionalIntegration = this.integration;
77 }
78}
79
80module.exports = ModuleProfile;