profiler.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. Option,
  8. RetVal,
  9. generateActorSpec,
  10. types
  11. } = require("devtools/shared/protocol");
  12. types.addType("profiler-data", {
  13. // On Fx42+, the profile is only deserialized on the front; older
  14. // servers will get the profiler data as an object from nsIProfiler,
  15. // causing one parse/stringify cycle, then again implicitly in a packet.
  16. read: (v) => {
  17. if (typeof v.profile === "string") {
  18. // Create a new response object since `profile` is read only.
  19. let newValue = Object.create(null);
  20. newValue.profile = JSON.parse(v.profile);
  21. newValue.currentTime = v.currentTime;
  22. return newValue;
  23. }
  24. return v;
  25. }
  26. });
  27. const profilerSpec = generateActorSpec({
  28. typeName: "profiler",
  29. /**
  30. * The set of events the ProfilerActor emits over RDP.
  31. */
  32. events: {
  33. "console-api-profiler": {
  34. data: Arg(0, "json"),
  35. },
  36. "profiler-started": {
  37. data: Arg(0, "json"),
  38. },
  39. "profiler-stopped": {
  40. data: Arg(0, "json"),
  41. },
  42. "profiler-status": {
  43. data: Arg(0, "json"),
  44. },
  45. // Only for older geckos, pre-protocol.js ProfilerActor (<Fx42).
  46. // Emitted on other events as a transition from older profiler events
  47. // to newer ones.
  48. "eventNotification": {
  49. subject: Option(0, "json"),
  50. topic: Option(0, "string"),
  51. details: Option(0, "json")
  52. }
  53. },
  54. methods: {
  55. startProfiler: {
  56. // Write out every property in the request, since we want all these options to be
  57. // on the packet's top-level for backwards compatibility, when the profiler actor
  58. // was not using protocol.js (<Fx42)
  59. request: {
  60. entries: Option(0, "nullable:number"),
  61. interval: Option(0, "nullable:number"),
  62. features: Option(0, "nullable:array:string"),
  63. threadFilters: Option(0, "nullable:array:string"),
  64. },
  65. response: RetVal("json"),
  66. },
  67. stopProfiler: {
  68. response: RetVal("json"),
  69. },
  70. getProfile: {
  71. request: {
  72. startTime: Option(0, "nullable:number"),
  73. stringify: Option(0, "nullable:boolean")
  74. },
  75. response: RetVal("profiler-data")
  76. },
  77. getFeatures: {
  78. response: RetVal("json")
  79. },
  80. getBufferInfo: {
  81. response: RetVal("json")
  82. },
  83. getStartOptions: {
  84. response: RetVal("json")
  85. },
  86. isActive: {
  87. response: RetVal("json")
  88. },
  89. getSharedLibraryInformation: {
  90. response: RetVal("json")
  91. },
  92. registerEventNotifications: {
  93. // Explicitly enumerate the arguments
  94. // @see ProfilerActor#startProfiler
  95. request: {
  96. events: Option(0, "nullable:array:string"),
  97. },
  98. response: RetVal("json")
  99. },
  100. unregisterEventNotifications: {
  101. // Explicitly enumerate the arguments
  102. // @see ProfilerActor#startProfiler
  103. request: {
  104. events: Option(0, "nullable:array:string"),
  105. },
  106. response: RetVal("json")
  107. },
  108. setProfilerStatusInterval: {
  109. request: { interval: Arg(0, "number") },
  110. oneway: true
  111. }
  112. }
  113. });
  114. exports.profilerSpec = profilerSpec;