Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
vm: implement vm.measureMemory() for per-context memory measurement#31824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
joyeecheung commented Feb 17, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
ba8d46b to bc6f5feCompareThis 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.
bc6f5fe to 6c04e3cComparedevsnek commented Feb 17, 2020
Is there a reason we don't want to expose this on |
joyeecheung commented Feb 17, 2020
@devsnek This is currently different from the API proposed in https://github.com/ulan/performance-measure-memory in that an |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
devsnek commented Feb 18, 2020
@joyeecheung did you have any interest in the Context.current() approach I mentioned in irc? |
joyeecheung commented Feb 18, 2020
@devsnek That sounds interesting but seems orthogonal to what this PR does? |
devsnek commented Feb 18, 2020
@joyeecheung well if we wanted to use that approach instead i assume we wouldn't also have the static method this pr adds, which is why i ask |
joyeecheung commented Feb 18, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@devsnek A measureMemory method could be added to the prototype of the Context class but that when the API does land, yes, but I think it's better to decouple the functionality of measuring the per-context memory from an API that has not landed yet, and this provides the functionality for contextified objects which is something that does exist in the wild (it could also take the new class when the time comes, and avoids the overhead of creating an extra wrapper for the invoking context). |
joyeecheung commented Feb 18, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@bnoordhuis@addaleax@jasnell@lundibundi Thanks for the reviews. I've updated the PR, PTAL.
|
Uh oh!
There was an error while loading. Please reload this page.
…ement Co-Authored-By: Colin Ihrig <[email protected]>
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. PR-URL: #31824 Refs: https://github.com/ulan/performance-measure-memory Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
joyeecheung commented Feb 26, 2020
Landed in fb73045, thanks! |
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. PR-URL: #31824 Refs: https://github.com/ulan/performance-measure-memory Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Uh oh!
There was an error while loading. Please reload this page.
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
SimonSchick commented Mar 26, 2020
It seems the example code is wrong, the docs suggest the function should be called like this |
gengjiawen commented Mar 26, 2020
Do you mind send a PR for this ? |
SimonSchick commented Mar 26, 2020
I'm currently busy updating the node type definitions to v11 (hence this comment). |
limerickgds commented Apr 13, 2020
@joyeecheung i did a test, The data is not as expected,: |
joyeecheung commented Apr 22, 2020
@limerickgds This no longer works after the recent V8 update - the promises returned by 'use strict';constvm=require('vm');require('util').inspect.defaultOptions.depth=100;functiongetMeasureMemory(){returnvm.measureMemory({mode: 'detailed',execution: 'eager'});}letglobalStore=[];constoperateStore={add: ()=>{leti=1000;while(i--){globalStore.push('test'.repeat(10000));}},remove: ()=>{globalStore=[];},};constscript=` var store = []; fn ={ add: () =>{ let i = 1000; while(i--){store.push('test'.repeat(10000)) } }, remove: () =>{ store = []; } }`;constcontext=vm.createContext({fn: ()=>{}, console,});vm.runInContext(script,context);asyncfunctionmeasureMemoryTest(){letresult={};result=awaitgetMeasureMemory();console.log('start: \n',result);context.fn.add();result=awaitgetMeasureMemory();console.log('after add once: \n',result);context.fn.remove();result=awaitgetMeasureMemory();console.log('after remove all: \n',result);operateStore.add();result=awaitgetMeasureMemory();console.log('after add global context: \n',result);}measureMemoryTest();This seems to be about right (according to the ranges, instead of the estimates which are pretty rough since it's measured after marking, and before sweeping) |

This patch implements
vm.measureMemory()with the newv8::Isolate::MeasureMemory()API to measure per-context memoryusage. This should be experimental, since detailed memory
measurement requires further integration with the V8 API
that should be available in a future V8 update.
Refs: https://github.com/ulan/performance-measure-memory
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes