Skip to content

Commit 1bbdd93

Browse files
authored
Merge pull request #477 from sam-github/add-new-gc-types
Expose new GC types introduced in v8 version 4.6
2 parents eed52dd + 107cd81 commit 1bbdd93

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,13 @@ Emitted every 5 seconds, summarising sample based information of the event loop
238238
Emitted when a garbage collection (GC) cycle occurs in the underlying V8 runtime.
239239
* `data` (Object) the data from the GC sample:
240240
* `time` (Number) the milliseconds when the sample was taken. This can be converted to a Date using `new Date(data.time)`.
241-
* `type` (String) the type of GC cycle, either 'M' or 'S'.
241+
* `type` (String) the type of GC cycle, either:
242+
- `'M'`: MarkSweepCompact, aka "major"
243+
- `'S'`: Scavenge, aka "minor"
244+
- `'I'`: IncrementalMarking, aka "incremental" (only exists on node 5.x
245+
and greater)
246+
- '`W'`: ProcessWeakCallbacks, aka "weakcb" (only exists on node 5.x
247+
and greater)
242248
* `size` (Number) the size of the JavaScript heap in bytes.
243249
* `used` (Number) the amount of memory used on the JavaScript heap in bytes.
244250
* `duration` (Number) the duration of the GC cycle in milliseconds.

src/plugins/node/gc/nodegcplugin.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,17 @@ void afterGC(v8::Isolate *isolate, GCType type, GCCallbackFlags flags) {
115115
gcRealEnd = GetRealTime();
116116

117117
// GC type
118-
const char *gcType = (type == kGCTypeMarkSweepCompact) ? "M" : "S";
118+
const char *gcType = NULL;
119+
switch (type) {
120+
case kGCTypeMarkSweepCompact: gcType = "M"; break;
121+
case kGCTypeScavenge: gcType = "S"; break;
122+
#if NODE_VERSION_AT_LEAST(5, 0, 0)
123+
case kGCTypeIncrementalMarking: gcType = "I"; break;
124+
case kGCTypeProcessWeakCallbacks: gcType = "W"; break;
125+
#endif
126+
// Should never happen, but call it minor if type is unrecognized.
127+
default: gcType = "S"; break;
128+
}
119129

120130
// GC heap stats
121131
HeapStatistics hs;

0 commit comments

Comments
 (0)