test_HeapSnapshot_takeCensus_06.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. // Check HeapSnapshot.prototype.takeCensus handling of 'breakdown' argument.
  4. //
  5. // Ported from js/src/jit-test/tests/debug/Memory-takeCensus-06.js
  6. function run_test() {
  7. var Pattern = Match.Pattern;
  8. var g = newGlobal();
  9. var dbg = new Debugger(g);
  10. Pattern({ count: Pattern.NATURAL,
  11. bytes: Pattern.NATURAL })
  12. .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count" } }));
  13. let census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: false, bytes: false } });
  14. equal("count" in census, false);
  15. equal("bytes" in census, false);
  16. census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: true, bytes: false } });
  17. equal("count" in census, true);
  18. equal("bytes" in census, false);
  19. census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: false, bytes: true } });
  20. equal("count" in census, false);
  21. equal("bytes" in census, true);
  22. census = saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count", count: true, bytes: true } });
  23. equal("count" in census, true);
  24. equal("bytes" in census, true);
  25. // Pattern doesn't mind objects with extra properties, so we'll restrict this
  26. // list to the object classes we're pretty sure are going to stick around for
  27. // the forseeable future.
  28. Pattern({
  29. Function: { count: Pattern.NATURAL },
  30. Object: { count: Pattern.NATURAL },
  31. Debugger: { count: Pattern.NATURAL },
  32. Sandbox: { count: Pattern.NATURAL },
  33. // The below are all Debugger prototype objects.
  34. Source: { count: Pattern.NATURAL },
  35. Environment: { count: Pattern.NATURAL },
  36. Script: { count: Pattern.NATURAL },
  37. Memory: { count: Pattern.NATURAL },
  38. Frame: { count: Pattern.NATURAL }
  39. })
  40. .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "objectClass" } }));
  41. Pattern({
  42. objects: { count: Pattern.NATURAL },
  43. scripts: { count: Pattern.NATURAL },
  44. strings: { count: Pattern.NATURAL },
  45. other: { count: Pattern.NATURAL }
  46. })
  47. .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "coarseType" } }));
  48. // As for { by: 'objectClass' }, restrict our pattern to the types
  49. // we predict will stick around for a long time.
  50. Pattern({
  51. JSString: { count: Pattern.NATURAL },
  52. "js::Shape": { count: Pattern.NATURAL },
  53. JSObject: { count: Pattern.NATURAL },
  54. JSScript: { count: Pattern.NATURAL }
  55. })
  56. .assert(saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "internalType" } }));
  57. // Nested breakdowns.
  58. let coarseTypePattern = {
  59. objects: { count: Pattern.NATURAL },
  60. scripts: { count: Pattern.NATURAL },
  61. strings: { count: Pattern.NATURAL },
  62. other: { count: Pattern.NATURAL }
  63. };
  64. Pattern({
  65. JSString: coarseTypePattern,
  66. "js::Shape": coarseTypePattern,
  67. JSObject: coarseTypePattern,
  68. JSScript: coarseTypePattern,
  69. })
  70. .assert(saveHeapSnapshotAndTakeCensus(dbg, {
  71. breakdown: { by: "internalType",
  72. then: { by: "coarseType" }
  73. }
  74. }));
  75. Pattern({
  76. Function: { count: Pattern.NATURAL },
  77. Object: { count: Pattern.NATURAL },
  78. Debugger: { count: Pattern.NATURAL },
  79. Sandbox: { count: Pattern.NATURAL },
  80. other: coarseTypePattern
  81. })
  82. .assert(saveHeapSnapshotAndTakeCensus(dbg, {
  83. breakdown: {
  84. by: "objectClass",
  85. then: { by: "count" },
  86. other: { by: "coarseType" }
  87. }
  88. }));
  89. Pattern({
  90. objects: { count: Pattern.NATURAL, label: "object" },
  91. scripts: { count: Pattern.NATURAL, label: "scripts" },
  92. strings: { count: Pattern.NATURAL, label: "strings" },
  93. other: { count: Pattern.NATURAL, label: "other" }
  94. })
  95. .assert(saveHeapSnapshotAndTakeCensus(dbg, {
  96. breakdown: {
  97. by: "coarseType",
  98. objects: { by: "count", label: "object" },
  99. scripts: { by: "count", label: "scripts" },
  100. strings: { by: "count", label: "strings" },
  101. other: { by: "count", label: "other" }
  102. }
  103. }));
  104. do_test_finished();
  105. }