Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@datadog/pprof

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/pprof - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0-pre-929cc2a

2

out/src/cpu-profiler.d.ts

@@ -18,3 +18,3 @@ /**

export default class CpuProfiler extends NativeCpuProfiler {
profile(): import("../../proto/profile").perftools.profiles.IProfile | undefined;
profile(): import("pprof-format").Profile | undefined;
}

@@ -82,10 +82,15 @@ "use strict";

}
targetNode.cpuTime += sample.cpuTime;
targetNode.hitCount++;
if (sample.labels) {
targetNode.labelSets.push(sample.labels);
if (sample.labels && Object.keys(sample.labels).length > 0) {
targetNode.labelSets.push({
labels: sample.labels,
cpuTime: sample.cpuTime,
});
}
else {
targetNode.cpuTime += sample.cpuTime;
targetNode.hitCount++;
}
targetNode = timeProfile.topDownRoot;
}
const intervalMicros = 1000 / this.frequency;
const intervalMicros = 1000000 / this.frequency;
return (0, profile_serializer_1.serializeCpuProfile)(timeProfile, intervalMicros);

@@ -92,0 +97,0 @@ }

@@ -16,3 +16,3 @@ /**

*/
import { perftools } from '../../proto/profile';
import { Profile } from 'pprof-format';
import { SourceMapper } from './sourcemapper/sourcemapper';

@@ -28,3 +28,3 @@ import { AllocationProfileNode } from './v8-types';

*/
export declare function profile(ignoreSamplePath?: string, sourceMapper?: SourceMapper): perftools.profiles.IProfile;
export declare function profile(ignoreSamplePath?: string, sourceMapper?: SourceMapper): Profile;
/**

@@ -31,0 +31,0 @@ * Starts heap profiling. If heap profiling has already been started with

@@ -17,4 +17,4 @@ /**

/// <reference types="node" />
import { perftools } from '../../proto/profile';
export declare function encode(profile: perftools.profiles.IProfile): Promise<Buffer>;
export declare function encodeSync(profile: perftools.profiles.IProfile): Buffer;
import { Profile } from 'pprof-format';
export declare function encode(profile: Profile): Promise<Buffer>;
export declare function encodeSync(profile: Profile): Buffer;

@@ -21,14 +21,11 @@ "use strict";

const zlib_1 = require("zlib");
const profile_1 = require("../../proto/profile");
const gzipPromise = pify(zlib_1.gzip);
async function encode(profile) {
const buffer = profile_1.perftools.profiles.Profile.encode(profile).finish();
return gzipPromise(buffer);
return gzipPromise(profile.encode());
}
exports.encode = encode;
function encodeSync(profile) {
const buffer = profile_1.perftools.profiles.Profile.encode(profile).finish();
return (0, zlib_1.gzipSync)(buffer);
return (0, zlib_1.gzipSync)(profile.encode());
}
exports.encodeSync = encodeSync;
//# sourceMappingURL=profile-encoder.js.map

@@ -16,3 +16,3 @@ /**

*/
import { perftools } from '../../proto/profile';
import { Profile } from 'pprof-format';
import { SourceMapper } from './sourcemapper/sourcemapper';

@@ -27,3 +27,3 @@ import { AllocationProfileNode, CpuProfile, TimeProfile } from './v8-types';

*/
export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros: number, sourceMapper?: SourceMapper): perftools.profiles.IProfile;
export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros: number, sourceMapper?: SourceMapper, recomputeSamplingInterval?: boolean): Profile;
/**

@@ -36,3 +36,3 @@ * Converts cpu profile into into a profile proto.

*/
export declare function serializeCpuProfile(prof: CpuProfile, intervalMicros: number, sourceMapper?: SourceMapper): perftools.profiles.IProfile;
export declare function serializeCpuProfile(prof: CpuProfile, intervalMicros: number, sourceMapper?: SourceMapper): Profile;
/**

@@ -48,2 +48,2 @@ * Converts v8 heap profile into into a profile proto.

*/
export declare function serializeHeapProfile(prof: AllocationProfileNode, startTimeNanos: number, intervalBytes: number, ignoreSamplesPath?: string, sourceMapper?: SourceMapper): perftools.profiles.IProfile;
export declare function serializeHeapProfile(prof: AllocationProfileNode, startTimeNanos: number, intervalBytes: number, ignoreSamplesPath?: string, sourceMapper?: SourceMapper): Profile;

@@ -19,3 +19,3 @@ "use strict";

