| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 577d228 commit 3982919
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1610,6 +1610,28 @@ Will generate: | |||
| 1610 | 1610 | When using [`Worker`][] threads, `rss` will be a value that is valid for the | |
| 1611 | 1611 | entire process, while the other fields will only refer to the current thread. | |
| 1612 | 1612 | ||
| 1613 | + The `process.memoryUsage()` method iterate over each page to gather | ||
| 1614 | + informations about memory usage which can be slow depending on the | ||
| 1615 | + program memory allocations. | ||
| 1616 | + | ||
| 1617 | + ## `process.memoryUsage.rss()` | ||
| 1618 | + | ||
| 1619 | + * Returns: {integer} | ||
| 1620 | + | ||
| 1621 | + The `process.memoryUsage.rss()` method returns an integer representing the | ||
| 1622 | + Resident Set Size (RSS) in bytes. | ||
| 1623 | + | ||
| 1624 | + The Resident Set Size, is the amount of space occupied in the main | ||
| 1625 | + memory device (that is a subset of the total allocated memory) for the | ||
| 1626 | + process, including all C++ and JavaScript objects and code. | ||
| 1627 | + | ||
| 1628 | + This is the same value as the one returned by `process.memoryUsage()`. | ||
| 1629 | + | ||
| 1630 | + ```js | ||
| 1631 | + console.log(process.memoryUsage.rss()); | ||
| 1632 | + // 35655680 | ||
| 1633 | + ``` | ||
| 1634 | + | ||
| 1613 | 1635 | ## `process.nextTick(callback[, ...args])` | |
| 1614 | 1636 | <!-- YAML | |
| 1615 | 1637 | added: v0.1.26 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ function wrapProcessMethods(binding) { | |||
| 46 | 46 | hrtimeBigInt: _hrtimeBigInt, | |
| 47 | 47 | cpuUsage: _cpuUsage, | |
| 48 | 48 | memoryUsage: _memoryUsage, | |
| 49 | + rss, | ||
| 49 | 50 | resourceUsage: _resourceUsage | |
| 50 | 51 | } = binding; | |
| 51 | 52 | ||
@@ -160,6 +161,8 @@ function wrapProcessMethods(binding) { | |||
| 160 | 161 | }; | |
| 161 | 162 | } | |
| 162 | 163 | ||
| 164 | + memoryUsage.rss = rss; | ||
| 165 | + | ||
| 163 | 166 | function exit(code) { | |
| 164 | 167 | if (code || code === 0) | |
| 165 | 168 | process.exitCode = code; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -193,14 +193,20 @@ static void Kill(const FunctionCallbackInfo<Value>& args) { | |||
| 193 | 193 | args.GetReturnValue().Set(err); | |
| 194 | 194 | } | |
| 195 | 195 | ||
| 196 | - static void MemoryUsage(const FunctionCallbackInfo<Value>& args) { | ||
| 196 | + static void Rss(const FunctionCallbackInfo<Value>& args) { | ||
| 197 | 197 | Environment* env = Environment::GetCurrent(args); | |
| 198 | 198 | ||
| 199 | 199 | size_t rss; | |
| 200 | 200 | int err = uv_resident_set_memory(&rss); | |
| 201 | 201 | if (err) | |
| 202 | 202 | return env->ThrowUVException(err, "uv_resident_set_memory"); | |
| 203 | 203 | ||
| 204 | + args.GetReturnValue().Set(static_cast<double>(rss)); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + static void MemoryUsage(const FunctionCallbackInfo<Value>& args) { | ||
| 208 | + Environment* env = Environment::GetCurrent(args); | ||
| 209 | + | ||
| 204 | 210 | Isolate* isolate = env->isolate(); | |
| 205 | 211 | // V8 memory usage | |
| 206 | 212 | HeapStatistics v8_heap_stats; | |
@@ -213,6 +219,11 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) { | |||
| 213 | 219 | Local<ArrayBuffer> ab = get_fields_array_buffer(args, 0, 5); | |
| 214 | 220 | double* fields = static_cast<double*>(ab->GetBackingStore()->Data()); | |
| 215 | 221 | ||
| 222 | + size_t rss; | ||
| 223 | + int err = uv_resident_set_memory(&rss); | ||
| 224 | + if (err) | ||
| 225 | + return env->ThrowUVException(err, "uv_resident_set_memory"); | ||
| 226 | + | ||
| 216 | 227 | fields[0] = rss; | |
| 217 | 228 | fields[1] = v8_heap_stats.total_heap_size(); | |
| 218 | 229 | fields[2] = v8_heap_stats.used_heap_size(); | |
@@ -450,6 +461,7 @@ static void InitializeProcessMethods(Local<Object> target, | |||
| 450 | 461 | env->SetMethod(target, "umask", Umask); | |
| 451 | 462 | env->SetMethod(target, "_rawDebug", RawDebug); | |
| 452 | 463 | env->SetMethod(target, "memoryUsage", MemoryUsage); | |
| 464 | + env->SetMethod(target, "rss", Rss); | ||
| 453 | 465 | env->SetMethod(target, "cpuUsage", CPUUsage); | |
| 454 | 466 | env->SetMethod(target, "hrtime", Hrtime); | |
| 455 | 467 | env->SetMethod(target, "hrtimeBigInt", HrtimeBigInt); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,3 +44,5 @@ if (r.arrayBuffers > 0) { | |||
| 44 | 44 | assert.strictEqual(after.arrayBuffers - r.arrayBuffers, size, | |
| 45 | 45 | `${after.arrayBuffers} - ${r.arrayBuffers} === ${size}`); | |
| 46 | 46 | } | |
| 47 | + | ||
| 48 | + assert(process.memoryUsage.rss() > 0); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments