ModuleProfile.js 2.4 KB

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