-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: implement vm.measureMemory() for per-context memory measurement
This patch implements `vm.measureMemory()` with the new `v8::Isolate::MeasureMemory()` API to measure per-context memory usage. This should be experimental, since detailed memory measurement requires further integration with the V8 API that should be available in a future V8 update.
- Loading branch information
1 parent
4c746a6
commit 6c04e3c
Showing
5 changed files
with
215 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const vm = require('vm'); | ||
const { | ||
SUMMARY, | ||
DETAILED | ||
} = vm.constants.measureMemory.mode; | ||
|
||
common.expectWarning('ExperimentalWarning', | ||
'vm.measureMemory is an experimental feature. ' + | ||
'This feature could change at any time'); | ||
|
||
// Test measuring memory of the current context | ||
{ | ||
vm.measureMemory(undefined) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
vm.measureMemory({}) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
vm.measureMemory({ mode: SUMMARY }) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
vm.measureMemory({ mode: DETAILED }) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
assert.throws(() => vm.measureMemory(null), { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
assert.throws(() => vm.measureMemory('summary'), { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
assert.throws(() => vm.measureMemory({ mode: -1 }), { | ||
code: 'ERR_OUT_OF_RANGE' | ||
}); | ||
} | ||
|
||
// Test measuring memory of the sandbox | ||
{ | ||
const sandbox = vm.createContext(); | ||
vm.measureMemory(undefined, sandbox) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
vm.measureMemory({}, sandbox) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
vm.measureMemory({ mode: SUMMARY }, sandbox) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
vm.measureMemory({ mode: DETAILED }, sandbox) | ||
.then((result) => { | ||
assert(result instanceof Object); | ||
}); | ||
|
||
assert.throws(() => vm.measureMemory({ mode: SUMMARY }, null), { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
} |
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