Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,7 @@ jobs:
- name: Release notes
env:
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
VERSION: ${{ fromJson(steps.pkg.outputs.json).version }}
run: |
# The release notes are the body of the proposal PR, looked up by its
# head branch. This resolves even after the branch is deleted on merge.
notes="$RUNNER_TEMP/v$VERSION.md"
gh pr view "v$VERSION-proposal" --json body --jq .body > "$notes"
# v5.x is currently the only release line. Once a second one ships,
# --latest has to be decided per branch rather than hardcoded.
if gh release view "v$VERSION" > /dev/null 2>&1; then
gh release edit "v$VERSION" --title "$VERSION" -F "$notes" --latest
else
gh release create "v$VERSION" --target "${{ github.ref_name }}" --title "$VERSION" -F "$notes" --latest
fi
run: node scripts/release-notes.js

publish_dev:
needs: build
Expand Down
25 changes: 22 additions & 3 deletions bindings/profilers/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static void HeapProfilerCleanupHook(void* data) {
}
}

NAN_METHOD(HeapProfiler::StartSamplingHeapProfiler) {
static void StartSampling(const Nan::FunctionCallbackInfo<v8::Value>& info,
bool restart) {
auto isolate = info.GetIsolate();

// Register cleanup hook if not already registered for this isolate
Expand Down Expand Up @@ -89,15 +90,19 @@ NAN_METHOD(HeapProfiler::StartSamplingHeapProfiler) {
#if NODE_MAJOR_VERSION >= 26
if (allocations) {
flags = static_cast<v8::HeapProfiler::SamplingFlags>(
v8::HeapProfiler::kSamplingForceGC |
v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMajorGC |
v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMinorGC);
}
#endif

// Collection resets only V8 sampling. Keep the OOM callback, configuration,
// extension counters, and cleanup hook attached to the existing state.
if (restart) {
isolate->GetHeapProfiler()->StopSamplingHeapProfiler();
}
isolate->GetHeapProfiler()->StartSamplingHeapProfiler(
sample_interval, stack_depth, flags);
} else if (info.Length() == 0) {
} else if (info.Length() == 0 && !restart) {
isolate->GetHeapProfiler()->StartSamplingHeapProfiler();
} else {
return Nan::ThrowTypeError(
Expand All @@ -111,6 +116,18 @@ NAN_METHOD(HeapProfiler::StartSamplingHeapProfiler) {
state->allocations = allocations;
}

NAN_METHOD(HeapProfiler::StartSamplingHeapProfiler) {
StartSampling(info, false);
}

NAN_METHOD(HeapProfiler::RestartSamplingHeapProfiler) {
auto& state = PerIsolateData::For(info.GetIsolate())->GetHeapProfilerState();
if (!state) {
return Nan::ThrowError("Heap profiler is not enabled.");
}
StartSampling(info, true);
}

// Signature:
// stopSamplingHeapProfiler()
NAN_METHOD(HeapProfiler::StopSamplingHeapProfiler) {
Expand Down Expand Up @@ -212,6 +229,8 @@ NAN_MODULE_INIT(HeapProfiler::Init) {
v8::Local<v8::Object> heapProfiler = Nan::New<v8::Object>();
Nan::SetMethod(
heapProfiler, "startSamplingHeapProfiler", StartSamplingHeapProfiler);
Nan::SetMethod(
heapProfiler, "restartSamplingHeapProfiler", RestartSamplingHeapProfiler);
Nan::SetMethod(
heapProfiler, "stopSamplingHeapProfiler", StopSamplingHeapProfiler);
Nan::SetMethod(heapProfiler, "getAllocationProfile", GetAllocationProfile);
Expand Down
3 changes: 3 additions & 0 deletions bindings/profilers/heap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class HeapProfiler {
// stopSamplingHeapProfiler()
static NAN_METHOD(StopSamplingHeapProfiler);

// Restart V8 sampling while preserving OOM monitoring.
static NAN_METHOD(RestartSamplingHeapProfiler);

// Signature:
// getAllocationProfile(): AllocationProfileNode
static NAN_METHOD(GetAllocationProfile);
Expand Down
53 changes: 23 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datadog/pprof",
"version": "5.20.0",
"version": "5.20.1",
"description": "pprof support for Node.js",
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,20 +43,20 @@
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "26.6.3",
"@types/node": "26.6.6",
"@types/semver": "^7.8.0",
"@types/sinon": "^22.0.0",
"@types/sinon": "^22.0.2",
"@types/tmp": "^0.2.3",
"clang-format": "^1.8.0",
"codecov": "^3.8.3",
"deep-copy": "^1.4.2",
"eslint-plugin-n": "^18.4.0",
"eslint-plugin-n": "^18.5.0",
"gts": "^7.0.0",
"js-green-licenses": "^4.0.0",
"mocha": "^11.8.0",
"nan": "^2.29.0",
"nan": "^2.30.0",
"nyc": "^18.0.0",
"semver": "^7.8.5",
"semver": "^7.8.6",
"sinon": "^22.1.0",
"source-map-support": "^0.5.21",
"tmp": "0.2.7",
Expand Down
99 changes: 99 additions & 0 deletions scripts/release-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use strict'

// Usage: node scripts/release-notes.js [version] [--dry-run]
//
// Publishes the release proposal PR's body as the GitHub release notes for
// that version, expanding bare pull request references into their titles.
//
// The proposal PR is resolved by its head branch, which keeps working after
// the branch is deleted on merge. `--latest` is hardcoded because v5.x is the
// only release line; once a second one ships it has to be decided per branch.

const { execFileSync } = require('child_process')
const { writeFileSync } = require('fs')
const { join } = require('path')
const { tmpdir } = require('os')

const owner = 'DataDog'
const name = 'pprof-nodejs'
const repo = `${owner}/${name}`

const args = process.argv.slice(2)
const dryRun = args.includes('--dry-run')
const version = args.find(arg => !arg.startsWith('--')) || require('../package.json').version
const tag = `v${version}`

function gh (params) {
return execFileSync('gh', params, { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 }).trim()
}

function ghSucceeds (params) {
try {
gh(params)
return true
} catch {
return false
}
}

function readTitles (numbers) {
const titles = new Map()
if (numbers.length === 0) return titles

const fields = numbers
.map(number => `pr${number}: pullRequest(number: ${number}) { number title }`)
.join(' ')
const response = JSON.parse(gh([
'api', 'graphql', '-f',
`query=query { repository(owner: "${owner}", name: "${name}") { ${fields} } }`
]))

if (response.errors && response.errors.length > 0) {
throw new Error(`Pull request title lookup failed: ${response.errors[0].message}`)
}

for (const pullRequest of Object.values(response.data.repository)) {
if (pullRequest) titles.set(String(pullRequest.number), pullRequest.title)
}

return titles
}

// Only a list item that is nothing but a reference is expanded, so bodies that
// already spell out their titles are left exactly as the author wrote them.
const bareReference = /^([ \t]*[-*][ \t]+)#(\d+)[ \t]*$/gm

const body = gh(['pr', 'view', `${tag}-proposal`, '--repo', repo, '--json', 'body', '--jq', '.body'])
.replace(/\r\n/g, '\n')
const numbers = [...new Set([...body.matchAll(bareReference)].map(match => match[2]))]
const titles = readTitles(numbers)
const notes = body.replace(bareReference, (line, bullet, number) => {
const title = titles.get(number)
return title ? `${bullet}${title} (#${number})` : line
})

if (dryRun) {
console.log(notes)
process.exit(0)
}

const file = join(process.env.RUNNER_TEMP || tmpdir(), `${tag}.md`)
writeFileSync(file, notes)

const exists = ghSucceeds(['release', 'view', tag, '--repo', repo, '--json', 'tagName'])
const prerelease = version.includes('-')

// --verify-tag keeps a lagging tag push from silently creating the tag on the
// default branch instead of on the release commit.
const params = [
'release', exists ? 'edit' : 'create', tag,
'--repo', repo,
'--verify-tag',
'--title', version,
'--notes-file', file,
prerelease ? '--latest=false' : '--latest'
]

if (prerelease) params.push('--prerelease')

console.log(gh(params))
12 changes: 12 additions & 0 deletions ts/src/heap-profiler-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export function startSamplingHeapProfiler(
);
}

export function restartSamplingHeapProfiler(
heapIntervalBytes: number,
heapStackDepth: number,
allocations: boolean,
) {
profiler.heapProfiler.restartSamplingHeapProfiler(
heapIntervalBytes,
heapStackDepth,
allocations,
);
}

export function stopSamplingHeapProfiler() {
profiler.heapProfiler.stopSamplingHeapProfiler();
}
Expand Down
Loading
Loading