Skip to content

Commit e7fea14

Browse files
fanatidcodebytere
authored andcommitted
perf_hooks: add property flags to GCPerformanceEntry
PR-URL: #29547 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 425662e commit e7fea14

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

doc/api/perf_hooks.md

+19
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ The value may be one of:
201201
* `perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL`
202202
* `perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB`
203203

204+
### performanceEntry.flags
205+
<!-- YAML
206+
added: REPLACEME
207+
-->
208+
209+
* {number}
210+
211+
When `performanceEntry.entryType` is equal to `'gc'`, the `performance.flags`
212+
property contains additional information about garbage collection operation.
213+
The value may be one of:
214+
215+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO`
216+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED`
217+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED`
218+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING`
219+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE`
220+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY`
221+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE`
222+
204223
## Class: `PerformanceNodeTiming extends PerformanceEntry`
205224
<!-- YAML
206225
added: v8.5.0

src/node_perf.cc

+20
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ void PerformanceGCCallback(Environment* env,
244244
env->kind_string(),
245245
Integer::New(env->isolate(), entry->gckind()),
246246
attr).Check();
247+
obj->DefineOwnProperty(context,
248+
env->flags_string(),
249+
Integer::New(env->isolate(), entry->gcflags()),
250+
attr).Check();
247251
PerformanceEntry::Notify(env, entry->kind(), obj);
248252
}
249253
}
@@ -270,6 +274,7 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
270274
auto entry = std::make_unique<GCPerformanceEntry>(
271275
env,
272276
static_cast<PerformanceGCKind>(type),
277+
static_cast<PerformanceGCFlags>(flags),
273278
state->performance_last_gc_start_mark,
274279
PERFORMANCE_NOW());
275280
env->SetUnrefImmediate([entry = std::move(entry)](Environment* env) mutable {
@@ -587,6 +592,21 @@ void Initialize(Local<Object> target,
587592
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_INCREMENTAL);
588593
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_WEAKCB);
589594

595+
NODE_DEFINE_CONSTANT(
596+
constants, NODE_PERFORMANCE_GC_FLAGS_NO);
597+
NODE_DEFINE_CONSTANT(
598+
constants, NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED);
599+
NODE_DEFINE_CONSTANT(
600+
constants, NODE_PERFORMANCE_GC_FLAGS_FORCED);
601+
NODE_DEFINE_CONSTANT(
602+
constants, NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING);
603+
NODE_DEFINE_CONSTANT(
604+
constants, NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE);
605+
NODE_DEFINE_CONSTANT(
606+
constants, NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY);
607+
NODE_DEFINE_CONSTANT(
608+
constants, NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE);
609+
590610
#define V(name, _) \
591611
NODE_DEFINE_HIDDEN_CONSTANT(constants, NODE_PERFORMANCE_ENTRY_TYPE_##name);
592612
NODE_PERFORMANCE_ENTRY_TYPES(V)

src/node_perf.h

+23-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace performance {
2121

2222
using v8::FunctionCallbackInfo;
2323
using v8::GCType;
24+
using v8::GCCallbackFlags;
2425
using v8::Local;
2526
using v8::Object;
2627
using v8::Value;
@@ -110,19 +111,40 @@ enum PerformanceGCKind {
110111
NODE_PERFORMANCE_GC_WEAKCB = GCType::kGCTypeProcessWeakCallbacks
111112
};
112113

114+
enum PerformanceGCFlags {
115+
NODE_PERFORMANCE_GC_FLAGS_NO =
116+
GCCallbackFlags::kNoGCCallbackFlags,
117+
NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED =
118+
GCCallbackFlags::kGCCallbackFlagConstructRetainedObjectInfos,
119+
NODE_PERFORMANCE_GC_FLAGS_FORCED =
120+
GCCallbackFlags::kGCCallbackFlagForced,
121+
NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING =
122+
GCCallbackFlags::kGCCallbackFlagSynchronousPhantomCallbackProcessing,
123+
NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE =
124+
GCCallbackFlags::kGCCallbackFlagCollectAllAvailableGarbage,
125+
NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY =
126+
GCCallbackFlags::kGCCallbackFlagCollectAllExternalMemory,
127+
NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE =
128+
GCCallbackFlags::kGCCallbackScheduleIdleGarbageCollection
129+
};
130+
113131
class GCPerformanceEntry : public PerformanceEntry {
114132
public:
115133
GCPerformanceEntry(Environment* env,
116134
PerformanceGCKind gckind,
135+
PerformanceGCFlags gcflags,
117136
uint64_t startTime,
118137
uint64_t endTime) :
119138
PerformanceEntry(env, "gc", "gc", startTime, endTime),
120-
gckind_(gckind) { }
139+
gckind_(gckind),
140+
gcflags_(gcflags) { }
121141

122142
PerformanceGCKind gckind() const { return gckind_; }
143+
PerformanceGCFlags gcflags() const { return gcflags_; }
123144

124145
private:
125146
PerformanceGCKind gckind_;
147+
PerformanceGCFlags gcflags_;
126148
};
127149

128150
class ELDHistogram : public HandleWrap, public Histogram {

test/parallel/test-performance-gc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const {
1212
NODE_PERFORMANCE_GC_MAJOR,
1313
NODE_PERFORMANCE_GC_MINOR,
1414
NODE_PERFORMANCE_GC_INCREMENTAL,
15-
NODE_PERFORMANCE_GC_WEAKCB
15+
NODE_PERFORMANCE_GC_WEAKCB,
16+
NODE_PERFORMANCE_GC_FLAGS_FORCED
1617
} = constants;
1718

1819
const kinds = [
@@ -30,6 +31,7 @@ const kinds = [
3031
assert.strictEqual(entry.name, 'gc');
3132
assert.strictEqual(entry.entryType, 'gc');
3233
assert(kinds.includes(entry.kind));
34+
assert.strictEqual(entry.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED);
3335
assert.strictEqual(typeof entry.startTime, 'number');
3436
assert.strictEqual(typeof entry.duration, 'number');
3537
obs.disconnect();

0 commit comments

Comments
 (0)