Skip to content

Commit 5abaac2

Browse files
IlyasShabigh-worker-campaigns-3e9aa4[bot]dependabot[bot]szegedi
authored
V5.14.2 (#331)
* use trusted publishing for dev releases (#310) * use trusted publishing for dev releases * use release publisher file to release dev tag too (#311) use release publisher file to release dev tag * chore(deps): minor: sinon · patch: @types/node, @types/sinon (#317) Co-authored-by: gh-worker-campaigns-3e9aa4[bot] <244854796+gh-worker-campaigns-3e9aa4[bot]@users.noreply.github.com> * build(deps-dev): bump typescript from 5.9.3 to 6.0.3 (#315) * build(deps-dev): bump typescript from 5.9.3 to 6.0.3 Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.9.3 to 6.0.3. - [Commits](microsoft/TypeScript@v5.9.3...v6.0.3) --- updated-dependencies: - dependency-name: typescript dependency-version: 6.0.3 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix(ts): explicit types in tsconfig and bump @types/node to 25.6.0 TypeScript 6.0 no longer auto-loads @types/* by default with this project's tsconfig setup, so Node and Mocha globals (Buffer, process, __dirname, describe, it, ...) became unresolved. Pin "types" to ["node", "mocha"] so the compiler picks them up explicitly. Also bumps @types/node from 25.5.2 to 25.6.0, superseding #314. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Attila Szegedi <attila.szegedi@datadoghq.com> * chore(deps): node-gyp-build (major → 4.8.4) (#316) Co-authored-by: gh-worker-campaigns-3e9aa4[bot] <244854796+gh-worker-campaigns-3e9aa4[bot]@users.noreply.github.com> * build(deps-dev): bump @types/node from 25.6.0 to 25.7.0 (#324) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 25.6.0 to 25.7.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-version: 25.7.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps-dev): bump eslint-plugin-n from 17.24.0 to 18.0.1 (#320) Bumps [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) from 17.24.0 to 18.0.1. - [Release notes](https://github.com/eslint-community/eslint-plugin-n/releases) - [Changelog](https://github.com/eslint-community/eslint-plugin-n/blob/master/CHANGELOG.md) - [Commits](eslint-community/eslint-plugin-n@v17.24.0...v18.0.1) --- updated-dependencies: - dependency-name: eslint-plugin-n dependency-version: 18.0.1 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump node-gyp-build from 3.9.0 to 4.8.4 (#284) Bumps [node-gyp-build](https://github.com/prebuild/node-gyp-build) from 3.9.0 to 4.8.4. - [Commits](prebuild/node-gyp-build@v3.9.0...v4.8.4) --- updated-dependencies: - dependency-name: node-gyp-build dependency-version: 4.8.4 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Attila Szegedi <szegedi@users.noreply.github.com> * build(deps-dev): bump semver from 7.7.4 to 7.8.0 (#323) Bumps [semver](https://github.com/npm/node-semver) from 7.7.4 to 7.8.0. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/main/CHANGELOG.md) - [Commits](npm/node-semver@v7.7.4...v7.8.0) --- updated-dependencies: - dependency-name: semver dependency-version: 7.8.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps-dev): bump sinon from 21.1.2 to 22.0.0 (#325) Bumps [sinon](https://github.com/sinonjs/sinon) from 21.1.2 to 22.0.0. - [Release notes](https://github.com/sinonjs/sinon/releases) - [Changelog](https://github.com/sinonjs/sinon/blob/main/docs/changelog.md) - [Commits](sinonjs/sinon@v21.1.2...v22.0.0) --- updated-dependencies: - dependency-name: sinon dependency-version: 22.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add Node.js v25 to benchmarks (#326) * support Node.js v26 (#327) * support Node.js v26 * Revert lazy profile-tree changes to mitigate CpuProfile::Delete crash (#329) * Revert "use stop and collect on time profiler (#305)" This reverts commit 85f2457. * Revert "Switch heap profiling to use lazy allocation profile method by default (#281)" This reverts commit fb3d75d. * Touchup for TS6 changes introduced after the reverted commits. Specifically enforcing TS2883 under `composite: true`: any function whose inferred return type names a non-imported type must be annotated explicitly. * v14.5.2 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: gh-worker-campaigns-3e9aa4[bot] <244854796+gh-worker-campaigns-3e9aa4[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Attila Szegedi <attila.szegedi@datadoghq.com> Co-authored-by: Attila Szegedi <szegedi@users.noreply.github.com>
1 parent 0cc3b97 commit 5abaac2

23 files changed

Lines changed: 1228 additions & 262 deletions

.github/workflows/build.yml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
asan:
1111
strategy:
1212
matrix:
13-
version: [18, 20, 22, 24, 25]
13+
version: [18, 20, 22, 24, 25, 26]
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v3
@@ -23,7 +23,7 @@ jobs:
2323
valgrind:
2424
strategy:
2525
matrix:
26-
version: [18, 20, 22, 24, 25]
26+
version: [18, 20, 22, 24, 25, 26]
2727
runs-on: ubuntu-latest
2828
steps:
2929
- uses: actions/checkout@v3
@@ -42,27 +42,7 @@ jobs:
4242
cache: true # enable caching of dependencies based on lockfile
4343
min-node-version: 18
4444
skip: 'linux-arm,linux-ia32' # skip building for these platforms
45-
46-
dev_publish:
47-
needs: build
48-
runs-on: ubuntu-latest
49-
if: github.ref == 'refs/heads/main'
50-
environment: npm
51-
env:
52-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
53-
steps:
54-
- uses: actions/checkout@v2
55-
- uses: actions/download-artifact@v4
56-
- uses: actions/setup-node@v3
57-
with:
58-
registry-url: 'https://registry.npmjs.org'
59-
- run: npm install
60-
- id: pkg
61-
run: |
62-
content=`cat ./package.json | tr '\n' ' '`
63-
echo "json=$content" >> $GITHUB_OUTPUT
64-
- run: npm version --no-git-tag-version ${{ fromJson(steps.pkg.outputs.json).version }}-$(git rev-parse --short HEAD)+${{ github.run_id }}.${{ github.run_attempt }}
65-
- run: npm publish --tag dev
45+
node-gyp-build-major: 4
6646

6747
build-successful:
6848
if: always()

.github/workflows/release.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Release
33
on:
44
push:
55
branches:
6+
- main
67
- v[0-9]+.x
78

89
jobs:
@@ -15,9 +16,11 @@ jobs:
1516
min-node-version: 18
1617
skip: 'linux-arm,linux-ia32' # skip building for these platforms
1718

18-
publish:
19+
publish_release:
1920
needs: build
2021
runs-on: ubuntu-latest
22+
# release.yml also runs on main for dev publishes, so keep release publishes on version branches only.
23+
if: startsWith(github.ref, 'refs/heads/v')
2124
environment: npm
2225
permissions:
2326
id-token: write # Required for OIDC
@@ -43,3 +46,26 @@ jobs:
4346
- run: |
4447
git tag v${{ fromJson(steps.pkg.outputs.json).version }}
4548
git push https://x-access-token:${{ steps.octo-sts.outputs.token }}@github.com/${{ github.repository }}.git v${{ fromJson(steps.pkg.outputs.json).version }}
49+
50+
publish_dev:
51+
needs: build
52+
runs-on: ubuntu-latest
53+
if: github.ref == 'refs/heads/main'
54+
environment: npm
55+
permissions:
56+
id-token: write # Required for OIDC
57+
contents: read
58+
steps:
59+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
60+
- uses: actions/download-artifact@v4
61+
- uses: actions/setup-node@v3
62+
with:
63+
node-version: '24'
64+
registry-url: 'https://registry.npmjs.org'
65+
- run: npm install
66+
- id: pkg
67+
run: |
68+
content=`cat ./package.json | tr '\n' ' '`
69+
echo "json=$content" >> $GITHUB_OUTPUT
70+
- run: npm version --no-git-tag-version ${{ fromJson(steps.pkg.outputs.json).version }}-$(git rev-parse --short HEAD)+${{ github.run_id }}.${{ github.run_attempt }}
71+
- run: npm publish --tag dev

.gitlab/benchmarks.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ benchmarks:
3636
- MAJOR_NODE_VERSION: 20
3737
- MAJOR_NODE_VERSION: 22
3838
- MAJOR_NODE_VERSION: 24
39-
# TODO: Re-enable this once support for Node 25 is merged on main
40-
# - MAJOR_NODE_VERSION: 25
39+
- MAJOR_NODE_VERSION: 25
4140
artifacts:
4241
name: "reports"
4342
paths:

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,10 @@ Install [`pprof`][npm-url] with `npm` or add to your `package.json`.
9797
pprof -http=: heap.pb.gz
9898
```
9999

100-
* Collecting a heap profile with V8 allocation profile format:
100+
* Collecting a heap profile with V8 allocation profile format:
101101
```javascript
102-
const profile = pprof.heap.v8Profile(pprof.heap.convertProfile);
102+
const profile = await pprof.heap.v8Profile();
103103
```
104-
`v8Profile` accepts a callback and returns its result. Allocation nodes
105-
are only valid during the callback, so copy/transform what you need
106-
before returning. `heap.convertProfile` performs that conversion during
107-
the callback, and `heap.profile()` uses it under the hood.
108104

109105
[build-image]: https://github.com/Datadog/pprof-nodejs/actions/workflows/build.yml/badge.svg?branch=main
110106
[build-url]: https://github.com/Datadog/pprof-nodejs/actions/workflows/build.yml

benchmark/sirun/runall.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if [ -n "${MAJOR_NODE_VERSION:-}" ]; then
99
source "${NVM_DIR:-usr/local/nvm}/nvm.sh"
1010
fi
1111

12+
nvm install "${MAJOR_NODE_VERSION}"
1213
nvm use "${MAJOR_NODE_VERSION}"
1314

1415
pushd ../../

bindings/profilers/heap.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,23 @@ NAN_METHOD(HeapProfiler::StopSamplingHeapProfiler) {
488488
}
489489
}
490490

491+
// Signature:
492+
// getAllocationProfile(): AllocationProfileNode
493+
NAN_METHOD(HeapProfiler::GetAllocationProfile) {
494+
auto isolate = info.GetIsolate();
495+
std::unique_ptr<v8::AllocationProfile> profile(
496+
isolate->GetHeapProfiler()->GetAllocationProfile());
497+
if (!profile) {
498+
return Nan::ThrowError("Heap profiler is not enabled.");
499+
}
500+
v8::AllocationProfile::Node* root = profile->GetRootNode();
501+
auto state = PerIsolateData::For(isolate)->GetHeapProfilerState();
502+
if (state) {
503+
state->OnNewProfile();
504+
}
505+
info.GetReturnValue().Set(TranslateAllocationProfile(root));
506+
}
507+
491508
// mapAllocationProfile(callback): callback result
492509
NAN_METHOD(HeapProfiler::MapAllocationProfile) {
493510
if (info.Length() < 1 || !info[0]->IsFunction()) {
@@ -579,6 +596,7 @@ NAN_MODULE_INIT(HeapProfiler::Init) {
579596
heapProfiler, "startSamplingHeapProfiler", StartSamplingHeapProfiler);
580597
Nan::SetMethod(
581598
heapProfiler, "stopSamplingHeapProfiler", StopSamplingHeapProfiler);
599+
Nan::SetMethod(heapProfiler, "getAllocationProfile", GetAllocationProfile);
582600
Nan::SetMethod(heapProfiler, "mapAllocationProfile", MapAllocationProfile);
583601
Nan::SetMethod(heapProfiler, "monitorOutOfMemory", MonitorOutOfMemory);
584602
Nan::Set(target,

bindings/profilers/heap.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class HeapProfiler {
3030
// stopSamplingHeapProfiler()
3131
static NAN_METHOD(StopSamplingHeapProfiler);
3232

33+
// Signature:
34+
// getAllocationProfile(): AllocationProfileNode
35+
static NAN_METHOD(GetAllocationProfile);
36+
3337
// Signature:
3438
// mapAllocationProfile(callback): callback result
3539
static NAN_METHOD(MapAllocationProfile);

bindings/profilers/wall.cc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ class PersistentContextPtr : public node::ObjectWrap {
135135
}
136136
};
137137

138+
inline void* GetAlignedPointerFromInternalField(Object* object, int index) {
139+
#if NODE_MAJOR_VERSION >= 26
140+
return object->GetAlignedPointerFromInternalField(
141+
index, kEmbedderDataTypeTagDefault);
142+
#else
143+
return object->GetAlignedPointerFromInternalField(index);
144+
#endif
145+
}
146+
138147
// Maximum number of rounds in the GetV8ToEpochOffset
139148
static constexpr int MAX_EPOCH_OFFSET_ATTEMPTS = 20;
140149

@@ -920,6 +929,28 @@ v8::ProfilerId WallProfiler::StartInternal() {
920929
return result.id;
921930
}
922931

932+
NAN_METHOD(WallProfiler::Stop) {
933+
if (info.Length() != 1) {
934+
return Nan::ThrowTypeError("Stop must have one argument.");
935+
}
936+
if (!info[0]->IsBoolean()) {
937+
return Nan::ThrowTypeError("Restart must be a boolean.");
938+
}
939+
940+
bool restart = info[0].As<Boolean>()->Value();
941+
942+
WallProfiler* wallProfiler =
943+
Nan::ObjectWrap::Unwrap<WallProfiler>(info.This());
944+
945+
v8::Local<v8::Value> profile;
946+
auto err = wallProfiler->StopImpl(restart, profile);
947+
948+
if (!err.success) {
949+
return Nan::ThrowTypeError(err.msg.c_str());
950+
}
951+
info.GetReturnValue().Set(profile);
952+
}
953+
923954
// stopAndCollect(restart, callback): callback result
924955
NAN_METHOD(WallProfiler::StopAndCollect) {
925956
if (info.Length() != 2) {
@@ -1078,6 +1109,20 @@ Result WallProfiler::StopCore(bool restart, ProfileBuilder&& buildProfile) {
10781109
return {};
10791110
}
10801111

1112+
Result WallProfiler::StopImpl(bool restart, v8::Local<v8::Value>& profile) {
1113+
return StopCore(restart,
1114+
[&](const v8::CpuProfile* v8_profile,
1115+
bool hasCpuTime,
1116+
int64_t nonJSThreadsCpuTime,
1117+
ContextsByNode* contextsByNodePtr) {
1118+
profile = TranslateTimeProfile(v8_profile,
1119+
includeLines_,
1120+
contextsByNodePtr,
1121+
hasCpuTime,
1122+
nonJSThreadsCpuTime);
1123+
});
1124+
}
1125+
10811126
Result WallProfiler::StopAndCollectImpl(bool restart,
10821127
v8::Local<v8::Function> callback,
10831128
v8::Local<v8::Value>& result) {
@@ -1112,6 +1157,7 @@ NAN_MODULE_INIT(WallProfiler::Init) {
11121157
SetContext);
11131158

11141159
Nan::SetPrototypeMethod(tpl, "start", Start);
1160+
Nan::SetPrototypeMethod(tpl, "stop", Stop);
11151161
Nan::SetPrototypeMethod(tpl, "stopAndCollect", StopAndCollect);
11161162
Nan::SetPrototypeMethod(tpl, "dispose", Dispose);
11171163
Nan::SetPrototypeMethod(tpl,
@@ -1274,7 +1320,7 @@ ContextPtr WallProfiler::GetContextPtr(Isolate* isolate) {
12741320
auto wrapObj = reinterpret_cast<Object*>(wrapValue);
12751321
if (wrapObj->InternalFieldCount() > 0) {
12761322
return static_cast<PersistentContextPtr*>(
1277-
wrapObj->GetAlignedPointerFromInternalField(0))
1323+
GetAlignedPointerFromInternalField(wrapObj, 0))
12781324
->Get();
12791325
}
12801326
}

bindings/profilers/wall.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class WallProfiler : public Nan::ObjectWrap {
157157
v8::ProfilerId StartInternal();
158158
template <typename ProfileBuilder>
159159
Result StopCore(bool restart, ProfileBuilder&& buildProfile);
160+
Result StopImpl(bool restart, v8::Local<v8::Value>& profile);
160161
Result StopAndCollectImpl(bool restart,
161162
v8::Local<v8::Function> callback,
162163
v8::Local<v8::Value>& result);
@@ -188,6 +189,7 @@ class WallProfiler : public Nan::ObjectWrap {
188189

189190
static NAN_METHOD(New);
190191
static NAN_METHOD(Start);
192+
static NAN_METHOD(Stop);
191193
static NAN_METHOD(StopAndCollect);
192194
static NAN_METHOD(V8ProfilerStuckEventLoopDetected);
193195
static NAN_METHOD(Dispose);

bindings/translate-heap-profile.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,30 @@ class HeapProfileTranslator : ProfileTranslator {
4141
#undef X
4242

4343
public:
44+
v8::Local<v8::Value> TranslateAllocationProfile(
45+
v8::AllocationProfile::Node* node) {
46+
v8::Local<v8::Array> children = NewArray(node->children.size());
47+
for (size_t i = 0; i < node->children.size(); i++) {
48+
Set(children, i, TranslateAllocationProfile(node->children[i]));
49+
}
50+
51+
v8::Local<v8::Array> allocations = NewArray(node->allocations.size());
52+
for (size_t i = 0; i < node->allocations.size(); i++) {
53+
auto alloc = node->allocations[i];
54+
Set(allocations,
55+
i,
56+
CreateAllocation(NewNumber(alloc.count), NewNumber(alloc.size)));
57+
}
58+
59+
return CreateNode(node->name,
60+
node->script_name,
61+
NewInteger(node->script_id),
62+
NewInteger(node->line_number),
63+
NewInteger(node->column_number),
64+
children,
65+
allocations);
66+
}
67+
4468
v8::Local<v8::Value> TranslateAllocationProfile(Node* node) {
4569
v8::Local<v8::Array> children = NewArray(node->children.size());
4670
for (size_t i = 0; i < node->children.size(); i++) {
@@ -118,6 +142,11 @@ std::shared_ptr<Node> TranslateAllocationProfileToCpp(
118142
return new_node;
119143
}
120144

145+
v8::Local<v8::Value> TranslateAllocationProfile(
146+
v8::AllocationProfile::Node* node) {
147+
return HeapProfileTranslator().TranslateAllocationProfile(node);
148+
}
149+
121150
v8::Local<v8::Value> TranslateAllocationProfile(Node* node) {
122151
return HeapProfileTranslator().TranslateAllocationProfile(node);
123152
}

0 commit comments

Comments
 (0)