test_perf-utils-allocations-to-samples.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests if allocations data received from the performance actor is properly
  5. * converted to something that follows the same structure as the samples data
  6. * received from the profiler.
  7. */
  8. function run_test() {
  9. run_next_test();
  10. }
  11. add_task(function () {
  12. const { getProfileThreadFromAllocations } = require("devtools/shared/performance/recording-utils");
  13. let output = getProfileThreadFromAllocations(TEST_DATA);
  14. equal(output.toSource(), EXPECTED_OUTPUT.toSource(), "The output is correct.");
  15. });
  16. var TEST_DATA = {
  17. sites: [0, 0, 1, 2, 3],
  18. timestamps: [50, 100, 150, 200, 250],
  19. sizes: [0, 0, 100, 200, 300],
  20. frames: [
  21. null, {
  22. source: "A",
  23. line: 1,
  24. column: 2,
  25. functionDisplayName: "x",
  26. parent: 0
  27. }, {
  28. source: "B",
  29. line: 3,
  30. column: 4,
  31. functionDisplayName: "y",
  32. parent: 1
  33. }, {
  34. source: "C",
  35. line: 5,
  36. column: 6,
  37. functionDisplayName: null,
  38. parent: 2
  39. }
  40. ]
  41. };
  42. var EXPECTED_OUTPUT = {
  43. name: "allocations",
  44. samples: {
  45. "schema": {
  46. "stack": 0,
  47. "time": 1,
  48. "size": 2,
  49. },
  50. data: [
  51. [ 1, 150, 100 ],
  52. [ 2, 200, 200 ],
  53. [ 3, 250, 300 ]
  54. ]
  55. },
  56. stackTable: {
  57. "schema": {
  58. "prefix": 0,
  59. "frame": 1
  60. },
  61. "data": [
  62. null,
  63. [ null, 1 ], // x (A:1:2)
  64. [ 1, 2 ], // x (A:1:2) > y (B:3:4)
  65. [ 2, 3 ] // x (A:1:2) > y (B:3:4) > C:5:6
  66. ]
  67. },
  68. frameTable: {
  69. "schema": {
  70. "location": 0,
  71. "implementation": 1,
  72. "optimizations": 2,
  73. "line": 3,
  74. "category": 4
  75. },
  76. data: [
  77. null,
  78. [ 0 ],
  79. [ 1 ],
  80. [ 2 ]
  81. ]
  82. },
  83. "stringTable": [
  84. "x (A:1:2)",
  85. "y (B:3:4)",
  86. "C:5:6"
  87. ],
  88. };