browser_perf-options-flatten-tree-recursion-02.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests that the memory flamegraphs get rerendered when toggling
  6. * `flatten-tree-recursion`.
  7. */
  8. const { SIMPLE_URL } = require("devtools/client/performance/test/helpers/urls");
  9. const { UI_FLATTEN_RECURSION_PREF, UI_ENABLE_ALLOCATIONS_PREF } = require("devtools/client/performance/test/helpers/prefs");
  10. const { initPerformanceInNewTab, teardownToolboxAndRemoveTab } = require("devtools/client/performance/test/helpers/panel-utils");
  11. const { startRecording, stopRecording } = require("devtools/client/performance/test/helpers/actions");
  12. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  13. add_task(function* () {
  14. let { panel } = yield initPerformanceInNewTab({
  15. url: SIMPLE_URL,
  16. win: window
  17. });
  18. let {
  19. EVENTS,
  20. PerformanceController,
  21. DetailsView,
  22. MemoryFlameGraphView,
  23. RecordingUtils,
  24. FlameGraphUtils
  25. } = panel.panelWin;
  26. // Enable memory to test
  27. Services.prefs.setBoolPref(UI_ENABLE_ALLOCATIONS_PREF, true);
  28. Services.prefs.setBoolPref(UI_FLATTEN_RECURSION_PREF, true);
  29. yield startRecording(panel);
  30. yield stopRecording(panel);
  31. let rendered = once(MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED);
  32. yield DetailsView.selectView("memory-flamegraph");
  33. yield rendered;
  34. let allocations1 = PerformanceController.getCurrentRecording().getAllocations();
  35. let thread1 = RecordingUtils.getProfileThreadFromAllocations(allocations1);
  36. let rendering1 = FlameGraphUtils._cache.get(thread1);
  37. ok(allocations1,
  38. "The allocations were retrieved from the controller.");
  39. ok(thread1,
  40. "The allocations profile was synthesized by the utility funcs.");
  41. ok(rendering1,
  42. "The rendering data was cached.");
  43. rendered = once(MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED);
  44. Services.prefs.setBoolPref(UI_FLATTEN_RECURSION_PREF, false);
  45. yield rendered;
  46. ok(true, "MemoryFlameGraphView rerendered when toggling flatten-tree-recursion.");
  47. let allocations2 = PerformanceController.getCurrentRecording().getAllocations();
  48. let thread2 = RecordingUtils.getProfileThreadFromAllocations(allocations2);
  49. let rendering2 = FlameGraphUtils._cache.get(thread2);
  50. is(allocations1, allocations2,
  51. "The same allocations data should be retrieved from the controller (1).");
  52. is(thread1, thread2,
  53. "The same allocations profile should be retrieved from the utility funcs. (1).");
  54. isnot(rendering1, rendering2,
  55. "The rendering data should be different because other options were used (1).");
  56. rendered = once(MemoryFlameGraphView, EVENTS.UI_MEMORY_FLAMEGRAPH_RENDERED);
  57. Services.prefs.setBoolPref(UI_FLATTEN_RECURSION_PREF, true);
  58. yield rendered;
  59. ok(true, "MemoryFlameGraphView rerendered when toggling back flatten-tree-recursion.");
  60. let allocations3 = PerformanceController.getCurrentRecording().getAllocations();
  61. let thread3 = RecordingUtils.getProfileThreadFromAllocations(allocations3);
  62. let rendering3 = FlameGraphUtils._cache.get(thread3);
  63. is(allocations2, allocations3,
  64. "The same allocations data should be retrieved from the controller (2).");
  65. is(thread2, thread3,
  66. "The same allocations profile should be retrieved from the utility funcs. (2).");
  67. isnot(rendering2, rendering3,
  68. "The rendering data should be different because other options were used (2).");
  69. yield teardownToolboxAndRemoveTab(panel);
  70. });