Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: add property flags to GCPerformanceEntry #29547

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/api/perf_hooks.md
Expand Up @@ -201,6 +201,25 @@ The value may be one of:
* `perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL`
* `perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB`

### performanceEntry.flags
<!-- YAML
added: REPLACEME
-->

* {number}

When `performanceEntry.entryType` is equal to `'gc'`, the `performance.flags`
property contains additional information about garbage collection operation.
The value may be one of:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are exposing this we at least need a note similar to the one in https://nodejs.org/api/v8.html#v8_v8_getheapspacestatistics

Neither the ordering of heap spaces, nor the availability of a heap space can be guaranteed as the statistics are provided via the V8 GetHeapSpaceStatistics function and may change from one V8 version to the next.

As compared to the GC kind the flags here seem to be even less stable.

This also lacks explanation and they are less self-explanatory compared to the gc kinds. I guess we could link to the v8 docs of GCCallbackFlags at least for reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flags provided via V8 GCCallbackFlags enum and may change from one V8 version to next.

Looks good for adding after constants list?


* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO`
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED`
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED`
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING`
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE`
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY`
* `perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE`

## Class: `PerformanceNodeTiming extends PerformanceEntry`
<!-- YAML
added: v8.5.0
Expand Down
20 changes: 20 additions & 0 deletions src/node_perf.cc
Expand Up @@ -244,6 +244,10 @@ void PerformanceGCCallback(Environment* env,
env->kind_string(),
Integer::New(env->isolate(), entry->gckind()),
attr).Check();
obj->DefineOwnProperty(context,
env->flags_string(),
Integer::New(env->isolate(), entry->gcflags()),
attr).Check();
PerformanceEntry::Notify(env, entry->kind(), obj);
}
}
Expand All @@ -270,6 +274,7 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
auto entry = std::make_unique<GCPerformanceEntry>(
env,
static_cast<PerformanceGCKind>(type),
static_cast<PerformanceGCFlags>(flags),
state->performance_last_gc_start_mark,
PERFORMANCE_NOW());
env->SetUnrefImmediate([entry = std::move(entry)](Environment* env) mutable {
Expand Down Expand Up @@ -587,6 +592,21 @@ void Initialize(Local<Object> target,
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_INCREMENTAL);
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_WEAKCB);

NODE_DEFINE_CONSTANT(
constants, NODE_PERFORMANCE_GC_FLAGS_NO);
NODE_DEFINE_CONSTANT(
constants, NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED);
NODE_DEFINE_CONSTANT(
constants, NODE_PERFORMANCE_GC_FLAGS_FORCED);
NODE_DEFINE_CONSTANT(
constants, NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING);
NODE_DEFINE_CONSTANT(
constants, NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE);
NODE_DEFINE_CONSTANT(
constants, NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY);
NODE_DEFINE_CONSTANT(
constants, NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE);

#define V(name, _) \
NODE_DEFINE_HIDDEN_CONSTANT(constants, NODE_PERFORMANCE_ENTRY_TYPE_##name);
NODE_PERFORMANCE_ENTRY_TYPES(V)
Expand Down
24 changes: 23 additions & 1 deletion src/node_perf.h
Expand Up @@ -21,6 +21,7 @@ namespace performance {

using v8::FunctionCallbackInfo;
using v8::GCType;
using v8::GCCallbackFlags;
using v8::Local;
using v8::Object;
using v8::Value;
Expand Down Expand Up @@ -110,19 +111,40 @@ enum PerformanceGCKind {
NODE_PERFORMANCE_GC_WEAKCB = GCType::kGCTypeProcessWeakCallbacks
};

enum PerformanceGCFlags {
NODE_PERFORMANCE_GC_FLAGS_NO =
GCCallbackFlags::kNoGCCallbackFlags,
NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED =
GCCallbackFlags::kGCCallbackFlagConstructRetainedObjectInfos,
NODE_PERFORMANCE_GC_FLAGS_FORCED =
GCCallbackFlags::kGCCallbackFlagForced,
NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING =
GCCallbackFlags::kGCCallbackFlagSynchronousPhantomCallbackProcessing,
NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE =
GCCallbackFlags::kGCCallbackFlagCollectAllAvailableGarbage,
NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY =
GCCallbackFlags::kGCCallbackFlagCollectAllExternalMemory,
NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE =
GCCallbackFlags::kGCCallbackScheduleIdleGarbageCollection
};

class GCPerformanceEntry : public PerformanceEntry {
public:
GCPerformanceEntry(Environment* env,
PerformanceGCKind gckind,
PerformanceGCFlags gcflags,
uint64_t startTime,
uint64_t endTime) :
PerformanceEntry(env, "gc", "gc", startTime, endTime),
gckind_(gckind) { }
gckind_(gckind),
gcflags_(gcflags) { }

PerformanceGCKind gckind() const { return gckind_; }
PerformanceGCFlags gcflags() const { return gcflags_; }

private:
PerformanceGCKind gckind_;
PerformanceGCFlags gcflags_;
};

class ELDHistogram : public HandleWrap, public Histogram {
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-performance-gc.js
Expand Up @@ -12,7 +12,8 @@ const {
NODE_PERFORMANCE_GC_MAJOR,
NODE_PERFORMANCE_GC_MINOR,
NODE_PERFORMANCE_GC_INCREMENTAL,
NODE_PERFORMANCE_GC_WEAKCB
NODE_PERFORMANCE_GC_WEAKCB,
NODE_PERFORMANCE_GC_FLAGS_FORCED
} = constants;

const kinds = [
Expand All @@ -30,6 +31,7 @@ const kinds = [
assert.strictEqual(entry.name, 'gc');
assert.strictEqual(entry.entryType, 'gc');
assert(kinds.includes(entry.kind));
assert.strictEqual(entry.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED);
assert.strictEqual(typeof entry.startTime, 'number');
assert.strictEqual(typeof entry.duration, 'number');
obs.disconnect();
Expand Down