browser_perf-tree-view-10.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests if the profiler's tree view, when inverted, displays the self and
  6. * total costs correctly.
  7. */
  8. const { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");
  9. const { CallView } = require("devtools/client/performance/modules/widgets/tree-view");
  10. const RecordingUtils = require("devtools/shared/performance/recording-utils");
  11. add_task(function () {
  12. let threadNode = new ThreadNode(gProfile.threads[0], { startTime: 0, endTime: 50,
  13. invertTree: true });
  14. let treeRoot = new CallView({ frame: threadNode, inverted: true });
  15. let container = document.createElement("vbox");
  16. treeRoot.attachTo(container);
  17. // Add 1 to each index to skip the hidden root node
  18. let $$nam = i => container.querySelectorAll(
  19. ".call-tree-cell[type=function] > .call-tree-name")[i + 1];
  20. let $$per = i => container.querySelectorAll(
  21. ".call-tree-cell[type=percentage]")[i + 1];
  22. let $$selfper = i => container.querySelectorAll(
  23. ".call-tree-cell[type='self-percentage']")[i + 1];
  24. /**
  25. * Samples:
  26. *
  27. * A->C
  28. * A->B
  29. * A->B->C x4
  30. * A->B->D x4
  31. *
  32. * Expected:
  33. *
  34. * +--total--+--self--+--tree----+
  35. * | 50% | 50% | C |
  36. * | 40% | 0 | -> B |
  37. * | 30% | 0 | -> A |
  38. * | 10% | 0 | -> A |
  39. * | 40% | 40% | D |
  40. * | 40% | 0 | -> B |
  41. * | 40% | 0 | -> A |
  42. * | 10% | 10% | B |
  43. * | 10% | 0 | -> A |
  44. * +---------+--------+----------+
  45. */
  46. is(container.childNodes.length, 10,
  47. "The container node should have all children available.");
  48. // total, self, indent + name
  49. [
  50. [ 50, 50, "C"],
  51. [ 40, 0, " B"],
  52. [ 30, 0, " A"],
  53. [ 10, 0, " A"],
  54. [ 40, 40, "D"],
  55. [ 40, 0, " B"],
  56. [ 40, 0, " A"],
  57. [ 10, 10, "B"],
  58. [ 10, 0, " A"],
  59. ].forEach(function (def, i) {
  60. info(`Checking ${i}th tree item.`);
  61. let [total, self, name] = def;
  62. name = name.trim();
  63. is($$nam(i).textContent.trim(), name, `${name} has correct name.`);
  64. is($$per(i).textContent.trim(), `${total}%`, `${name} has correct total percent.`);
  65. is($$selfper(i).textContent.trim(), `${self}%`, `${name} has correct self percent.`);
  66. });
  67. });
  68. const gProfile = RecordingUtils.deflateProfile({
  69. meta: { version: 2 },
  70. threads: [{
  71. samples: [{
  72. time: 5,
  73. frames: [
  74. { location: "(root)" },
  75. { location: "A" },
  76. { location: "B" },
  77. { location: "C" }
  78. ]
  79. }, {
  80. time: 10,
  81. frames: [
  82. { location: "(root)" },
  83. { location: "A" },
  84. { location: "B" },
  85. { location: "D" }
  86. ]
  87. }, {
  88. time: 15,
  89. frames: [
  90. { location: "(root)" },
  91. { location: "A" },
  92. { location: "C" },
  93. ]
  94. }, {
  95. time: 20,
  96. frames: [
  97. { location: "(root)" },
  98. { location: "A" },
  99. { location: "B" },
  100. ]
  101. }, {
  102. time: 25,
  103. frames: [
  104. { location: "(root)" },
  105. { location: "A" },
  106. { location: "B" },
  107. { location: "C" }
  108. ]
  109. }, {
  110. time: 30,
  111. frames: [
  112. { location: "(root)" },
  113. { location: "A" },
  114. { location: "B" },
  115. { location: "C" }
  116. ]
  117. }, {
  118. time: 35,
  119. frames: [
  120. { location: "(root)" },
  121. { location: "A" },
  122. { location: "B" },
  123. { location: "D" }
  124. ]
  125. }, {
  126. time: 40,
  127. frames: [
  128. { location: "(root)" },
  129. { location: "A" },
  130. { location: "B" },
  131. { location: "D" }
  132. ]
  133. }, {
  134. time: 45,
  135. frames: [
  136. { location: "(root)" },
  137. { location: "B" },
  138. { location: "C" }
  139. ]
  140. }, {
  141. time: 50,
  142. frames: [
  143. { location: "(root)" },
  144. { location: "A" },
  145. { location: "B" },
  146. { location: "D" }
  147. ]
  148. }]
  149. }]
  150. });