UNPKG

@oaklean/profiler-core

Version:

Part of the @oaklean suite. It provides all basic functions to work with the `.oak` file format. It allows parsing the `.oak` file format as well as tools for analyzing the measurement values. It also provides all necessary capabilities required for prec

64 lines (63 loc) 3.02 kB
import { NullableMappedPosition } from 'source-map'; import { CPUProfileSourceLocation } from './CPUProfile/CPUProfileSourceLocation'; import { ExternalResourceHelper } from './ExternalResourceHelper'; import { SourceMap } from '../model/SourceMap'; import { NodeModule } from '../model/NodeModule'; import { ProgramStructureTree } from '../model/ProgramStructureTree'; import { UnifiedPath } from '../system/UnifiedPath'; import { ResolvedSourceNodeLocation } from '../types'; type ResolveFunctionIdentifierResult = { sourceNodeLocation: ResolvedSourceNodeLocation; functionIdentifierPresentInOriginalFile: boolean; nodeModule: NodeModule | null; relativeNodeModulePath: UnifiedPath | null; }; /** * This helper resolves a function identifier from a CPU profile's source location. * It does so by requesting the executed code from the Node engine and parsing it. * If the requested code contains a source map, it attempts to resolve the original source location. * * Additionally, it checks whether the executed code is part of a Node module. * If so, it determines the associated Node module. */ export declare class ResolveFunctionIdentifierHelper { hideOriginalSourceFileNotExistErrors: boolean; private rootDir; private externalResourceHelper; private PSTperNodeScript; private PSTperOriginalFile; private functionIdentifierCache; private _nodeModulePerFileCache; constructor(rootDir: UnifiedPath, externalResourceHelper: ExternalResourceHelper); /** * Adds a caching layer to the NodeModuleUtils.nodeModuleFromFilePath function */ private nodeModuleFromFilePath; resolveFunctionIdentifier(sourceLocation: CPUProfileSourceLocation): Promise<ResolveFunctionIdentifierResult>; /** * Why does this function exists? * * Example source code: * 1 methodABC(title, highResolutionStopTime) { * 2 var _a, _b, _c; * 3 return __awaiter(this, void 0, void 0, function* () { * 4 // do something * 5 }); * 6 } * * If a source mapping exists for every line except line 2 and 3 * and the function identifier is requested for line 2 or 3 the source map will return undefined. * * So the ProgramStructureTree node has to be resolved for that location. * This will return the parent function (methodABC) and its corresponding scope for line 2 and 3, * since the ProgramStructureTree treats the __awaiter function as part of the methodABC function. * * Then the sourcemap can be used to resolve the original source location of the function methodABC. * * If the sourcemap still returns undefined, * the requested source code location is not part of the original source code. * */ static resolveMappedLocationFromSourceMap(programStructureTreeNodeScript: ProgramStructureTree, sourceMap: SourceMap, lineNumber: number, columnNumber: number): Promise<NullableMappedPosition | undefined>; } export {};