recording-common.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. /**
  6. * A mixin to be used for PerformanceRecordingActor, PerformanceRecordingFront,
  7. * and LegacyPerformanceRecording for helper methods to access data.
  8. */
  9. const PerformanceRecordingCommon = exports.PerformanceRecordingCommon = {
  10. // Private fields, only needed when a recording is started or stopped.
  11. _console: false,
  12. _imported: false,
  13. _recording: false,
  14. _completed: false,
  15. _configuration: {},
  16. _startingBufferStatus: null,
  17. _localStartTime: 0,
  18. // Serializable fields, necessary and sufficient for import and export.
  19. _label: "",
  20. _duration: 0,
  21. _markers: null,
  22. _frames: null,
  23. _memory: null,
  24. _ticks: null,
  25. _allocations: null,
  26. _profile: null,
  27. _systemHost: null,
  28. _systemClient: null,
  29. /**
  30. * Helper methods for returning the status of the recording.
  31. * These methods should be consistent on both the front and actor.
  32. */
  33. isRecording: function () { return this._recording; },
  34. isCompleted: function () { return this._completed || this.isImported(); },
  35. isFinalizing: function () { return !this.isRecording() && !this.isCompleted(); },
  36. isConsole: function () { return this._console; },
  37. isImported: function () { return this._imported; },
  38. /**
  39. * Helper methods for returning configuration for the recording.
  40. * These methods should be consistent on both the front and actor.
  41. */
  42. getConfiguration: function () { return this._configuration; },
  43. getLabel: function () { return this._label; },
  44. /**
  45. * Gets duration of this recording, in milliseconds.
  46. * @return number
  47. */
  48. getDuration: function () {
  49. // Compute an approximate ending time for the current recording if it is
  50. // still in progress. This is needed to ensure that the view updates even
  51. // when new data is not being generated. If recording is completed, use
  52. // the duration from the profiler; if between recording and being finalized,
  53. // use the last estimated duration.
  54. if (this.isRecording()) {
  55. return this._estimatedDuration = Date.now() - this._localStartTime;
  56. } else {
  57. return this._duration || this._estimatedDuration || 0;
  58. }
  59. },
  60. /**
  61. * Helper methods for returning recording data.
  62. * These methods should be consistent on both the front and actor.
  63. */
  64. getMarkers: function () { return this._markers; },
  65. getFrames: function () { return this._frames; },
  66. getMemory: function () { return this._memory; },
  67. getTicks: function () { return this._ticks; },
  68. getAllocations: function () { return this._allocations; },
  69. getProfile: function () { return this._profile; },
  70. getHostSystemInfo: function () { return this._systemHost; },
  71. getClientSystemInfo: function () { return this._systemClient; },
  72. getStartingBufferStatus: function () { return this._startingBufferStatus; },
  73. getAllData: function () {
  74. let label = this.getLabel();
  75. let duration = this.getDuration();
  76. let markers = this.getMarkers();
  77. let frames = this.getFrames();
  78. let memory = this.getMemory();
  79. let ticks = this.getTicks();
  80. let allocations = this.getAllocations();
  81. let profile = this.getProfile();
  82. let configuration = this.getConfiguration();
  83. let systemHost = this.getHostSystemInfo();
  84. let systemClient = this.getClientSystemInfo();
  85. return { label, duration, markers, frames, memory, ticks, allocations, profile, configuration, systemHost, systemClient };
  86. },
  87. };