Skip to content

Commit 107cd81

Browse files
committed
Expose new GC types introduced in v8 version 4.6
Everything that was not kGCTypeMarkSweepCompact used to be mapped to "S" (Scavenge), but that became wrong with 4.6, which has more GC types.
1 parent 763f90c commit 107cd81

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
@@ -149,7 +149,17 @@ void afterGC(v8::Isolate *isolate, GCType type, GCCallbackFlags flags) {
149149
gcRealEnd = GetRealTime();
150150

151151
// GC type
152-
const char *gcType = (type == kGCTypeMarkSweepCompact) ? "M" : "S";
152+
const char *gcType = NULL;
153+
switch (type) {
154+
case kGCTypeMarkSweepCompact: gcType = "M"; break;
155+
case kGCTypeScavenge: gcType = "S"; break;
156+
#if NODE_VERSION_AT_LEAST(5, 0, 0)
157+
case kGCTypeIncrementalMarking: gcType = "I"; break;
158+
case kGCTypeProcessWeakCallbacks: gcType = "W"; break;
159+
#endif
160+
// Should never happen, but call it minor if type is unrecognized.
161+
default: gcType = "S"; break;
162+
}
153163

154164
// GC heap stats
155165
HeapStatistics hs;

0 commit comments

Comments
 (0)