timeline.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. const {
  6. Arg,
  7. RetVal,
  8. Option,
  9. generateActorSpec,
  10. types
  11. } = require("devtools/shared/protocol");
  12. /**
  13. * Type representing an array of numbers as strings, serialized fast(er).
  14. * http://jsperf.com/json-stringify-parse-vs-array-join-split/3
  15. *
  16. * XXX: It would be nice if on local connections (only), we could just *give*
  17. * the array directly to the front, instead of going through all this
  18. * serialization redundancy.
  19. */
  20. types.addType("array-of-numbers-as-strings", {
  21. write: (v) => v.join(","),
  22. // In Gecko <= 37, `v` is an array; do not transform in this case.
  23. read: (v) => typeof v === "string" ? v.split(",") : v
  24. });
  25. const timelineSpec = generateActorSpec({
  26. typeName: "timeline",
  27. events: {
  28. /**
  29. * Events emitted when "DOMContentLoaded" and "Load" markers are received.
  30. */
  31. "doc-loading": {
  32. type: "doc-loading",
  33. marker: Arg(0, "json"),
  34. endTime: Arg(0, "number")
  35. },
  36. /**
  37. * The "markers" events emitted every DEFAULT_TIMELINE_DATA_PULL_TIMEOUT ms
  38. * at most, when profile markers are found. The timestamps on each marker
  39. * are relative to when recording was started.
  40. */
  41. "markers": {
  42. type: "markers",
  43. markers: Arg(0, "json"),
  44. endTime: Arg(1, "number")
  45. },
  46. /**
  47. * The "memory" events emitted in tandem with "markers", if this was enabled
  48. * when the recording started. The `delta` timestamp on this measurement is
  49. * relative to when recording was started.
  50. */
  51. "memory": {
  52. type: "memory",
  53. delta: Arg(0, "number"),
  54. measurement: Arg(1, "json")
  55. },
  56. /**
  57. * The "ticks" events (from the refresh driver) emitted in tandem with
  58. * "markers", if this was enabled when the recording started. All ticks
  59. * are timestamps with a zero epoch.
  60. */
  61. "ticks": {
  62. type: "ticks",
  63. delta: Arg(0, "number"),
  64. timestamps: Arg(1, "array-of-numbers-as-strings")
  65. },
  66. /**
  67. * The "frames" events emitted in tandem with "markers", containing
  68. * JS stack frames. The `delta` timestamp on this frames packet is
  69. * relative to when recording was started.
  70. */
  71. "frames": {
  72. type: "frames",
  73. delta: Arg(0, "number"),
  74. frames: Arg(1, "json")
  75. }
  76. },
  77. methods: {
  78. isRecording: {
  79. request: {},
  80. response: {
  81. value: RetVal("boolean")
  82. }
  83. },
  84. start: {
  85. request: {
  86. withMarkers: Option(0, "boolean"),
  87. withTicks: Option(0, "boolean"),
  88. withMemory: Option(0, "boolean"),
  89. withFrames: Option(0, "boolean"),
  90. withGCEvents: Option(0, "boolean"),
  91. withDocLoadingEvents: Option(0, "boolean")
  92. },
  93. response: {
  94. value: RetVal("number")
  95. }
  96. },
  97. stop: {
  98. response: {
  99. // Set as possibly nullable due to the end time possibly being
  100. // undefined during destruction
  101. value: RetVal("nullable:number")
  102. }
  103. },
  104. },
  105. });
  106. exports.timelineSpec = timelineSpec;