| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9966449 commit bd6af78
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -302,82 +302,6 @@ console.log(globalVar); | |||
| 302 | 302 | // 1000 | |
| 303 | 303 | ``` | |
| 304 | 304 | ||
| 305 | - ## `vm.measureMemory([options])` | ||
| 306 | - | ||
| 307 | - <!-- YAML | ||
| 308 | - added: v13.10.0 | ||
| 309 | - --> | ||
| 310 | - | ||
| 311 | - > Stability: 1 - Experimental | ||
| 312 | - | ||
| 313 | - Measure the memory known to V8 and used by all contexts known to the | ||
| 314 | - current V8 isolate, or the main context. | ||
| 315 | - | ||
| 316 | - * `options` {Object} Optional. | ||
| 317 | - * `mode` {string} Either `'summary'` or `'detailed'`. In summary mode, | ||
| 318 | - only the memory measured for the main context will be returned. In | ||
| 319 | - detailed mode, the measure measured for all contexts known to the | ||
| 320 | - current V8 isolate will be returned. | ||
| 321 | - **Default:** `'summary'` | ||
| 322 | - * `execution` {string} Either `'default'` or `'eager'`. With default | ||
| 323 | - execution, the promise will not resolve until after the next scheduled | ||
| 324 | - garbage collection starts, which may take a while (or never if the program | ||
| 325 | - exits before the next GC). With eager execution, the GC will be started | ||
| 326 | - right away to measure the memory. | ||
| 327 | - **Default:** `'default'` | ||
| 328 | - * Returns: {Promise} If the memory is successfully measured the promise will | ||
| 329 | - resolve with an object containing information about the memory usage. | ||
| 330 | - | ||
| 331 | - The format of the object that the returned Promise may resolve with is | ||
| 332 | - specific to the V8 engine and may change from one version of V8 to the next. | ||
| 333 | - | ||
| 334 | - The returned result is different from the statistics returned by | ||
| 335 | - `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the | ||
| 336 | - memory reachable by each V8 specific contexts in the current instance of | ||
| 337 | - the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure | ||
| 338 | - the memory occupied by each heap space in the current V8 instance. | ||
| 339 | - | ||
| 340 | - ```js | ||
| 341 | - const vm = require('vm'); | ||
| 342 | - // Measure the memory used by the main context. | ||
| 343 | - vm.measureMemory({ mode: 'summary' }) | ||
| 344 | - // This is the same as vm.measureMemory() | ||
| 345 | - .then((result) => { | ||
| 346 | - // The current format is: | ||
| 347 | - // { | ||
| 348 | - // total: { | ||
| 349 | - // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ] | ||
| 350 | - // } | ||
| 351 | - // } | ||
| 352 | - console.log(result); | ||
| 353 | - }); | ||
| 354 | - | ||
| 355 | - const context = vm.createContext({ a: 1 }); | ||
| 356 | - vm.measureMemory({ mode: 'detailed', execution: 'eager' }) | ||
| 357 | - .then((result) => { | ||
| 358 | - // Reference the context here so that it won't be GC'ed | ||
| 359 | - // until the measurement is complete. | ||
| 360 | - console.log(context.a); | ||
| 361 | - // { | ||
| 362 | - // total: { | ||
| 363 | - // jsMemoryEstimate: 2574732, | ||
| 364 | - // jsMemoryRange: [ 2574732, 2904372 ] | ||
| 365 | - // }, | ||
| 366 | - // current: { | ||
| 367 | - // jsMemoryEstimate: 2438996, | ||
| 368 | - // jsMemoryRange: [ 2438996, 2768636 ] | ||
| 369 | - // }, | ||
| 370 | - // other: [ | ||
| 371 | - // { | ||
| 372 | - // jsMemoryEstimate: 135736, | ||
| 373 | - // jsMemoryRange: [ 135736, 465376 ] | ||
| 374 | - // } | ||
| 375 | - // ] | ||
| 376 | - // } | ||
| 377 | - console.log(result); | ||
| 378 | - }); | ||
| 379 | - ``` | ||
| 380 | - | ||
| 381 | 305 | ## Class: `vm.Module` | |
| 382 | 306 | <!-- YAML | |
| 383 | 307 | added: | |
@@ -1039,6 +963,82 @@ added: v0.11.7 | |||
| 1039 | 963 | Returns `true` if the given `object` object has been [contextified][] using | |
| 1040 | 964 | [`vm.createContext()`][]. | |
| 1041 | 965 | ||
| 966 | + ## `vm.measureMemory([options])` | ||
| 967 | + | ||
| 968 | + <!-- YAML | ||
| 969 | + added: v13.10.0 | ||
| 970 | + --> | ||
| 971 | + | ||
| 972 | + > Stability: 1 - Experimental | ||
| 973 | + | ||
| 974 | + Measure the memory known to V8 and used by all contexts known to the | ||
| 975 | + current V8 isolate, or the main context. | ||
| 976 | + | ||
| 977 | + * `options` {Object} Optional. | ||
| 978 | + * `mode` {string} Either `'summary'` or `'detailed'`. In summary mode, | ||
| 979 | + only the memory measured for the main context will be returned. In | ||
| 980 | + detailed mode, the measure measured for all contexts known to the | ||
| 981 | + current V8 isolate will be returned. | ||
| 982 | + **Default:** `'summary'` | ||
| 983 | + * `execution` {string} Either `'default'` or `'eager'`. With default | ||
| 984 | + execution, the promise will not resolve until after the next scheduled | ||
| 985 | + garbage collection starts, which may take a while (or never if the program | ||
| 986 | + exits before the next GC). With eager execution, the GC will be started | ||
| 987 | + right away to measure the memory. | ||
| 988 | + **Default:** `'default'` | ||
| 989 | + * Returns: {Promise} If the memory is successfully measured the promise will | ||
| 990 | + resolve with an object containing information about the memory usage. | ||
| 991 | + | ||
| 992 | + The format of the object that the returned Promise may resolve with is | ||
| 993 | + specific to the V8 engine and may change from one version of V8 to the next. | ||
| 994 | + | ||
| 995 | + The returned result is different from the statistics returned by | ||
| 996 | + `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the | ||
| 997 | + memory reachable by each V8 specific contexts in the current instance of | ||
| 998 | + the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure | ||
| 999 | + the memory occupied by each heap space in the current V8 instance. | ||
| 1000 | + | ||
| 1001 | + ```js | ||
| 1002 | + const vm = require('vm'); | ||
| 1003 | + // Measure the memory used by the main context. | ||
| 1004 | + vm.measureMemory({ mode: 'summary' }) | ||
| 1005 | + // This is the same as vm.measureMemory() | ||
| 1006 | + .then((result) => { | ||
| 1007 | + // The current format is: | ||
| 1008 | + // { | ||
| 1009 | + // total: { | ||
| 1010 | + // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ] | ||
| 1011 | + // } | ||
| 1012 | + // } | ||
| 1013 | + console.log(result); | ||
| 1014 | + }); | ||
| 1015 | + | ||
| 1016 | + const context = vm.createContext({ a: 1 }); | ||
| 1017 | + vm.measureMemory({ mode: 'detailed', execution: 'eager' }) | ||
| 1018 | + .then((result) => { | ||
| 1019 | + // Reference the context here so that it won't be GC'ed | ||
| 1020 | + // until the measurement is complete. | ||
| 1021 | + console.log(context.a); | ||
| 1022 | + // { | ||
| 1023 | + // total: { | ||
| 1024 | + // jsMemoryEstimate: 2574732, | ||
| 1025 | + // jsMemoryRange: [ 2574732, 2904372 ] | ||
| 1026 | + // }, | ||
| 1027 | + // current: { | ||
| 1028 | + // jsMemoryEstimate: 2438996, | ||
| 1029 | + // jsMemoryRange: [ 2438996, 2768636 ] | ||
| 1030 | + // }, | ||
| 1031 | + // other: [ | ||
| 1032 | + // { | ||
| 1033 | + // jsMemoryEstimate: 135736, | ||
| 1034 | + // jsMemoryRange: [ 135736, 465376 ] | ||
| 1035 | + // } | ||
| 1036 | + // ] | ||
| 1037 | + // } | ||
| 1038 | + console.log(result); | ||
| 1039 | + }); | ||
| 1040 | + ``` | ||
| 1041 | + | ||
| 1042 | 1042 | ## `vm.runInContext(code, contextifiedObject[, options])` | |
| 1043 | 1043 | <!-- YAML | |
| 1044 | 1044 | added: v0.3.1 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments