Skip to content
Open
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
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"license": "Apache-2.0",
"dependencies": {
"node-gyp-build": "^4.8.4",
"pprof-format": "^2.3.2",
"pprof-format": "^2.4.0",
"source-map": "^0.8.0"
},
"devDependencies": {
Expand Down
49 changes: 29 additions & 20 deletions ts/src/heap-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import {
DEFAULT_COLUMN_NUMBERS,
serializeHeapProfile,
} from './profile-serializer';
import {NormalizedProfile, normalizeHeapProfile} from './profile-normalizer';
import {
CapturedProfile,
HeapProfileNormalizerOptions,
visitHeapProfile,
} from './profile-normalizer';
import {SourceMapper} from './sourcemapper/sourcemapper';
import {
AllocationProfileNode,
Expand Down Expand Up @@ -105,28 +109,33 @@ export function profile(
);
}

/** Options of a heap profile's normalization, set when it is captured. */
export type HeapProfileCaptureOptions = Pick<
HeapProfileNormalizerOptions,
'ignoreSamplesPath' | 'sourceMapper' | 'generateLabels'
>;

/**
* Collects a profile and returns it normalized into a format-neutral
* representation. Throws if heap profiler is not enabled.
* Like profile(), but captures the profile to be visited later, instead of
* serializing it as pprof: see {@link CapturedProfile}. Collecting the profile
* from V8, and in allocation mode restarting sampling, happens now.
* `generateLabels` runs when the profile is visited. Throws if heap profiler
* is not enabled.
*/
export function normalizedProfile(
ignoreSamplePath?: string,
sourceMapper?: SourceMapper,
generateLabels?: GenerateAllocationLabelsFunction,
): NormalizedProfile {
export function capture(
options: HeapProfileCaptureOptions = {},
): CapturedProfile {
return collectProfile(root => {
const startTimeNanos = BigInt(Date.now()) * 1_000_000n;
return normalizeHeapProfile(
addExternalMemoryNode(root, startedWithAllocations),
{
startTimeNanos,
intervalBytes: heapIntervalBytes,
ignoreSamplesPath: ignoreSamplePath,
sourceMapper,
generateLabels,
allocations: startedWithAllocations,
},
);
const profile = addExternalMemoryNode(root, startedWithAllocations);
const normalizerOptions: HeapProfileNormalizerOptions = {
...options,
startTimeNanos: BigInt(Date.now()) * 1_000_000n,
intervalBytes: heapIntervalBytes,
allocations: startedWithAllocations,
};
return {
visit: visitor => visitHeapProfile(profile, visitor, normalizerOptions),
};
});
}

Expand Down
34 changes: 22 additions & 12 deletions ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,38 @@ export {
TimeProfileNode,
ProfileNode,
LabelSet,
TimeProfile,
} from './v8-types';
export {
CapturedProfile,
Frame,
frameFunctionName,
HeapProfileNormalizerOptions,
NormalizedProfile,
NormalizedSample,
normalizeHeapProfile,
normalizeTimeProfile,
ProfileMetadata,
ProfileVisitor,
SampleLabel,
SampleLabelValue,
SampleType,
TimeProfileNormalizerOptions,
visitHeapProfile,
visitTimeProfile,
VisitResult,
} from './profile-normalizer';
export {
ColumnNumbers,
PprofProfileBuilder,
PprofSerializerOptions,
} from './profile-serializer';
export {
LinkExtractor,
OtelColumns,
OtelProfileOptions,
OtelProfilesBuilder,
OtelSerializerOptions,
ProfileAttribute,
SampleLink,
} from './otel-serializer';

export {HeapLimitExtensionSize} from './heap-profiler';
export {
HeapLimitExtensionSize,
HeapProfileCaptureOptions,
} from './heap-profiler';
export {TimeProfileCaptureOptions} from './time-profiler';

export {encode, encodeSync} from './profile-encoder';
export {SourceMapper} from './sourcemapper/sourcemapper';
Expand All @@ -56,7 +66,7 @@ export const time = {
profile: timeProfiler.profile,
start: timeProfiler.start,
stop: timeProfiler.stop,
stopNormalized: timeProfiler.stopNormalized,
stopAndCapture: timeProfiler.stopAndCapture,
profileV2: timeProfiler.profileV2,
getContext: timeProfiler.getContext,
setContext: timeProfiler.setContext,
Expand All @@ -74,7 +84,7 @@ export const heap = {
stop: heapProfiler.stop,
profile: heapProfiler.profile,
profileV2: heapProfiler.profileV2,
normalizedProfile: heapProfiler.normalizedProfile,
capture: heapProfiler.capture,
convertProfile: heapProfiler.convertProfile,
v8Profile: heapProfiler.v8Profile,
monitorOutOfMemory: heapProfiler.monitorOutOfMemory,
Expand Down
Loading
Loading