test_HeapAnalyses_takeCensusDiff_01.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. // Test that the HeapAnalyses{Client,Worker} can take diffs between censuses.
  4. function run_test() {
  5. run_next_test();
  6. }
  7. const BREAKDOWN = {
  8. by: "objectClass",
  9. then: { by: "count", count: true, bytes: false },
  10. other: { by: "count", count: true, bytes: false },
  11. };
  12. add_task(function* () {
  13. const client = new HeapAnalysesClient();
  14. const markers = [allocationMarker()];
  15. const firstSnapshotFilePath = saveNewHeapSnapshot();
  16. // Allocate and hold an additional AllocationMarker object so we can see it in
  17. // the next heap snapshot.
  18. markers.push(allocationMarker());
  19. const secondSnapshotFilePath = saveNewHeapSnapshot();
  20. yield client.readHeapSnapshot(firstSnapshotFilePath);
  21. yield client.readHeapSnapshot(secondSnapshotFilePath);
  22. ok(true, "Should have read both heap snapshot files");
  23. const { delta } = yield client.takeCensusDiff(firstSnapshotFilePath,
  24. secondSnapshotFilePath,
  25. { breakdown: BREAKDOWN });
  26. equal(delta.AllocationMarker.count, 1,
  27. "There exists one new AllocationMarker in the second heap snapshot");
  28. const { delta: deltaTreeNode } = yield client.takeCensusDiff(firstSnapshotFilePath,
  29. secondSnapshotFilePath,
  30. { breakdown: BREAKDOWN },
  31. { asTreeNode: true });
  32. // Have to manually set these because symbol properties aren't structured
  33. // cloned.
  34. delta[CensusUtils.basisTotalBytes] = deltaTreeNode.totalBytes;
  35. delta[CensusUtils.basisTotalCount] = deltaTreeNode.totalCount;
  36. compareCensusViewData(BREAKDOWN, delta, deltaTreeNode,
  37. "Returning delta-census as a tree node represents same data as the report");
  38. client.destroy();
  39. });