-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Deno.core.heapStats() (#9659)
This commit implements "Deno.core.heapStats()" function that allows to programatically measure isolate heap-usage.
- Loading branch information
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. | ||
"use strict"; | ||
|
||
function allocTest(alloc, allocAssert, deallocAssert) { | ||
// Helper func that GCs then returns heapStats | ||
const sample = () => { | ||
// deno-lint-ignore no-undef | ||
gc(); | ||
return Deno.core.heapStats(); | ||
}; | ||
const delta = (t1, t2) => t2.usedHeapSize - t1.usedHeapSize; | ||
|
||
// Sample "clean" heapStats | ||
const t1 = sample(); | ||
|
||
// Alloc | ||
let x = alloc(); | ||
const t2 = sample(); | ||
allocAssert(delta(t1, t2)); | ||
|
||
// Free | ||
x = null; | ||
const t3 = sample(); | ||
deallocAssert(delta(t2, t3)); | ||
} | ||
|
||
function main() { | ||
// Large-array test, 1M slot array consumes ~4MB (4B per slot) | ||
allocTest( | ||
() => new Array(1e6), | ||
(delta) => console.log("Allocated:", Math.round(delta / 1e6) + "MB"), | ||
(delta) => console.log("Freed:", Math.round(delta / 1e6) + "MB"), | ||
); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Allocated: 4MB | ||
Freed: -4MB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters