Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!nodeVersionOkay(process.version)) {
throw new Error(
`Could not start profiler: node version ${process.version}` +
` does not satisfies "${pjson.engines.node}"` +
'\nSee https://github.com/GoogleCloudPlatform/cloud-profiler-nodejs#prerequisites' +
' for details.'
);
}
let profilerConfig: ProfilerConfig = initConfigLocal(config);
// Start the heap profiler if profiler config does not indicate heap profiling
// is disabled. This must be done before any asynchronous calls are made so
// all memory allocations made after start() is called can be captured.
if (!profilerConfig.disableHeap) {
heapProfiler.start(
profilerConfig.heapIntervalBytes,
profilerConfig.heapMaxStackDepth
);
}
profilerConfig = await initConfigMetadata(profilerConfig);
return new Profiler(profilerConfig);
}
async writeHeapProfile(prof: RequestProfile): Promise {
if (this.config.disableHeap) {
throw Error('Cannot collect heap profile, heap profiler not enabled.');
}
const p = heapProfiler.profile(
this.config.ignoreHeapSamplesPath,
this.sourceMapper
);
prof.profileBytes = await profileBytes(p);
return prof;
}
}
throw Error('Cannot collect time profile, duration is undefined.');
}
const durationMillis = parseDuration(prof.duration);
if (!durationMillis) {
throw Error(
`Cannot collect time profile, duration "${prof.duration}" cannot` +
` be parsed.`
);
}
const options = {
durationMillis,
intervalMicros: this.config.timeIntervalMicros,
sourceMapper: this.sourceMapper,
};
const p = await timeProfiler.profile(options);
prof.profileBytes = await profileBytes(p);
return prof;
}
async start(): Promise {
if (!this.config.disableSourceMaps) {
try {
this.sourceMapper = await SourceMapper.create(
this.config.sourceMapSearchPath
);
} catch (err) {
this.logger.error(
`Failed to initialize SourceMapper. Source map support has been disabled: ${err}`
);
this.config.disableSourceMaps = true;
}
}
this.runLoop();
}