@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
79 lines (78 loc) • 4.06 kB
TypeScript
import { CallRelationTracker } from './CallRelationTracker';
import { State } from './types/state';
import { Transition, TransitionResult } from './types/transition';
import { StackFrame, AwaiterStack } from './types/stack';
import { CPUNode } from '../CPUProfile/CPUNode';
import { ResolveFunctionIdentifierHelper } from '../ResolveFunctionIdentifierHelper';
import { UnifiedPath } from '../../system';
import { ProjectReport } from '../../model/ProjectReport';
import { MetricsDataCollection } from '../../model/interfaces/MetricsDataCollection';
import { ICpuProfileRaw } from '../../../lib/vscode-js-profile-core/src/cpu/types';
import { CPUProfileSourceLocation } from '../CPUProfile';
/**
* This state machine is responsible to track the current state of the CPU profile insertion.
* It handles transitions between different states based on the source location of the CPU nodes.
* The states include:
* - Project: when the current function belongs to the project source code.
* - Module: when the current function belongs to an external module.
* - LangInternal: when the current function is a language internal function (e.g., V8 internals).
* - Wasm: when the current function is a WebAssembly function.
*
* The state machine uses the ResolveFunctionIdentifierHelper to determine the appropriate state
* based on the source location of the CPU nodes.
* It also tracks call relations to avoid double counting of sensor values for already recorded calls.
*
* The state machine maintains an awaiter stack to correctly account for async function calls and their awaiters.
* This ensures that sensor values are accurately attributed to the correct source nodes in async scenarios.
*
*/
export declare class InsertCPUProfileStateMachine {
projectReport: ProjectReport;
callRelationTracker: CallRelationTracker;
awaiterStack: AwaiterStack;
debug: {
transitions: boolean;
states: boolean;
compensations: boolean;
} | undefined;
constructor(reportToApply: ProjectReport);
/**
* Inserts a CPU profile into the state machine, updating the project report accordingly.
*
* @param resolveFunctionIdentifierHelper the helper to resolve function identifiers
* @param profile the raw cpu profile to insert
* @param metricsDataCollection optional metrics data collection to enrich the cpu profile with energy values
*/
insertCPUProfile(rootDir: UnifiedPath, resolveFunctionIdentifierHelper: ResolveFunctionIdentifierHelper, profile: ICpuProfileRaw, metricsDataCollection?: MetricsDataCollection): Promise<void>;
/**
* Inserts CPU nodes into the state machine, updating the project report accordingly.
*
* @param rootNode the root node of the cpu model
* @param resolveFunctionIdentifierHelper the helper to resolve function identifiers
*/
insertCPUNodes(rootNode: CPUNode, resolveFunctionIdentifierHelper: ResolveFunctionIdentifierHelper): Promise<void>;
/**
* determine the transition based on the current state and the cpu node's source location
*
* @param currentState the current state of the state machine
*
* @param sourceLocation the source location of the incoming cpu node
* @returns the transition to the next state
*/
static getTransition(currentState: State, sourceLocation: CPUProfileSourceLocation, resolveFunctionIdentifierHelper: ResolveFunctionIdentifierHelper): Promise<Transition>;
/**
* performs the state transition and accounting based on the current stack frame and the transition
*
* @param currentStackFrame
* @param transition
* @returns the result of the transition including the next state and accounting info
*/
applyTransition(currentStackFrame: StackFrame, transition: Transition): Promise<TransitionResult>;
/**
* applies headless accounting if necessary
*
* @param currentStackFrame
* @param transition
*/
applyHeadless(currentStackFrame: StackFrame, transition: Transition): void;
}