@datadog/pprof
Advanced tools
Comparing version
import * as heapProfiler from './heap-profiler'; | ||
import * as timeProfiler from './time-profiler'; | ||
export { AllocationProfileNode, TimeProfileNode, ProfileNode } from './v8-types'; | ||
export { AllocationProfileNode, TimeProfileNode, ProfileNode, LabelSet, } from './v8-types'; | ||
export { encode, encodeSync } from './profile-encoder'; | ||
@@ -11,4 +11,8 @@ export { SourceMapper } from './sourcemapper/sourcemapper'; | ||
stop: typeof timeProfiler.stop; | ||
setLabels: typeof timeProfiler.setLabels; | ||
setContext: typeof timeProfiler.setContext; | ||
isStarted: typeof timeProfiler.isStarted; | ||
getState: typeof timeProfiler.getState; | ||
constants: { | ||
kSampleCount: any; | ||
}; | ||
}; | ||
@@ -15,0 +19,0 @@ export declare const heap: { |
@@ -57,4 +57,6 @@ "use strict"; | ||
stop: timeProfiler.stop, | ||
setLabels: timeProfiler.setLabels, | ||
setContext: timeProfiler.setContext, | ||
isStarted: timeProfiler.isStarted, | ||
getState: timeProfiler.getState, | ||
constants: timeProfiler.constants, | ||
}; | ||
@@ -61,0 +63,0 @@ exports.heap = { |
@@ -18,3 +18,3 @@ /** | ||
import { SourceMapper } from './sourcemapper/sourcemapper'; | ||
import { AllocationProfileNode, CpuProfile, TimeProfile } from './v8-types'; | ||
import { AllocationProfileNode, LabelSet, TimeProfile } from './v8-types'; | ||
/** | ||
@@ -27,12 +27,4 @@ * Converts v8 time profile into into a profile proto. | ||
*/ | ||
export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros: number, sourceMapper?: SourceMapper, recomputeSamplingInterval?: boolean): Profile; | ||
export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros: number, sourceMapper?: SourceMapper, recomputeSamplingInterval?: boolean, generateLabels?: (context: object) => LabelSet): Profile; | ||
/** | ||
* Converts cpu profile into into a profile proto. | ||
* (https://github.com/google/pprof/blob/master/proto/profile.proto) | ||
* | ||
* @param prof - profile to be converted. | ||
* @param intervalMicros - average time (microseconds) between samples. | ||
*/ | ||
export declare function serializeCpuProfile(prof: CpuProfile, intervalMicros: number, sourceMapper?: SourceMapper): Profile; | ||
/** | ||
* Converts v8 heap profile into into a profile proto. | ||
@@ -39,0 +31,0 @@ * (https://github.com/google/pprof/blob/master/proto/profile.proto) |
@@ -18,3 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serializeHeapProfile = exports.serializeCpuProfile = exports.serializeTimeProfile = void 0; | ||
exports.serializeHeapProfile = exports.serializeTimeProfile = void 0; | ||
const pprof_format_1 = require("pprof-format"); | ||
@@ -140,12 +140,2 @@ function isGeneratedLocation(location) { | ||
/** | ||
* @return value type for cpu samples (type:cpu, units:nanoseconds), and | ||
* adds strings used in this value type to the table. | ||
*/ | ||
function createCpuValueType(table) { | ||
return new pprof_format_1.ValueType({ | ||
type: table.dedup('cpu'), | ||
unit: table.dedup('nanoseconds'), | ||
}); | ||
} | ||
/** | ||
* @return value type for object counts (type:objects, units:count), and | ||
@@ -181,3 +171,3 @@ * adds strings used in this value type to the table. | ||
*/ | ||
function serializeTimeProfile(prof, intervalMicros, sourceMapper, recomputeSamplingInterval = false) { | ||
function serializeTimeProfile(prof, intervalMicros, sourceMapper, recomputeSamplingInterval = false, generateLabels) { | ||
// If requested, recompute sampling interval from profile duration and total number of hits, | ||
@@ -192,4 +182,3 @@ // since profile duration should be #hits x interval. | ||
if (totalHitCount > 0) { | ||
intervalMicros = Math.min(Math.max(Math.floor((prof.endTime - prof.startTime) / | ||
computeTotalHitCount(prof.topDownRoot)), intervalMicros), 2 * intervalMicros); | ||
intervalMicros = Math.min(Math.max(Math.floor((prof.endTime - prof.startTime) / totalHitCount), intervalMicros), 2 * intervalMicros); | ||
} | ||
@@ -200,8 +189,9 @@ } | ||
let unlabelledHits = entry.node.hitCount; | ||
for (const labelSet of entry.node.labelSets || []) { | ||
if (Object.keys(labelSet).length > 0) { | ||
for (const context of entry.node.contexts || []) { | ||
const labels = generateLabels ? generateLabels(context) : context; | ||
if (Object.keys(labels).length > 0) { | ||
const sample = new pprof_format_1.Sample({ | ||
locationId: entry.stack, | ||
value: [1, intervalNanos], | ||
label: buildLabels(labelSet, stringTable), | ||
label: buildLabels(labels, stringTable), | ||
}); | ||
@@ -251,43 +241,2 @@ samples.push(sample); | ||
/** | ||
* Converts cpu profile into into a profile proto. | ||
* (https://github.com/google/pprof/blob/master/proto/profile.proto) | ||
* | ||
* @param prof - profile to be converted. | ||
* @param intervalMicros - average time (microseconds) between samples. | ||
*/ | ||
function serializeCpuProfile(prof, intervalMicros, sourceMapper) { | ||
const intervalNanos = intervalMicros * 1000; | ||
const appendCpuEntryToSamples = (entry, samples) => { | ||
for (const labelCpu of entry.node.labelSets) { | ||
const sample = new pprof_format_1.Sample({ | ||
locationId: entry.stack, | ||
value: [1, labelCpu.cpuTime], | ||
label: buildLabels(labelCpu.labels, stringTable), | ||
}); | ||
samples.push(sample); | ||
} | ||
if (entry.node.hitCount > 0) { | ||
const sample = new pprof_format_1.Sample({ | ||
locationId: entry.stack, | ||
value: [entry.node.hitCount, entry.node.cpuTime], | ||
}); | ||
samples.push(sample); | ||
} | ||
}; | ||
const stringTable = new pprof_format_1.StringTable(); | ||
const sampleValueType = createSampleCountValueType(stringTable); | ||
// const wallValueType = createTimeValueType(stringTable); | ||
const cpuValueType = createCpuValueType(stringTable); | ||
const profile = { | ||
sampleType: [sampleValueType, cpuValueType /*, wallValueType*/], | ||
timeNanos: Date.now() * 1000 * 1000, | ||
durationNanos: prof.endTime - prof.startTime, | ||
periodType: cpuValueType, | ||
period: intervalNanos, | ||
}; | ||
serialize(profile, prof.topDownRoot, appendCpuEntryToSamples, stringTable, undefined, sourceMapper); | ||
return new pprof_format_1.Profile(profile); | ||
} | ||
exports.serializeCpuProfile = serializeCpuProfile; | ||
/** | ||
* Converts v8 heap profile into into a profile proto. | ||
@@ -294,0 +243,0 @@ * (https://github.com/google/pprof/blob/master/proto/profile.proto) |
export declare const TimeProfiler: any; | ||
export declare const constants: any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TimeProfiler = void 0; | ||
exports.constants = exports.TimeProfiler = void 0; | ||
/** | ||
@@ -23,2 +23,3 @@ * Copyright 2018 Google Inc. All Rights Reserved. | ||
exports.TimeProfiler = profiler.TimeProfiler; | ||
exports.constants = profiler.constants; | ||
//# sourceMappingURL=time-profiler-bindings.js.map |
@@ -33,9 +33,13 @@ /** | ||
lineNumbers?: boolean; | ||
customLabels?: boolean; | ||
withContexts?: boolean; | ||
} | ||
export declare function profile({ intervalMicros, durationMillis, sourceMapper, lineNumbers, customLabels, }: TimeProfilerOptions): Promise<import("pprof-format").Profile>; | ||
export declare function start({ intervalMicros, durationMillis, sourceMapper, lineNumbers, customLabels, }: TimeProfilerOptions): void; | ||
export declare function stop(restart?: boolean): import("pprof-format").Profile; | ||
export declare function setLabels(labels?: LabelSet): void; | ||
export declare function profile({ intervalMicros, durationMillis, sourceMapper, lineNumbers, withContexts, }: TimeProfilerOptions): Promise<import("pprof-format").Profile>; | ||
export declare function start({ intervalMicros, durationMillis, sourceMapper, lineNumbers, withContexts, }: TimeProfilerOptions): void; | ||
export declare function stop(restart?: boolean, generateLabels?: (context: object) => LabelSet): import("pprof-format").Profile; | ||
export declare function getState(): any; | ||
export declare function setContext(context?: object): void; | ||
export declare function isStarted(): boolean; | ||
export {}; | ||
export declare const constants: { | ||
kSampleCount: any; | ||
}; | ||
export { LabelSet }; |
@@ -21,6 +21,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isStarted = exports.setLabels = exports.stop = exports.start = exports.profile = void 0; | ||
exports.constants = exports.isStarted = exports.setContext = exports.getState = exports.stop = exports.start = exports.profile = void 0; | ||
const delay_1 = __importDefault(require("delay")); | ||
const profile_serializer_1 = require("./profile-serializer"); | ||
const time_profiler_bindings_1 = require("./time-profiler-bindings"); | ||
const { kSampleCount } = time_profiler_bindings_1.constants; | ||
const DEFAULT_INTERVAL_MICROS = 1000; | ||
@@ -37,3 +38,3 @@ const DEFAULT_DURATION_MILLIS = 60000; | ||
}); | ||
async function profile({ intervalMicros = DEFAULT_INTERVAL_MICROS, durationMillis = DEFAULT_DURATION_MILLIS, sourceMapper, lineNumbers = false, customLabels = false, }) { | ||
async function profile({ intervalMicros = DEFAULT_INTERVAL_MICROS, durationMillis = DEFAULT_DURATION_MILLIS, sourceMapper, lineNumbers = false, withContexts = false, }) { | ||
start({ | ||
@@ -44,3 +45,3 @@ intervalMicros, | ||
lineNumbers, | ||
customLabels, | ||
withContexts, | ||
}); | ||
@@ -52,13 +53,13 @@ await (0, delay_1.default)(durationMillis); | ||
// Temporarily retained for backwards compatibility with older tracer | ||
function start({ intervalMicros = DEFAULT_INTERVAL_MICROS, durationMillis = DEFAULT_DURATION_MILLIS, sourceMapper, lineNumbers = false, customLabels = false, }) { | ||
function start({ intervalMicros = DEFAULT_INTERVAL_MICROS, durationMillis = DEFAULT_DURATION_MILLIS, sourceMapper, lineNumbers = false, withContexts = false, }) { | ||
if (gProfiler) { | ||
throw new Error('Wall profiler is already started'); | ||
} | ||
gProfiler = new time_profiler_bindings_1.TimeProfiler(intervalMicros, durationMillis * 1000, lineNumbers, customLabels); | ||
gProfiler.start(); | ||
gProfiler = new time_profiler_bindings_1.TimeProfiler(intervalMicros, durationMillis * 1000, lineNumbers, withContexts); | ||
gSourceMapper = sourceMapper; | ||
gIntervalMicros = intervalMicros; | ||
gProfiler.start(); | ||
} | ||
exports.start = start; | ||
function stop(restart = false) { | ||
function stop(restart = false, generateLabels) { | ||
if (!gProfiler) { | ||
@@ -68,3 +69,3 @@ throw new Error('Wall profiler is not started'); | ||
const profile = gProfiler.stop(restart); | ||
const serialized_profile = (0, profile_serializer_1.serializeTimeProfile)(profile, gIntervalMicros, gSourceMapper, true); | ||
const serialized_profile = (0, profile_serializer_1.serializeTimeProfile)(profile, gIntervalMicros, gSourceMapper, true, generateLabels); | ||
if (!restart) { | ||
@@ -77,9 +78,16 @@ gProfiler = undefined; | ||
exports.stop = stop; | ||
function setLabels(labels) { | ||
function getState() { | ||
if (!gProfiler) { | ||
throw new Error('Wall profiler is not started'); | ||
} | ||
gProfiler.labels = labels; | ||
return gProfiler.state; | ||
} | ||
exports.setLabels = setLabels; | ||
exports.getState = getState; | ||
function setContext(context) { | ||
if (!gProfiler) { | ||
throw new Error('Wall profiler is not started'); | ||
} | ||
gProfiler.context = context; | ||
} | ||
exports.setContext = setContext; | ||
function isStarted() { | ||
@@ -89,2 +97,3 @@ return !!gProfiler; | ||
exports.isStarted = isStarted; | ||
exports.constants = { kSampleCount }; | ||
//# sourceMappingURL=time-profiler.js.map |
@@ -33,3 +33,3 @@ /** | ||
hitCount: number; | ||
labelSets?: LabelSet[]; | ||
contexts?: object[]; | ||
} | ||
@@ -43,43 +43,4 @@ export interface AllocationProfileNode extends ProfileNode { | ||
} | ||
export interface InitialCpuProfile { | ||
/** Time in nanoseconds at which profile was stopped. */ | ||
endTime: number; | ||
samples: CpuProfileSample[]; | ||
/** Time in nanoseconds at which profile was started. */ | ||
startTime: number; | ||
} | ||
export interface CpuProfile { | ||
/** Time in nanoseconds at which profile was stopped. */ | ||
endTime: number; | ||
topDownRoot: CpuProfileNode; | ||
/** Time in nanoseconds at which profile was started. */ | ||
startTime: number; | ||
} | ||
export interface LabelSet { | ||
[key: string]: string | number; | ||
} | ||
export interface LabelsCpu { | ||
labels: LabelSet; | ||
cpuTime: number; | ||
} | ||
export interface CpuProfileNode extends ProfileNode { | ||
hitCount: number; | ||
cpuTime: number; | ||
labelSets: LabelsCpu[]; | ||
} | ||
export interface CpuProfileSample { | ||
labels: LabelSet; | ||
locations: CodeEvent[]; | ||
cpuTime: number; | ||
} | ||
export interface CodeEvent { | ||
address: number; | ||
previousAddress?: number; | ||
size: number; | ||
comment?: string; | ||
functionName?: string; | ||
scriptName?: string; | ||
scriptId: number; | ||
line: number; | ||
column: number; | ||
} |
{ | ||
"name": "@datadog/pprof", | ||
"version": "4.0.0-pre-b439913", | ||
"version": "4.0.0-pre-d444c12", | ||
"description": "pprof support for Node.js", | ||
@@ -5,0 +5,0 @@ "repository": "datadog/pprof-nodejs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10654301
1.04%1442
-5.07%