Skip to content

Commit 9eeee0d

Browse files
fanatidtargos
authored andcommitted
perf_hooks: add property flags to GCPerformanceEntry
PR-URL: #29547 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent ab8f38b commit 9eeee0d

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

doc/api/perf_hooks.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,25 @@ The value may be one of:
209209
* `perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL`
210210
* `perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB`
211211

212+
### performanceEntry.flags
213+
<!-- YAML
214+
added: REPLACEME
215+
-->
216+
217+
* {number}
218+
219+
When `performanceEntry.entryType` is equal to `'gc'`, the `performance.flags`
220+
property contains additional information about garbage collection operation.
221+
The value may be one of:
222+
223+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO`
224+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED`
225+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED`
226+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING`
227+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE`
228+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY`
229+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE`
230+
212231
## Class: `PerformanceNodeTiming extends PerformanceEntry`
213232
<!-- YAML
214233
added: v8.5.0

src/node_perf.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ void PerformanceGCCallback(Environment* env,
249249
env->kind_string(),
250250
Integer::New(env->isolate(), entry->gckind()),
251251
attr).Check();
252+
obj->DefineOwnProperty(context,
253+
env->flags_string(),
254+
Integer::New(env->isolate(), entry->gcflags()),
255+
attr).Check();
252256
PerformanceEntry::Notify(env, entry->kind(), obj);
253257
}
254258
}
@@ -275,6 +279,7 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
275279
auto entry = std::make_unique<GCPerformanceEntry>(
276280
env,
277281
static_cast<PerformanceGCKind>(type),
282+
static_cast<PerformanceGCFlags>(flags),
278283
state->performance_last_gc_start_mark,
279284
PERFORMANCE_NOW());
280285
env->SetUnrefImmediate([entry = std::move(entry)](Environment* env) mutable {
@@ -592,6 +597,21 @@ void Initialize(Local<Object> target,
592597
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_INCREMENTAL);
593598
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_WEAKCB);
594599

600+
NODE_DEFINE_CONSTANT(
601+
constants, NODE_PERFORMANCE_GC_FLAGS_NO);
602+
NODE_DEFINE_CONSTANT(
603+
constants, NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED);
604+
NODE_DEFINE_CONSTANT(
605+
constants, NODE_PERFORMANCE_GC_FLAGS_FORCED);
606+
NODE_DEFINE_CONSTANT(
607+
constants, NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING);
608+
NODE_DEFINE_CONSTANT(
609+
constants, NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE);
610+
NODE_DEFINE_CONSTANT(
611+
constants, NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY);
612+
NODE_DEFINE_CONSTANT(
613+
constants, NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE);
614+
595615
#define V(name, _) \
596616
NODE_DEFINE_HIDDEN_CONSTANT(constants, NODE_PERFORMANCE_ENTRY_TYPE_##name);
597617
NODE_PERFORMANCE_ENTRY_TYPES(V)

src/node_perf.h

Lines changed: 23 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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)