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 2.2.2 to 2.2.3

out/src/logger.d.ts

1

out/src/index.d.ts

@@ -7,2 +7,3 @@ import cpuProfiler from './cpu-profiler';

export { SourceMapper } from './sourcemapper/sourcemapper';
export { setLogger } from './logger';
export declare const CpuProfiler: typeof cpuProfiler;

@@ -9,0 +10,0 @@ export declare const time: {

4

out/src/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.heap = exports.time = exports.CpuProfiler = exports.SourceMapper = exports.encodeSync = exports.encode = void 0;
exports.heap = exports.time = exports.CpuProfiler = exports.setLogger = exports.SourceMapper = exports.encodeSync = exports.encode = void 0;
/**

@@ -29,2 +29,4 @@ * Copyright 2019 Google Inc. All Rights Reserved.

Object.defineProperty(exports, "SourceMapper", { enumerable: true, get: function () { return sourcemapper_1.SourceMapper; } });
var logger_1 = require("./logger");
Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return logger_1.setLogger; } });
exports.CpuProfiler = cpu_profiler_1.default;

@@ -31,0 +33,0 @@ exports.time = {

@@ -35,3 +35,4 @@ /**

infoMap: Map<string, MapInfoCompiled>;
static create(searchDirs: string[]): Promise<SourceMapper>;
debug: boolean;
static create(searchDirs: string[], debug?: boolean): Promise<SourceMapper>;
/**

@@ -45,3 +46,3 @@ * @param {Array.<string>} sourceMapPaths An array of paths to .map source map

*/
constructor();
constructor(debug?: boolean);
/**

@@ -48,0 +49,0 @@ * Used to get the information about the transpiled file from a given input

@@ -25,13 +25,4 @@ "use strict";

const path = require("path");
// Apparently the source-map module feature-detects the browser by checking
// if the fetch function exists. Because it now exists in Node.js v18, the
// source-map module thinks it's running in a browser and doesn't work.
const desc = Object.getOwnPropertyDescriptor(globalThis, 'fetch');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete globalThis.fetch;
const sourceMap = require("source-map");
if (desc) {
Object.defineProperty(globalThis, 'fetch', desc);
}
const logger_1 = require("../logger");
const pify = require('pify');

@@ -42,9 +33,4 @@ const pLimit = require('p-limit');

const MAP_EXT = '.map';
const debug = process.env.DD_PROFILING_DEBUG_SOURCE_MAPS
? (msg) => {
console.log(typeof msg === 'function' ? msg() : msg);
}
: () => { };
function error(msg) {
debug(`Error: ${msg}`);
logger_1.logger.debug(`Error: ${msg}`);
return new Error(msg);

@@ -59,3 +45,3 @@ }

*/
async function processSourceMap(infoMap, mapPath) {
async function processSourceMap(infoMap, mapPath, debug) {
// this handles the case when the path is undefined, null, or

@@ -91,19 +77,52 @@ // the empty string

}
/*
* If the source map file defines a "file" attribute, use it as
/* If the source map file defines a "file" attribute, use it as
* the output file where the path is relative to the directory
* containing the map file. Otherwise, use the name of the output
* file (with the .map extension removed) as the output file.
* With nextjs/webpack, when there are subdirectories in `pages` directory,
* the generated source maps do not reference correctly the generated files
* in their `file` property.
* For example if the generated file / source maps have paths:
* <root>/pages/sub/foo.js(.map)
* foo.js.map will have ../pages/sub/foo.js as `file` property instead of
* ../../pages/sub/foo.js
* To workaround this, check first if file referenced in `file` property
* exists and if it does not, check if generated file exists alongside the
* source map file.
*/
const dir = path.dirname(mapPath);
const generatedBase = consumer.file
? consumer.file
: path.basename(mapPath, MAP_EXT);
const generatedPath = path.resolve(dir, generatedBase);
infoMap.set(generatedPath, { mapFileDir: dir, mapConsumer: consumer });
debug(`Loaded source map for ${generatedPath} => ${mapPath}`);
const generatedPathCandidates = [];
if (consumer.file) {
generatedPathCandidates.push(path.resolve(dir, consumer.file));
}
const samePath = path.resolve(dir, path.basename(mapPath, MAP_EXT));
if (generatedPathCandidates.length === 0 ||
generatedPathCandidates[0] !== samePath) {
generatedPathCandidates.push(samePath);
}
for (const generatedPath of generatedPathCandidates) {
try {
await fs.promises.access(generatedPath, fs.constants.F_OK);
infoMap.set(generatedPath, { mapFileDir: dir, mapConsumer: consumer });
if (debug) {
logger_1.logger.debug(`Loaded source map for ${generatedPath} => ${mapPath}`);
}
return;
}
catch (err) {
if (debug) {
logger_1.logger.debug(`Generated path ${generatedPath} does not exist`);
}
}
}
if (debug) {
logger_1.logger.debug(`Unable to find generated file for ${mapPath}`);
}
}
class SourceMapper {
static async create(searchDirs) {
debug(() => `Looking for source map files in dirs: [${searchDirs.join(', ')}]`);
static async create(searchDirs, debug = false) {
if (debug) {
logger_1.logger.debug(`Looking for source map files in dirs: [${searchDirs.join(', ')}]`);
}
const mapFiles = [];

@@ -121,4 +140,6 @@ for (const dir of searchDirs) {

}
debug(() => `Found source map files: [${mapFiles.join(', ')}]`);
return createFromMapFiles(mapFiles);
if (debug) {
logger_1.logger.debug(`Found source map files: [${mapFiles.join(', ')}]`);
}
return createFromMapFiles(mapFiles, debug);
}

@@ -133,4 +154,5 @@ /**

*/
constructor() {
constructor(debug = false) {
this.infoMap = new Map();
this.debug = debug;
}

@@ -193,3 +215,5 @@ /**

if (entry === null) {
debug(() => `Source map lookup failed: no map found for ${location.file} (normalized: ${inputPath})`);
if (this.debug) {
logger_1.logger.debug(`Source map lookup failed: no map found for ${location.file} (normalized: ${inputPath})`);
}
return location;

@@ -205,3 +229,5 @@ }

if (pos.source === null) {
debug(() => `Source map lookup failed for ${location.name}(${location.file}:${location.line}:${location.column})`);
if (this.debug) {
logger_1.logger.debug(`Source map lookup failed for ${location.name}(${location.file}:${location.line}:${location.column})`);
}
return location;

@@ -215,3 +241,5 @@ }

};
debug(() => `Source map lookup succeeded for ${location.name}(${location.file}:${location.line}:${location.column}) => ${loc.name}(${loc.file}:${loc.line}:${loc.column})`);
if (this.debug) {
logger_1.logger.debug(`Source map lookup succeeded for ${location.name}(${location.file}:${location.line}:${location.column}) => ${loc.name}(${loc.file}:${loc.line}:${loc.column})`);
}
return loc;

@@ -221,6 +249,6 @@ }

exports.SourceMapper = SourceMapper;
async function createFromMapFiles(mapFiles) {
async function createFromMapFiles(mapFiles, debug) {
const limit = pLimit(CONCURRENCY);
const mapper = new SourceMapper();
const promises = mapFiles.map(mapPath => limit(() => processSourceMap(mapper.infoMap, mapPath)));
const mapper = new SourceMapper(debug);
const promises = mapFiles.map(mapPath => limit(() => processSourceMap(mapper.infoMap, mapPath, debug)));
try {

@@ -265,3 +293,3 @@ await Promise.all(promises);

else {
debug(() => `Non fatal error: ${error}`);
logger_1.logger.debug(() => `Non fatal error: ${error}`);
}

@@ -268,0 +296,0 @@ }

{
"name": "@datadog/pprof",
"version": "2.2.2",
"version": "2.2.3",
"description": "pprof support for Node.js",

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

"prepare": "npm run compile && npm run rebuild",
"pretest": "npm run compile && npm run rebuild"
"pretest": "npm run compile"
},

@@ -25,0 +25,0 @@ "author": {

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