exports.serializeHeapProfile = exports.serializeCpuProfile = exports.serializeTimeProfile = void 0;
const profile_1 = require("../../proto/profile");
const pprof_format_1 = require("pprof-format");
function isGeneratedLocation(location) {

@@ -27,26 +27,2 @@ return (location.column !== undefined &&

/**
* Used to build string table and access strings and their ids within the table
* when serializing a profile.
*/
class StringTable {
constructor() {
this.strings = [];
this.stringsMap = new Map();
this.getIndexOrAdd('');
}
/**
* @return index of str within the table. Also adds str to string table if
* str is not in the table already.
*/
getIndexOrAdd(str) {
let idx = this.stringsMap.get(str);
if (idx !== undefined) {
return idx;
}
idx = this.strings.push(str) - 1;
this.stringsMap.set(str, idx);
return idx;
}
}
/**
* Takes v8 profile and populates sample, location, and function fields of

@@ -92,3 +68,3 @@ * profile.proto.

profile.function = functions;
profile.stringTable = stringTable.strings;
profile.stringTable = stringTable;
function getLocation(node, sourceMapper) {

@@ -115,3 +91,3 @@ let profLoc = {

const line = getLine(node.scriptId, profLoc.file, profLoc.name, profLoc.line);
const location = new profile_1.perftools.profiles.Location({ id, line: [line] });
const location = new pprof_format_1.Location({ id, line: [line] });
locations.push(location);

@@ -121,3 +97,3 @@ return location;

function getLine(scriptId, scriptName, name, line) {
return new profile_1.perftools.profiles.Line({
return new pprof_format_1.Line({
functionId: getFunction(scriptId, scriptName, name).id,

@@ -136,8 +112,8 @@ line,

functionIdMap.set(keyStr, id);
const nameId = stringTable.getIndexOrAdd(name || '(anonymous)');
const f = new profile_1.perftools.profiles.Function({
const nameId = stringTable.dedup(name || '(anonymous)');
const f = new pprof_format_1.Function({
id,
name: nameId,
systemName: nameId,
filename: stringTable.getIndexOrAdd(scriptName || ''),
filename: stringTable.dedup(scriptName || ''),
});

@@ -153,5 +129,5 @@ functions.push(f);

function createSampleCountValueType(table) {
return new profile_1.perftools.profiles.ValueType({
type: table.getIndexOrAdd('sample'),
unit: table.getIndexOrAdd('count'),
return new pprof_format_1.ValueType({
type: table.dedup('sample'),
unit: table.dedup('count'),
});

@@ -164,5 +140,5 @@ }

function createTimeValueType(table) {
return new profile_1.perftools.profiles.ValueType({
type: table.getIndexOrAdd('wall'),
unit: table.getIndexOrAdd('nanoseconds'),
return new pprof_format_1.ValueType({
type: table.dedup('wall'),
unit: table.dedup('nanoseconds'),
});

@@ -175,5 +151,5 @@ }

function createCpuValueType(table) {
return new profile_1.perftools.profiles.ValueType({
type: table.getIndexOrAdd('cpu'),
unit: table.getIndexOrAdd('nanoseconds'),
return new pprof_format_1.ValueType({
type: table.dedup('cpu'),
unit: table.dedup('nanoseconds'),
});

@@ -186,5 +162,5 @@ }

function createObjectCountValueType(table) {
return new profile_1.perftools.profiles.ValueType({
type: table.getIndexOrAdd('objects'),
unit: table.getIndexOrAdd('count'),
return new pprof_format_1.ValueType({
type: table.dedup('objects'),
unit: table.dedup('count'),
});

@@ -197,7 +173,11 @@ }

function createAllocationValueType(table) {
return new profile_1.perftools.profiles.ValueType({
type: table.getIndexOrAdd('space'),
unit: table.getIndexOrAdd('bytes'),
return new pprof_format_1.ValueType({
type: table.dedup('space'),
unit: table.dedup('bytes'),
});
}
function computeTotalHitCount(root) {
return (root.hitCount +
root.children.reduce((sum, node) => sum + computeTotalHitCount(node), 0));
}
/**

@@ -210,7 +190,17 @@ * Converts v8 time profile into into a profile proto.

*/
function serializeTimeProfile(prof, intervalMicros, sourceMapper) {
function serializeTimeProfile(prof, intervalMicros, sourceMapper, recomputeSamplingInterval = false) {
// If requested, recompute sampling interval it from profile duration and total number of hits,
// since profile duration should be #hits x interval
// Recomputing an average interval is more accurate, since in practice intervals between
// samples are larger than the requested sampling interval (eg. 12.5ms vs 10ms requested).
if (recomputeSamplingInterval) {
const totalHitCount = computeTotalHitCount(prof.topDownRoot);
if (totalHitCount > 0) {
intervalMicros = Math.floor((prof.endTime - prof.startTime) / computeTotalHitCount(prof.topDownRoot));
}
}
const intervalNanos = intervalMicros * 1000;
const appendTimeEntryToSamples = (entry, samples) => {
if (entry.node.hitCount > 0) {
const sample = new profile_1.perftools.profiles.Sample({
const sample = new pprof_format_1.Sample({
locationId: entry.stack,

@@ -222,3 +212,3 @@ value: [entry.node.hitCount, entry.node.hitCount * intervalNanos],

};
const stringTable = new StringTable();
const stringTable = new pprof_format_1.StringTable();
const sampleValueType = createSampleCountValueType(stringTable);

@@ -231,6 +221,6 @@ const timeValueType = createTimeValueType(stringTable);

periodType: timeValueType,
period: intervalMicros,
period: intervalNanos,
};
serialize(profile, prof.topDownRoot, appendTimeEntryToSamples, stringTable, undefined, sourceMapper);
return profile;
return new pprof_format_1.Profile(profile);
}

@@ -242,7 +232,7 @@ exports.serializeTimeProfile = serializeTimeProfile;

if (typeof value === 'number' || typeof value === 'string') {
const label = new profile_1.perftools.profiles.Label({
key: stringTable.getIndexOrAdd(key),
const label = new pprof_format_1.Label({
key: stringTable.dedup(key),
num: typeof value === 'number' ? value : undefined,
str: typeof value === 'string'
? stringTable.getIndexOrAdd(value)
? stringTable.dedup(value)
: undefined,

@@ -265,19 +255,14 @@ });

const appendCpuEntryToSamples = (entry, samples) => {
for (const labelSet of entry.node.labelSets) {
const sample = new profile_1.perftools.profiles.Sample({
for (const labelCpu of entry.node.labelSets) {
const sample = new pprof_format_1.Sample({
locationId: entry.stack,
value: [1, intervalNanos],
label: buildLabels(labelSet, stringTable),
value: [1, labelCpu.cpuTime],
label: buildLabels(labelCpu.labels, stringTable),
});
samples.push(sample);
}
const unknownEntryCount = entry.node.hitCount - entry.node.labelSets.length;
if (unknownEntryCount > 0) {
const sample = new profile_1.perftools.profiles.Sample({
if (entry.node.hitCount > 0) {
const sample = new pprof_format_1.Sample({
locationId: entry.stack,
value: [
unknownEntryCount,
entry.node.cpuTime,
// unknownEntryCount * intervalNanos,
],
value: [entry.node.hitCount, entry.node.cpuTime],
});

@@ -287,3 +272,3 @@ samples.push(sample);

};
const stringTable = new StringTable();
const stringTable = new pprof_format_1.StringTable();
const sampleValueType = createSampleCountValueType(stringTable);

@@ -297,6 +282,6 @@ // const wallValueType = createTimeValueType(stringTable);

periodType: cpuValueType,
period: intervalMicros,
period: intervalNanos,
};
serialize(profile, prof.topDownRoot, appendCpuEntryToSamples, stringTable, undefined, sourceMapper);
return profile;
return new pprof_format_1.Profile(profile);
}

@@ -318,3 +303,3 @@ exports.serializeCpuProfile = serializeCpuProfile;

for (const alloc of entry.node.allocations) {
const sample = new profile_1.perftools.profiles.Sample({
const sample = new pprof_format_1.Sample({
locationId: entry.stack,

@@ -328,3 +313,3 @@ value: [alloc.count, alloc.sizeBytes * alloc.count],

};
const stringTable = new StringTable();
const stringTable = new pprof_format_1.StringTable();
const sampleValueType = createObjectCountValueType(stringTable);

@@ -339,5 +324,5 @@ const allocationValueType = createAllocationValueType(stringTable);

serialize(profile, prof, appendHeapEntryToSamples, stringTable, ignoreSamplesPath, sourceMapper);
return profile;
return new pprof_format_1.Profile(profile);
}
exports.serializeHeapProfile = serializeHeapProfile;
//# sourceMappingURL=profile-serializer.js.map

@@ -36,3 +36,2 @@ "use strict";

}
const scanner = require("../../third_party/cloud-debug-nodejs/src/agent/io/scanner");
const pify = require('pify');

@@ -207,7 +206,43 @@ const pLimit = require('p-limit');

}
function isErrnoException(e) {
return e instanceof Error && 'code' in e;
}
function isNonFatalError(error) {
const nonFatalErrors = ['ENOENT', 'EPERM', 'EACCES', 'ELOOP'];
return (isErrnoException(error) && error.code && nonFatalErrors.includes(error.code));
}
async function* walk(dir,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fileFilter = (filename) => true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
directoryFilter = (root, dirname) => true) {
async function* walkRecursive(dir) {
try {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory() && directoryFilter(dir, d.name)) {
yield* walkRecursive(entry);
}
else if (d.isFile() && fileFilter(d.name)) {
// check that the file is readable
await fs.promises.access(entry, fs.constants.R_OK);
yield entry;
}
}
}
catch (error) {
if (!isNonFatalError(error)) {
throw error;
}
}
}
yield* walkRecursive(dir);
}
async function getMapFiles(baseDir) {
const fileStats = await scanner.scan(false, baseDir, /.js.map$/);
const mapFiles = fileStats.selectFiles(/.js.map$/, process.cwd());
const mapFiles = [];
for await (const entry of walk(baseDir, filename => filename.endsWith('.js.map'), (root, dirname) => root !== '/proc' && dirname !== '.git' && dirname !== 'node_modules')) {
mapFiles.push(path.relative(baseDir, entry));
}
return mapFiles;
}
//# sourceMappingURL=sourcemapper.js.map

@@ -34,4 +34,4 @@ /**

}
export declare function profile(options: TimeProfilerOptions): Promise<import("../../proto/profile").perftools.profiles.IProfile>;
export declare function start(intervalMicros?: Microseconds, name?: string, sourceMapper?: SourceMapper, lineNumbers?: boolean): (restart?: boolean) => import("../../proto/profile").perftools.profiles.IProfile;
export declare function profile(options: TimeProfilerOptions): Promise<import("pprof-format").Profile>;
export declare function start(intervalMicros?: Microseconds, name?: string, sourceMapper?: SourceMapper, lineNumbers?: boolean): (restart?: boolean) => import("pprof-format").Profile;
export {};

@@ -52,3 +52,3 @@ "use strict";

}
return (0, profile_serializer_1.serializeTimeProfile)(result, intervalMicros, sourceMapper);
return (0, profile_serializer_1.serializeTimeProfile)(result, intervalMicros, sourceMapper, true);
}

@@ -69,3 +69,3 @@ // For Node.js v16+, we want to start the next profile before we stop the

profiler.dispose();
return (0, profile_serializer_1.serializeTimeProfile)(result, intervalMicros, sourceMapper);
return (0, profile_serializer_1.serializeTimeProfile)(result, intervalMicros, sourceMapper, true);
}

@@ -72,0 +72,0 @@ }

@@ -58,6 +58,10 @@ /**

}
export interface LabelsCpu {
labels: LabelSet;
cpuTime: number;
}
export interface CpuProfileNode extends ProfileNode {
hitCount: number;
cpuTime: number;
labelSets: LabelSet[];
labelSets: LabelsCpu[];
}

@@ -64,0 +68,0 @@ export interface CpuProfileSample {

{
"name": "@datadog/pprof",
"version": "1.1.1",
"version": "2.0.0-pre-929cc2a",
"description": "pprof support for Node.js",

@@ -21,5 +21,3 @@ "repository": "datadog/pprof-nodejs",

"prepare": "npm run compile",
"pretest": "npm run compile && npm run rebuild",
"proto": "npm run proto:profile",
"proto:profile": "mkdir -p proto && npx --yes pbjs -t static-module -w commonjs -o proto/profile.js third_party/proto/profile.proto && pbts -o proto/profile.d.ts proto/profile.js"
"pretest": "npm run compile && npm run rebuild"
},

@@ -32,7 +30,6 @@ "author": {

"delay": "^5.0.0",
"findit2": "^2.2.3",
"node-gyp-build": "^3.9.0",
"p-limit": "^3.1.0",
"pify": "^5.0.0",
"protobufjs": "^7.0.0",
"pprof-format": "^2.0.5",
"source-map": "^0.7.3",

@@ -61,3 +58,3 @@ "split": "^1.0.1"

"gts": "^3.0.0",
"js-green-licenses": "^3.0.0",
"js-green-licenses": "^4.0.0",
"linkinator": "^4.0.2",

@@ -64,0 +61,0 @@ "mkdirp": "^1.0.4",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc