browser_perf-tree-view-11.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /* eslint-disable */
  5. /**
  6. * Tests that if `show-jit-optimizations` is true, then an
  7. * icon is next to the frame with optimizations
  8. */
  9. var { CATEGORY_MASK } = require("devtools/client/performance/modules/categories");
  10. function* spawnTest() {
  11. let { panel } = yield initPerformance(SIMPLE_URL);
  12. let { EVENTS, $, $$, window, PerformanceController } = panel.panelWin;
  13. let { OverviewView, DetailsView, JsCallTreeView } = panel.panelWin;
  14. let profilerData = { threads: [gThread] };
  15. Services.prefs.setBoolPref(JIT_PREF, true);
  16. Services.prefs.setBoolPref(PLATFORM_DATA_PREF, false);
  17. Services.prefs.setBoolPref(INVERT_PREF, false);
  18. // Make two recordings, so we have one to switch to later, as the
  19. // second one will have fake sample data
  20. yield startRecording(panel);
  21. yield stopRecording(panel);
  22. yield DetailsView.selectView("js-calltree");
  23. yield injectAndRenderProfilerData();
  24. let rows = $$("#js-calltree-view .call-tree-item");
  25. is(rows.length, 4, "4 call tree rows exist");
  26. for (let row of rows) {
  27. let name = $(".call-tree-name", row).textContent.trim();
  28. switch (name) {
  29. case "A":
  30. ok($(".opt-icon", row), "found an opt icon on a leaf node with opt data");
  31. break;
  32. case "C":
  33. ok(!$(".opt-icon", row), "frames without opt data do not have an icon");
  34. break;
  35. case "Gecko":
  36. ok(!$(".opt-icon", row), "meta category frames with opt data do not have an icon");
  37. break;
  38. case "(root)":
  39. ok(!$(".opt-icon", row), "root frame certainly does not have opt data");
  40. break;
  41. default:
  42. ok(false, `Unidentified frame: ${name}`);
  43. break;
  44. }
  45. }
  46. yield teardown(panel);
  47. finish();
  48. function* injectAndRenderProfilerData() {
  49. // Get current recording and inject our mock data
  50. info("Injecting mock profile data");
  51. let recording = PerformanceController.getCurrentRecording();
  52. recording._profile = profilerData;
  53. // Force a rerender
  54. let rendered = once(JsCallTreeView, EVENTS.UI_JS_CALL_TREE_RENDERED);
  55. JsCallTreeView.render(OverviewView.getTimeInterval());
  56. yield rendered;
  57. }
  58. }
  59. var gUniqueStacks = new RecordingUtils.UniqueStacks();
  60. function uniqStr(s) {
  61. return gUniqueStacks.getOrAddStringIndex(s);
  62. }
  63. // Since deflateThread doesn't handle deflating optimization info, use
  64. // placeholder names A_O1, B_O2, and B_O3, which will be used to manually
  65. // splice deduped opts into the profile.
  66. var gThread = RecordingUtils.deflateThread({
  67. samples: [{
  68. time: 0,
  69. frames: [
  70. { location: "(root)" }
  71. ]
  72. }, {
  73. time: 5,
  74. frames: [
  75. { location: "(root)" },
  76. { location: "A (http://foo:1)" },
  77. ]
  78. }, {
  79. time: 5 + 1,
  80. frames: [
  81. { location: "(root)" },
  82. { location: "C (http://foo/bar/baz:56)" }
  83. ]
  84. }, {
  85. time: 5 + 1 + 2,
  86. frames: [
  87. { location: "(root)" },
  88. { category: CATEGORY_MASK("other"), location: "PlatformCode" }
  89. ]
  90. }],
  91. markers: []
  92. }, gUniqueStacks);
  93. // 3 RawOptimizationSites
  94. var gRawSite1 = {
  95. _testFrameInfo: { name: "A", line: "12", file: "@baz" },
  96. line: 12,
  97. column: 2,
  98. types: [{
  99. mirType: uniqStr("Object"),
  100. site: uniqStr("A (http://foo/bar/bar:12)"),
  101. typeset: [{
  102. keyedBy: uniqStr("constructor"),
  103. name: uniqStr("Foo"),
  104. location: uniqStr("A (http://foo/bar/baz:12)")
  105. }, {
  106. keyedBy: uniqStr("primitive"),
  107. location: uniqStr("self-hosted")
  108. }]
  109. }],
  110. attempts: {
  111. schema: {
  112. outcome: 0,
  113. strategy: 1
  114. },
  115. data: [
  116. [uniqStr("Failure1"), uniqStr("SomeGetter1")],
  117. [uniqStr("Failure2"), uniqStr("SomeGetter2")],
  118. [uniqStr("Failure3"), uniqStr("SomeGetter3")]
  119. ]
  120. }
  121. };
  122. gThread.frameTable.data.forEach((frame) => {
  123. const LOCATION_SLOT = gThread.frameTable.schema.location;
  124. const OPTIMIZATIONS_SLOT = gThread.frameTable.schema.optimizations;
  125. let l = gThread.stringTable[frame[LOCATION_SLOT]];
  126. switch (l) {
  127. case "A (http://foo:1)":
  128. frame[LOCATION_SLOT] = uniqStr("A (http://foo:1)");
  129. frame[OPTIMIZATIONS_SLOT] = gRawSite1;
  130. break;
  131. case "PlatformCode":
  132. frame[LOCATION_SLOT] = uniqStr("PlatformCode");
  133. frame[OPTIMIZATIONS_SLOT] = gRawSite1;
  134. break;
  135. }
  136. });
  137. /* eslint-enable */