profiler.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
  6. const { Profiler } = require("devtools/server/performance/profiler");
  7. const { actorBridgeWithSpec } = require("devtools/server/actors/common");
  8. const { profilerSpec } = require("devtools/shared/specs/profiler");
  9. loader.lazyRequireGetter(this, "events", "sdk/event/core");
  10. /**
  11. * This actor wraps the Profiler module at devtools/server/performance/profiler.js
  12. * and provides RDP definitions.
  13. *
  14. * @see devtools/server/performance/profiler.js for documentation.
  15. */
  16. var ProfilerActor = exports.ProfilerActor = ActorClassWithSpec(profilerSpec, {
  17. initialize: function (conn) {
  18. Actor.prototype.initialize.call(this, conn);
  19. this._onProfilerEvent = this._onProfilerEvent.bind(this);
  20. this.bridge = new Profiler();
  21. events.on(this.bridge, "*", this._onProfilerEvent);
  22. },
  23. /**
  24. * `disconnect` method required to call destroy, since this
  25. * actor is not managed by a parent actor.
  26. */
  27. disconnect: function () {
  28. this.destroy();
  29. },
  30. destroy: function () {
  31. events.off(this.bridge, "*", this._onProfilerEvent);
  32. this.bridge.destroy();
  33. Actor.prototype.destroy.call(this);
  34. },
  35. startProfiler: actorBridgeWithSpec("start"),
  36. stopProfiler: actorBridgeWithSpec("stop"),
  37. getProfile: actorBridgeWithSpec("getProfile"),
  38. getFeatures: actorBridgeWithSpec("getFeatures"),
  39. getBufferInfo: actorBridgeWithSpec("getBufferInfo"),
  40. getStartOptions: actorBridgeWithSpec("getStartOptions"),
  41. isActive: actorBridgeWithSpec("isActive"),
  42. getSharedLibraryInformation: actorBridgeWithSpec("getSharedLibraryInformation"),
  43. registerEventNotifications: actorBridgeWithSpec("registerEventNotifications"),
  44. unregisterEventNotifications: actorBridgeWithSpec("unregisterEventNotifications"),
  45. setProfilerStatusInterval: actorBridgeWithSpec("setProfilerStatusInterval"),
  46. /**
  47. * Pipe events from Profiler module to this actor.
  48. */
  49. _onProfilerEvent: function (eventName, ...data) {
  50. events.emit(this, eventName, ...data);
  51. },
  52. });