From f5ab171fd6e0745e3093fe18070efd679f36e703 Mon Sep 17 00:00:00 2001 From: Liang Gong Date: Fri, 2 Feb 2024 16:09:22 -0800 Subject: [PATCH] feat(api): support configuring console mode in APIs (#110) Summary: Support setting the console output mode in MemLab programming API: ``` const {findLeaks, takeSnapshots} = require('memlab/api'); (async function () { const scenario = { url: () => 'https://www.facebook.com', }; const result = await takeSnapshots({scenario, consoleMode: 'SILENT'}); const leaks = findLeaks(result, {consoleMode: 'CONTINUOUS_TEST'}); })(); ``` Differential Revision: D53361876 fbshipit-source-id: 10f8b501a1253173571da49f106c0819ca66e898 --- packages/api/src/API.ts | 60 ++++++--- packages/api/src/index.ts | 1 + packages/api/src/state/APIStateManager.ts | 47 +++++++ packages/api/src/state/ConsoleModeManager.ts | 115 ++++++++++++++++++ .../api/src/state/PuppeteerConfigManager.ts | 31 +++++ packages/core/src/lib/Config.ts | 24 +--- packages/core/src/lib/Types.ts | 23 ++++ website/docs/api/enums/_category_.yml | 2 + website/docs/api/enums/api_src.ConsoleMode.md | 45 +++++++ .../api/interfaces/core_src.IBrowserInfo.md | 6 +- .../docs/api/interfaces/core_src.IHeapEdge.md | 18 +-- .../api/interfaces/core_src.IHeapEdges.md | 6 +- .../api/interfaces/core_src.IHeapLocation.md | 12 +- .../docs/api/interfaces/core_src.IHeapNode.md | 64 +++++----- .../api/interfaces/core_src.IHeapNodes.md | 6 +- .../api/interfaces/core_src.IHeapSnapshot.md | 18 +-- .../interfaces/core_src.IHeapStringNode.md | 66 +++++----- .../api/interfaces/core_src.ILeakFilter.md | 6 +- .../docs/api/interfaces/core_src.IScenario.md | 22 ++-- website/docs/api/modules/api_src.md | 38 +++--- website/docs/api/modules/core_src.md | 22 ++-- 21 files changed, 454 insertions(+), 178 deletions(-) create mode 100644 packages/api/src/state/APIStateManager.ts create mode 100644 packages/api/src/state/ConsoleModeManager.ts create mode 100644 packages/api/src/state/PuppeteerConfigManager.ts create mode 100644 website/docs/api/enums/_category_.yml create mode 100644 website/docs/api/enums/api_src.ConsoleMode.md diff --git a/packages/api/src/API.ts b/packages/api/src/API.ts index e8995e388..bb71dad5f 100644 --- a/packages/api/src/API.ts +++ b/packages/api/src/API.ts @@ -18,6 +18,7 @@ import type { Nullable, Optional, } from '@memlab/core'; +import {ConsoleMode} from './state/ConsoleModeManager'; import { analysis, @@ -38,6 +39,7 @@ import {BaseAnalysis} from '@memlab/heap-analysis'; import APIUtils from './lib/APIUtils'; import BrowserInteractionResultReader from './result-reader/BrowserInteractionResultReader'; import BaseResultReader from './result-reader/BaseResultReader'; +import stateManager from './state/APIStateManager'; /** * Options for configuring browser interaction run, all fields are optional @@ -82,6 +84,11 @@ export type RunOptions = { * skip warmup page load for the target web app */ skipWarmup?: boolean; + /** + * specifying the terminal output mode, default is `default`. + * For more details. please check out {@link ConsoleMode} + */ + consoleMode?: ConsoleMode; }; /** @@ -134,15 +141,16 @@ export async function warmupAndTakeSnapshots( options: RunOptions = {}, ): Promise { const config = getConfigFromRunOptions(options); - config.externalCookiesFile = options.cookiesFile; - config.scenario = options.scenario; + const state = stateManager.getAndUpdateState(config, options); const testPlanner = new TestPlanner({config}); const {evalInBrowserAfterInitLoad} = options; if (!options.skipWarmup) { await warmup({testPlanner, config, evalInBrowserAfterInitLoad}); } await testInBrowser({testPlanner, config, evalInBrowserAfterInitLoad}); - return BrowserInteractionResultReader.from(config.workDir); + const ret = BrowserInteractionResultReader.from(config.workDir); + stateManager.restoreState(config, state); + return ret; } /** @@ -166,18 +174,18 @@ export async function warmupAndTakeSnapshots( * })(); * ``` */ -export async function run(runOptions: RunOptions = {}): Promise { - const config = getConfigFromRunOptions(runOptions); - config.externalCookiesFile = runOptions.cookiesFile; - config.scenario = runOptions.scenario; +export async function run(options: RunOptions = {}): Promise { + const config = getConfigFromRunOptions(options); + const state = stateManager.getAndUpdateState(config, options); const testPlanner = new TestPlanner({config}); - const {evalInBrowserAfterInitLoad} = runOptions; - if (!runOptions.skipWarmup) { + const {evalInBrowserAfterInitLoad} = options; + if (!options.skipWarmup) { await warmup({testPlanner, config, evalInBrowserAfterInitLoad}); } await testInBrowser({testPlanner, config, evalInBrowserAfterInitLoad}); const runResult = BrowserInteractionResultReader.from(config.workDir); const leaks = await findLeaks(runResult); + stateManager.restoreState(config, state); return {leaks, runResult}; } @@ -203,12 +211,13 @@ export async function takeSnapshots( options: RunOptions = {}, ): Promise { const config = getConfigFromRunOptions(options); - config.externalCookiesFile = options.cookiesFile; - config.scenario = options.scenario; + const state = stateManager.getAndUpdateState(config, options); const testPlanner = new TestPlanner(); const {evalInBrowserAfterInitLoad} = options; await testInBrowser({testPlanner, config, evalInBrowserAfterInitLoad}); - return BrowserInteractionResultReader.from(config.workDir); + const ret = BrowserInteractionResultReader.from(config.workDir); + stateManager.restoreState(config, state); + return ret; } /** @@ -216,6 +225,9 @@ export async function takeSnapshots( * This is equivalent to `memlab find-leaks` in CLI. * * @param runResult return value of a browser interaction run + * @param options configure memory leak detection run + * @param options.consoleMode specify the terminal output + * mode (see {@link ConsoleMode}) * @returns leak traces detected and clustered from the browser interaction * * **Examples**: * ```javascript @@ -225,18 +237,22 @@ export async function takeSnapshots( * const scenario = { * url: () => 'https://www.facebook.com', * }; - * const result = await takeSnapshots({scenario}); - * const leaks = findLeaks(result); + * const result = await takeSnapshots({scenario, consoleMode: 'SILENT'}); + * const leaks = findLeaks(result, {consoleMode: 'CONTINUOUS_TEST'}); * })(); * ``` */ export async function findLeaks( runResult: BaseResultReader, + options: {consoleMode?: ConsoleMode} = {}, ): Promise { + const state = stateManager.getAndUpdateState(defaultConfig, options); const workDir = runResult.getRootDirectory(); fileManager.initDirs(defaultConfig, {workDir}); defaultConfig.chaseWeakMapEdge = false; - return await analysis.checkLeak(); + const ret = await analysis.checkLeak(); + stateManager.restoreState(defaultConfig, state); + return ret; } /** @@ -247,16 +263,20 @@ export async function findLeaks( * @param baselineSnapshot the file path of the baseline heap snapshot * @param targetSnapshot the file path of the target heap snapshot * @param finalSnapshot the file path of the final heap snapshot - * @param options optionally, you can specify a working - * directory (other than the default one) for heap analysis + * @param options optionally, you can specify a mode for heap analysis + * @param options.workDir specify a working directory (other than + * the default one) + * @param options.consoleMode specify the terminal output + * mode (see {@link ConsoleMode}) * @returns leak traces detected and clustered from the browser interaction */ export async function findLeaksBySnapshotFilePaths( baselineSnapshot: string, targetSnapshot: string, finalSnapshot: string, - options: {workDir?: string} = {}, + options: {workDir?: string; consoleMode?: ConsoleMode} = {}, ): Promise { + const state = stateManager.getAndUpdateState(defaultConfig, options); defaultConfig.useExternalSnapshot = true; defaultConfig.externalSnapshotFilePaths = [ baselineSnapshot, @@ -265,7 +285,9 @@ export async function findLeaksBySnapshotFilePaths( ]; fileManager.initDirs(defaultConfig, {workDir: options.workDir}); defaultConfig.chaseWeakMapEdge = false; - return await analysis.checkLeak(); + const ret = await analysis.checkLeak(); + stateManager.restoreState(defaultConfig, state); + return ret; } /** diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index ac141c104..2368e078a 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -17,6 +17,7 @@ export async function registerPackage(): Promise { export * from './API'; export * from '@memlab/heap-analysis'; +export * from './state/ConsoleModeManager'; export {default as BrowserInteractionResultReader} from './result-reader/BrowserInteractionResultReader'; export {default as SnapshotResultReader} from './result-reader/SnapshotResultReader'; export { diff --git a/packages/api/src/state/APIStateManager.ts b/packages/api/src/state/APIStateManager.ts new file mode 100644 index 000000000..5ec8899a3 --- /dev/null +++ b/packages/api/src/state/APIStateManager.ts @@ -0,0 +1,47 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @oncall web_perf_infra + */ + +import type {MemLabConfig, Optional, PuppeteerConfig} from '@memlab/core'; +import type {ConsoleMode} from './ConsoleModeManager'; +import type {RunOptions} from '../API'; + +import consoleModeManager from './ConsoleModeManager'; +import puppeteerConfigManager from './PuppeteerConfigManager'; + +export class APIState { + modes: Optional>; + puppeteerConfig: Optional; +} + +/** + * Manage, save, and restore the current state of the API. + */ +class APIStateManager { + getAndUpdateState(config: MemLabConfig, options: RunOptions = {}) { + const state = new APIState(); + state.modes = consoleModeManager.getAndUpdateState(config, options); + state.puppeteerConfig = puppeteerConfigManager.getAndUpdateState( + config, + options, + ); + return state; + } + + restoreState(config: MemLabConfig, state: APIState) { + if (state.modes) { + consoleModeManager.restoreState(config, state.modes); + } + if (state.puppeteerConfig) { + puppeteerConfigManager.restoreState(config, state.puppeteerConfig); + } + } +} + +export default new APIStateManager(); diff --git a/packages/api/src/state/ConsoleModeManager.ts b/packages/api/src/state/ConsoleModeManager.ts new file mode 100644 index 000000000..203a9ff8a --- /dev/null +++ b/packages/api/src/state/ConsoleModeManager.ts @@ -0,0 +1,115 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @oncall web_perf_infra + */ + +import {MemLabConfig, Nullable, Optional, utils} from '@memlab/core'; +import type {RunOptions} from '../API'; + +/** + * enum of all console mode options + */ +export enum ConsoleMode { + /** + * mute all terminal output, equivalent to using `--silent` + */ + SILENT = 'SILENT', + /** + * continuous test mode, no terminal output overwrite or animation, + * equivalent to using `--sc` + */ + CONTINUOUS_TEST = 'CONTINUOUS_TEST', + /** + * the default mode, there could be terminal output overwrite and animation, + */ + DEFAULT = 'DEFAULT', + /** + * verbose mode, there could be terminal output overwrite and animation + */ + VERBOSE = 'VERBOSE', +} + +/** + * Manage, save, and restore the current state of the Console modes. + * @internal + */ +class ConsoleModeManager { + getAndUpdateState(config: MemLabConfig, options: RunOptions = {}) { + return this.setConsoleMode(config, options.consoleMode, true); + } + + restoreState(config: MemLabConfig, modes: Nullable>) { + if (modes == null) { + return; + } + this.resetConsoleMode(config); + for (const mode of modes) { + this.setConsoleMode(config, mode, false); + } + } + + private resetConsoleMode(config: MemLabConfig): void { + config.muteConsole = false; + config.isContinuousTest = false; + config.verbose = false; + } + + private setConsoleMode( + config: MemLabConfig, + mode: Optional, + reset: boolean, + ): Nullable> { + let existingModes: Nullable> = + this.getExistingConsoleModes(config); + switch (mode) { + case ConsoleMode.SILENT: + reset && this.resetConsoleMode(config); + config.muteConsole = true; + break; + case ConsoleMode.CONTINUOUS_TEST: + reset && this.resetConsoleMode(config); + config.isContinuousTest = true; + break; + case ConsoleMode.DEFAULT: + reset && this.resetConsoleMode(config); + config.muteConsole = false; + config.isContinuousTest = false; + break; + case ConsoleMode.VERBOSE: + reset && this.resetConsoleMode(config); + config.verbose = true; + break; + default: + if (mode == null) { + existingModes = null; + } else { + throw utils.haltOrThrow(`Unknown console mode: ${mode}`); + } + } + return existingModes; + } + + private getExistingConsoleModes(config: MemLabConfig): Set { + const modes = new Set([ConsoleMode.DEFAULT]); + if (config.muteConsole) { + modes.add(ConsoleMode.SILENT); + modes.delete(ConsoleMode.DEFAULT); + } + if (config.isContinuousTest) { + modes.add(ConsoleMode.CONTINUOUS_TEST); + modes.delete(ConsoleMode.DEFAULT); + } + if (config.verbose) { + modes.add(ConsoleMode.VERBOSE); + } + return modes; + } +} + +/** @internal */ +export default new ConsoleModeManager(); diff --git a/packages/api/src/state/PuppeteerConfigManager.ts b/packages/api/src/state/PuppeteerConfigManager.ts new file mode 100644 index 000000000..a7a6acc5e --- /dev/null +++ b/packages/api/src/state/PuppeteerConfigManager.ts @@ -0,0 +1,31 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @oncall web_perf_infra + */ + +import {MemLabConfig, PuppeteerConfig} from '@memlab/core'; +import {RunOptions} from '../API'; + +/** + * Manage, save, and restore the current state of the PuppeteerConfig. + */ +class PuppeteerStateManager { + getAndUpdateState(config: MemLabConfig, options: RunOptions = {}) { + const existing = config.puppeteerConfig; + config.puppeteerConfig = {...config.puppeteerConfig}; + config.externalCookiesFile = options.cookiesFile; + config.scenario = options.scenario; + return existing; + } + + restoreState(config: MemLabConfig, puppeteerConfig: PuppeteerConfig) { + config.puppeteerConfig = puppeteerConfig; + } +} + +export default new PuppeteerStateManager(); diff --git a/packages/core/src/lib/Config.ts b/packages/core/src/lib/Config.ts index cb5d99d4a..b5349d63f 100644 --- a/packages/core/src/lib/Config.ts +++ b/packages/core/src/lib/Config.ts @@ -8,10 +8,9 @@ * @oncall web_perf_infra */ -import type {LaunchOptions, Permission} from 'puppeteer'; +import type {Permission} from 'puppeteer'; import type { AnyFunction, - AnyValue, FileOption, IClusterStrategy, IRunningMode, @@ -22,6 +21,7 @@ import type { QuickExperiment, ILeakFilter, IPackageInfo, + PuppeteerConfig, } from './Types'; import path from 'path'; @@ -31,22 +31,6 @@ import constant from './Constant'; import fileManager, {FileManager} from './FileManager'; import {setInternalValue} from './InternalValueSetter'; -interface BrowserLaunchArgumentOptions { - headless?: boolean; - userDataDir?: string; - devtools?: boolean; - debuggingPort?: number; - args?: string[]; -} - -interface BrowserConnectOptions { - ignoreHTTPSErrors?: boolean; - defaultViewport?: AnyValue | null; - protocolTimeout?: number; - slowMo?: number; - targetFilter?: AnyFunction; -} - interface Device { name: string; userAgent: string; @@ -154,9 +138,7 @@ export class MemLabConfig { extraRunInfoMap: Map; heapConfig: Optional; - puppeteerConfig: LaunchOptions & - BrowserLaunchArgumentOptions & - BrowserConnectOptions; + puppeteerConfig: PuppeteerConfig; openDevtoolsConsole: boolean; emulateDevice: Nullable; addEnableGK: Set; diff --git a/packages/core/src/lib/Types.ts b/packages/core/src/lib/Types.ts index b1eb7fcae..09391515a 100644 --- a/packages/core/src/lib/Types.ts +++ b/packages/core/src/lib/Types.ts @@ -131,6 +131,29 @@ export type CLIArgs = { 'snapshot-dir': string; }; +/** @internal */ +interface BrowserLaunchArgumentOptions { + headless?: boolean; + userDataDir?: string; + devtools?: boolean; + debuggingPort?: number; + args?: string[]; +} + +/** @internal */ +interface BrowserConnectOptions { + ignoreHTTPSErrors?: boolean; + defaultViewport?: AnyValue | null; + protocolTimeout?: number; + slowMo?: number; + targetFilter?: AnyFunction; +} + +/** @internal */ +export type PuppeteerConfig = LaunchOptions & + BrowserLaunchArgumentOptions & + BrowserConnectOptions; + /** * This is the puppeteer [`Page`](https://pptr.dev/api/puppeteer.page) * class used by MemLab. The puppeteer `Page` class instance provides diff --git a/website/docs/api/enums/_category_.yml b/website/docs/api/enums/_category_.yml new file mode 100644 index 000000000..1687a9e03 --- /dev/null +++ b/website/docs/api/enums/_category_.yml @@ -0,0 +1,2 @@ +label: "Enumerations" +position: 2 \ No newline at end of file diff --git a/website/docs/api/enums/api_src.ConsoleMode.md b/website/docs/api/enums/api_src.ConsoleMode.md new file mode 100644 index 000000000..28217a5d2 --- /dev/null +++ b/website/docs/api/enums/api_src.ConsoleMode.md @@ -0,0 +1,45 @@ +--- +id: "api_src.ConsoleMode" +title: "Enumeration: ConsoleMode" +sidebar_label: "ConsoleMode" +custom_edit_url: null +--- + +enum of all console mode options + +## Enumeration Members + +### **CONTINUOUS\_TEST** + +continuous test mode, no terminal output overwrite or animation, +equivalent to using `--sc` + + * **Source**: + * api/src/state/ConsoleModeManager.ts:26 + +___ + +### **DEFAULT** + +the default mode, there could be terminal output overwrite and animation, + + * **Source**: + * api/src/state/ConsoleModeManager.ts:30 + +___ + +### **SILENT** + +mute all terminal output, equivalent to using `--silent` + + * **Source**: + * api/src/state/ConsoleModeManager.ts:21 + +___ + +### **VERBOSE** + +verbose mode, there could be terminal output overwrite and animation + + * **Source**: + * api/src/state/ConsoleModeManager.ts:34 diff --git a/website/docs/api/interfaces/core_src.IBrowserInfo.md b/website/docs/api/interfaces/core_src.IBrowserInfo.md index 0e0fb980f..dc364a1cd 100644 --- a/website/docs/api/interfaces/core_src.IBrowserInfo.md +++ b/website/docs/api/interfaces/core_src.IBrowserInfo.md @@ -16,7 +16,7 @@ through [RunMetaInfo](../modules/core_src.md#runmetainfo). browser version * **Source**: - * core/src/lib/Types.ts:1171 + * core/src/lib/Types.ts:1194 ___ @@ -25,7 +25,7 @@ ___ all web console output * **Source**: - * core/src/lib/Types.ts:1179 + * core/src/lib/Types.ts:1202 ___ @@ -34,4 +34,4 @@ ___ configuration for puppeteer * **Source**: - * core/src/lib/Types.ts:1175 + * core/src/lib/Types.ts:1198 diff --git a/website/docs/api/interfaces/core_src.IHeapEdge.md b/website/docs/api/interfaces/core_src.IHeapEdge.md index 322ebde60..a3dfcb02f 100644 --- a/website/docs/api/interfaces/core_src.IHeapEdge.md +++ b/website/docs/api/interfaces/core_src.IHeapEdge.md @@ -45,7 +45,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; index of this JS reference inside the `edge.snapshot.edges` pseudo array * **Source**: - * core/src/lib/Types.ts:1596 + * core/src/lib/Types.ts:1619 ___ @@ -55,7 +55,7 @@ returns an [IHeapNode](core_src.IHeapNode.md) instance representing the hosting JS heap object where this reference starts * **Source**: - * core/src/lib/Types.ts:1617 + * core/src/lib/Types.ts:1640 ___ @@ -67,7 +67,7 @@ otherwise this is a reference with a string name (`edge.name_or_index` will return a string) * **Source**: - * core/src/lib/Types.ts:1603 + * core/src/lib/Types.ts:1626 ___ @@ -77,7 +77,7 @@ name of the JS reference. If this is a reference to an array element or internal table element, it is an numeric index * **Source**: - * core/src/lib/Types.ts:1552 + * core/src/lib/Types.ts:1575 ___ @@ -86,7 +86,7 @@ ___ get the [IHeapSnapshot](core_src.IHeapSnapshot.md) containing this JS reference * **Source**: - * core/src/lib/Types.ts:1592 + * core/src/lib/Types.ts:1615 ___ @@ -96,7 +96,7 @@ returns an [IHeapNode](core_src.IHeapNode.md) instance representing the JS heap pointed to by this reference * **Source**: - * core/src/lib/Types.ts:1612 + * core/src/lib/Types.ts:1635 ___ @@ -105,7 +105,7 @@ ___ the index of the JS heap object pointed to by this reference * **Source**: - * core/src/lib/Types.ts:1607 + * core/src/lib/Types.ts:1630 ___ @@ -115,7 +115,7 @@ type of the JS reference, all types: `context`, `element`, `property`, `internal`, `hidden`, `shortcut`, `weak` * **Source**: - * core/src/lib/Types.ts:1557 + * core/src/lib/Types.ts:1580 ## Methods @@ -133,4 +133,4 @@ captured by the hosting object. * `...args`: `any`[] * **Returns**: `string` * **Source**: - * core/src/lib/Types.ts:1627 + * core/src/lib/Types.ts:1650 diff --git a/website/docs/api/interfaces/core_src.IHeapEdges.md b/website/docs/api/interfaces/core_src.IHeapEdges.md index ad4be0cdb..5b1775636 100644 --- a/website/docs/api/interfaces/core_src.IHeapEdges.md +++ b/website/docs/api/interfaces/core_src.IHeapEdges.md @@ -41,7 +41,7 @@ The total number of edges in heap graph (or JS references in heap snapshot). * **Source**: - * core/src/lib/Types.ts:1664 + * core/src/lib/Types.ts:1687 ## Methods @@ -54,7 +54,7 @@ to each element in ascending order of element index. * `callback`: (`edge`: [`IHeapEdge`](core_src.IHeapEdge.md), `index`: `number`) => `boolean` \| `void` | the callback does not need to return any value, if the callback returns `false` when iterating on element at index `i`, then all elements after `i` won't be iterated. * **Returns**: `void` * **Source**: - * core/src/lib/Types.ts:1680 + * core/src/lib/Types.ts:1703 ___ @@ -68,4 +68,4 @@ get an [IHeapEdge](core_src.IHeapEdge.md) element at the specified index at the specified index, otherwise it returns `null`. * **Source**: - * core/src/lib/Types.ts:1672 + * core/src/lib/Types.ts:1695 diff --git a/website/docs/api/interfaces/core_src.IHeapLocation.md b/website/docs/api/interfaces/core_src.IHeapLocation.md index ad42ebd83..7a3e0727c 100644 --- a/website/docs/api/interfaces/core_src.IHeapLocation.md +++ b/website/docs/api/interfaces/core_src.IHeapLocation.md @@ -43,7 +43,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; get the column number * **Source**: - * core/src/lib/Types.ts:1533 + * core/src/lib/Types.ts:1556 ___ @@ -52,7 +52,7 @@ ___ get the line number * **Source**: - * core/src/lib/Types.ts:1529 + * core/src/lib/Types.ts:1552 ___ @@ -61,7 +61,7 @@ ___ get the heap object this location this location represents * **Source**: - * core/src/lib/Types.ts:1521 + * core/src/lib/Types.ts:1544 ___ @@ -70,7 +70,7 @@ ___ get the script ID of the source file * **Source**: - * core/src/lib/Types.ts:1525 + * core/src/lib/Types.ts:1548 ___ @@ -79,7 +79,7 @@ ___ get the [IHeapSnapshot](core_src.IHeapSnapshot.md) containing this location instance * **Source**: - * core/src/lib/Types.ts:1517 + * core/src/lib/Types.ts:1540 ## Methods @@ -97,4 +97,4 @@ captured by the hosting object. * `...args`: `any`[] * **Returns**: `string` * **Source**: - * core/src/lib/Types.ts:1543 + * core/src/lib/Types.ts:1566 diff --git a/website/docs/api/interfaces/core_src.IHeapNode.md b/website/docs/api/interfaces/core_src.IHeapNode.md index 810d4124c..b41eb3548 100644 --- a/website/docs/api/interfaces/core_src.IHeapNode.md +++ b/website/docs/api/interfaces/core_src.IHeapNode.md @@ -52,7 +52,7 @@ For more information on what a dominator node is, please check out [this doc](https://developer.chrome.com/docs/devtools/memory-problems/memory-101/#dominators). * **Source**: - * core/src/lib/Types.ts:1821 + * core/src/lib/Types.ts:1844 ___ @@ -62,7 +62,7 @@ The total number of outgoing JS references (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1775 + * core/src/lib/Types.ts:1798 ___ @@ -72,7 +72,7 @@ returns true if the heap node has been set an incoming edge which leads to the parent node on the shortest path to GC root. * **Source**: - * core/src/lib/Types.ts:1797 + * core/src/lib/Types.ts:1820 ___ @@ -81,7 +81,7 @@ ___ unique id of the heap object * **Source**: - * core/src/lib/Types.ts:1702 + * core/src/lib/Types.ts:1725 ___ @@ -91,7 +91,7 @@ check if this a string node (normal string node, concatenated string node or sliced string node) * **Source**: - * core/src/lib/Types.ts:1833 + * core/src/lib/Types.ts:1856 ___ @@ -104,7 +104,7 @@ from the React Fiber tree, `is_detached` will be `true`; otherwise it will be `false` * **Source**: - * core/src/lib/Types.ts:1757 + * core/src/lib/Types.ts:1780 ___ @@ -114,7 +114,7 @@ source location information of this heap object (if it is recorded by the heap snapshot). * **Source**: - * core/src/lib/Types.ts:1826 + * core/src/lib/Types.ts:1849 ___ @@ -125,7 +125,7 @@ for JS object instances (type `object`), `name` is the constructor's name of the object instance. for `string`, `name` is the string value. * **Source**: - * core/src/lib/Types.ts:1698 + * core/src/lib/Types.ts:1721 ___ @@ -134,7 +134,7 @@ ___ index of this heap object inside the `node.snapshot.nodes` pseudo array * **Source**: - * core/src/lib/Types.ts:1806 + * core/src/lib/Types.ts:1829 ___ @@ -144,7 +144,7 @@ Get the number of all incoming references pointing to this heap object (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1792 + * core/src/lib/Types.ts:1815 ___ @@ -154,7 +154,7 @@ The incoming edge which leads to the parent node on the shortest path to GC root. * **Source**: - * core/src/lib/Types.ts:1802 + * core/src/lib/Types.ts:1825 ___ @@ -164,7 +164,7 @@ Get a JS array containing all outgoing JS references from this heap object (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1782 + * core/src/lib/Types.ts:1805 ___ @@ -174,7 +174,7 @@ Get a JS array containing all incoming JS references pointing to this heap object (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1787 + * core/src/lib/Types.ts:1810 ___ @@ -186,7 +186,7 @@ could be released if this object is released). For difference between [this doc](https://developer.chrome.com/docs/devtools/memory-problems/memory-101/#object_sizes). * **Source**: - * core/src/lib/Types.ts:1813 + * core/src/lib/Types.ts:1836 ___ @@ -198,7 +198,7 @@ by the object itself.). For difference between **shallow size** and [this doc](https://developer.chrome.com/docs/devtools/memory-problems/memory-101/#object_sizes). * **Source**: - * core/src/lib/Types.ts:1770 + * core/src/lib/Types.ts:1793 ___ @@ -207,7 +207,7 @@ ___ get the [IHeapSnapshot](core_src.IHeapSnapshot.md) containing this heap object * **Source**: - * core/src/lib/Types.ts:1749 + * core/src/lib/Types.ts:1772 ___ @@ -220,7 +220,7 @@ This is engine-specific, for example all types in V8: `symbol`, `bigint` * **Source**: - * core/src/lib/Types.ts:1692 + * core/src/lib/Types.ts:1715 ## Methods @@ -244,7 +244,7 @@ const reference = node.findAnyReference((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1902 + * core/src/lib/Types.ts:1925 ___ @@ -268,7 +268,7 @@ const referrer = node.findAnyReferrer((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1919 + * core/src/lib/Types.ts:1942 ___ @@ -293,7 +293,7 @@ const referrer = node.findAnyReferrerNode((node: IHeapNode) => { ``` * **Source**: - * core/src/lib/Types.ts:1937 + * core/src/lib/Types.ts:1960 ___ @@ -318,7 +318,7 @@ const referrerNodes = node.findReferrerNodes((node: IHeapNode) => { ``` * **Source**: - * core/src/lib/Types.ts:1972 + * core/src/lib/Types.ts:1995 ___ @@ -342,7 +342,7 @@ const referrers = node.findReferrers((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1954 + * core/src/lib/Types.ts:1977 ___ @@ -367,7 +367,7 @@ node.forEachReference((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1867 + * core/src/lib/Types.ts:1890 ___ @@ -392,7 +392,7 @@ node.forEachReferrer((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1885 + * core/src/lib/Types.ts:1908 ___ @@ -413,7 +413,7 @@ const reference = node.getAnyReferrer('ref', 'property'); ``` * **Source**: - * core/src/lib/Types.ts:2027 + * core/src/lib/Types.ts:2050 ___ @@ -439,7 +439,7 @@ const n2 = node.getAnyReferrer('ref', 'property')?.fromNode; ``` * **Source**: - * core/src/lib/Types.ts:2050 + * core/src/lib/Types.ts:2073 ___ @@ -460,7 +460,7 @@ const reference = node.getReference('map', 'hidden'); ``` * **Source**: - * core/src/lib/Types.ts:1987 + * core/src/lib/Types.ts:2010 ___ @@ -485,7 +485,7 @@ const hiddenClassNode2 = node.getReference('map', 'hidden')?.toNode; ``` * **Source**: - * core/src/lib/Types.ts:2009 + * core/src/lib/Types.ts:2032 ___ @@ -512,7 +512,7 @@ const nodes2 = node.getReferrers('ref', 'property') ``` * **Source**: - * core/src/lib/Types.ts:2090 + * core/src/lib/Types.ts:2113 ___ @@ -534,7 +534,7 @@ const referrers = node.getReferrers('ref', 'property'); ``` * **Source**: - * core/src/lib/Types.ts:2069 + * core/src/lib/Types.ts:2092 ___ @@ -552,7 +552,7 @@ captured by the hosting object. * `...args`: `any`[] * **Returns**: `string` * **Source**: - * core/src/lib/Types.ts:1849 + * core/src/lib/Types.ts:1872 ___ @@ -564,4 +564,4 @@ inside the string node. * **Returns**: [`Nullable`](../modules/core_src.md#nullable)<[`IHeapStringNode`](core_src.IHeapStringNode.md)\> * **Source**: - * core/src/lib/Types.ts:1839 + * core/src/lib/Types.ts:1862 diff --git a/website/docs/api/interfaces/core_src.IHeapNodes.md b/website/docs/api/interfaces/core_src.IHeapNodes.md index 74a7d538d..48bb11ec1 100644 --- a/website/docs/api/interfaces/core_src.IHeapNodes.md +++ b/website/docs/api/interfaces/core_src.IHeapNodes.md @@ -41,7 +41,7 @@ The total number of nodes in heap graph (or JS objects in heap snapshot). * **Source**: - * core/src/lib/Types.ts:2168 + * core/src/lib/Types.ts:2191 ## Methods @@ -54,7 +54,7 @@ to each element in ascending order of element index. * `callback`: (`node`: [`IHeapNode`](core_src.IHeapNode.md), `index`: `number`) => `boolean` \| `void` | the callback does not need to return any value, if the callback returns `false` when iterating on element at index `i`, then all elements after `i` won't be iterated. * **Returns**: `void` * **Source**: - * core/src/lib/Types.ts:2184 + * core/src/lib/Types.ts:2207 ___ @@ -68,4 +68,4 @@ get an [IHeapNode](core_src.IHeapNode.md) element at the specified index at the specified index, otherwise it returns `null`. * **Source**: - * core/src/lib/Types.ts:2176 + * core/src/lib/Types.ts:2199 diff --git a/website/docs/api/interfaces/core_src.IHeapSnapshot.md b/website/docs/api/interfaces/core_src.IHeapSnapshot.md index f99f4b642..d4e138a87 100644 --- a/website/docs/api/interfaces/core_src.IHeapSnapshot.md +++ b/website/docs/api/interfaces/core_src.IHeapSnapshot.md @@ -39,7 +39,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; ``` * **Source**: - * core/src/lib/Types.ts:1271 + * core/src/lib/Types.ts:1294 ___ @@ -70,7 +70,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; ``` * **Source**: - * core/src/lib/Types.ts:1245 + * core/src/lib/Types.ts:1268 ## Methods @@ -105,7 +105,7 @@ class TestObject { ``` * **Source**: - * core/src/lib/Types.ts:1412 + * core/src/lib/Types.ts:1435 ___ @@ -134,7 +134,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; ``` * **Source**: - * core/src/lib/Types.ts:1293 + * core/src/lib/Types.ts:1316 ___ @@ -166,7 +166,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; ``` * **Source**: - * core/src/lib/Types.ts:1345 + * core/src/lib/Types.ts:1368 ___ @@ -198,7 +198,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; ``` * **Source**: - * core/src/lib/Types.ts:1319 + * core/src/lib/Types.ts:1342 ___ @@ -244,7 +244,7 @@ test('memory test with heap assertion', async () => { ``` * **Source**: - * core/src/lib/Types.ts:1384 + * core/src/lib/Types.ts:1407 ___ @@ -276,7 +276,7 @@ import {getFullHeapFromFile} from '@memlab/heap-analysis'; ``` * **Source**: - * core/src/lib/Types.ts:1438 + * core/src/lib/Types.ts:1461 ___ @@ -320,4 +320,4 @@ test('memory test', async () => { ``` * **Source**: - * core/src/lib/Types.ts:1476 + * core/src/lib/Types.ts:1499 diff --git a/website/docs/api/interfaces/core_src.IHeapStringNode.md b/website/docs/api/interfaces/core_src.IHeapStringNode.md index 59a0706df..313deaf4a 100644 --- a/website/docs/api/interfaces/core_src.IHeapStringNode.md +++ b/website/docs/api/interfaces/core_src.IHeapStringNode.md @@ -51,7 +51,7 @@ For more information on what a dominator node is, please check out [this doc](https://developer.chrome.com/docs/devtools/memory-problems/memory-101/#dominators). * **Source**: - * core/src/lib/Types.ts:1821 + * core/src/lib/Types.ts:1844 ___ @@ -61,7 +61,7 @@ The total number of outgoing JS references (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1775 + * core/src/lib/Types.ts:1798 ___ @@ -71,7 +71,7 @@ returns true if the heap node has been set an incoming edge which leads to the parent node on the shortest path to GC root. * **Source**: - * core/src/lib/Types.ts:1797 + * core/src/lib/Types.ts:1820 ___ @@ -80,7 +80,7 @@ ___ unique id of the heap object * **Source**: - * core/src/lib/Types.ts:1702 + * core/src/lib/Types.ts:1725 ___ @@ -90,7 +90,7 @@ check if this a string node (normal string node, concatenated string node or sliced string node) * **Source**: - * core/src/lib/Types.ts:1833 + * core/src/lib/Types.ts:1856 ___ @@ -103,7 +103,7 @@ from the React Fiber tree, `is_detached` will be `true`; otherwise it will be `false` * **Source**: - * core/src/lib/Types.ts:1757 + * core/src/lib/Types.ts:1780 ___ @@ -113,7 +113,7 @@ source location information of this heap object (if it is recorded by the heap snapshot). * **Source**: - * core/src/lib/Types.ts:1826 + * core/src/lib/Types.ts:1849 ___ @@ -124,7 +124,7 @@ for JS object instances (type `object`), `name` is the constructor's name of the object instance. for `string`, `name` is the string value. * **Source**: - * core/src/lib/Types.ts:1698 + * core/src/lib/Types.ts:1721 ___ @@ -133,7 +133,7 @@ ___ index of this heap object inside the `node.snapshot.nodes` pseudo array * **Source**: - * core/src/lib/Types.ts:1806 + * core/src/lib/Types.ts:1829 ___ @@ -143,7 +143,7 @@ Get the number of all incoming references pointing to this heap object (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1792 + * core/src/lib/Types.ts:1815 ___ @@ -153,7 +153,7 @@ The incoming edge which leads to the parent node on the shortest path to GC root. * **Source**: - * core/src/lib/Types.ts:1802 + * core/src/lib/Types.ts:1825 ___ @@ -163,7 +163,7 @@ Get a JS array containing all outgoing JS references from this heap object (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1782 + * core/src/lib/Types.ts:1805 ___ @@ -173,7 +173,7 @@ Get a JS array containing all incoming JS references pointing to this heap object (including engine-internal, native, and JS references). * **Source**: - * core/src/lib/Types.ts:1787 + * core/src/lib/Types.ts:1810 ___ @@ -185,7 +185,7 @@ could be released if this object is released). For difference between [this doc](https://developer.chrome.com/docs/devtools/memory-problems/memory-101/#object_sizes). * **Source**: - * core/src/lib/Types.ts:1813 + * core/src/lib/Types.ts:1836 ___ @@ -197,7 +197,7 @@ by the object itself.). For difference between **shallow size** and [this doc](https://developer.chrome.com/docs/devtools/memory-problems/memory-101/#object_sizes). * **Source**: - * core/src/lib/Types.ts:1770 + * core/src/lib/Types.ts:1793 ___ @@ -206,7 +206,7 @@ ___ get the [IHeapSnapshot](core_src.IHeapSnapshot.md) containing this heap object * **Source**: - * core/src/lib/Types.ts:1749 + * core/src/lib/Types.ts:1772 ___ @@ -216,7 +216,7 @@ get the string value of the JS string heap object associated with this `IHeapStringNode` instance in heap * **Source**: - * core/src/lib/Types.ts:2131 + * core/src/lib/Types.ts:2154 ___ @@ -229,7 +229,7 @@ This is engine-specific, for example all types in V8: `symbol`, `bigint` * **Source**: - * core/src/lib/Types.ts:1692 + * core/src/lib/Types.ts:1715 ## Methods @@ -253,7 +253,7 @@ const reference = node.findAnyReference((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1902 + * core/src/lib/Types.ts:1925 ___ @@ -277,7 +277,7 @@ const referrer = node.findAnyReferrer((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1919 + * core/src/lib/Types.ts:1942 ___ @@ -302,7 +302,7 @@ const referrer = node.findAnyReferrerNode((node: IHeapNode) => { ``` * **Source**: - * core/src/lib/Types.ts:1937 + * core/src/lib/Types.ts:1960 ___ @@ -327,7 +327,7 @@ const referrerNodes = node.findReferrerNodes((node: IHeapNode) => { ``` * **Source**: - * core/src/lib/Types.ts:1972 + * core/src/lib/Types.ts:1995 ___ @@ -351,7 +351,7 @@ const referrers = node.findReferrers((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1954 + * core/src/lib/Types.ts:1977 ___ @@ -376,7 +376,7 @@ node.forEachReference((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1867 + * core/src/lib/Types.ts:1890 ___ @@ -401,7 +401,7 @@ node.forEachReferrer((edge: IHeapEdge) => { ``` * **Source**: - * core/src/lib/Types.ts:1885 + * core/src/lib/Types.ts:1908 ___ @@ -422,7 +422,7 @@ const reference = node.getAnyReferrer('ref', 'property'); ``` * **Source**: - * core/src/lib/Types.ts:2027 + * core/src/lib/Types.ts:2050 ___ @@ -448,7 +448,7 @@ const n2 = node.getAnyReferrer('ref', 'property')?.fromNode; ``` * **Source**: - * core/src/lib/Types.ts:2050 + * core/src/lib/Types.ts:2073 ___ @@ -469,7 +469,7 @@ const reference = node.getReference('map', 'hidden'); ``` * **Source**: - * core/src/lib/Types.ts:1987 + * core/src/lib/Types.ts:2010 ___ @@ -494,7 +494,7 @@ const hiddenClassNode2 = node.getReference('map', 'hidden')?.toNode; ``` * **Source**: - * core/src/lib/Types.ts:2009 + * core/src/lib/Types.ts:2032 ___ @@ -521,7 +521,7 @@ const nodes2 = node.getReferrers('ref', 'property') ``` * **Source**: - * core/src/lib/Types.ts:2090 + * core/src/lib/Types.ts:2113 ___ @@ -543,7 +543,7 @@ const referrers = node.getReferrers('ref', 'property'); ``` * **Source**: - * core/src/lib/Types.ts:2069 + * core/src/lib/Types.ts:2092 ___ @@ -561,7 +561,7 @@ captured by the hosting object. * `...args`: `any`[] * **Returns**: `string` * **Source**: - * core/src/lib/Types.ts:1849 + * core/src/lib/Types.ts:1872 ___ @@ -573,4 +573,4 @@ inside the string node. * **Returns**: [`Nullable`](../modules/core_src.md#nullable)<[`IHeapStringNode`](core_src.IHeapStringNode.md)\> * **Source**: - * core/src/lib/Types.ts:1839 + * core/src/lib/Types.ts:1862 diff --git a/website/docs/api/interfaces/core_src.ILeakFilter.md b/website/docs/api/interfaces/core_src.ILeakFilter.md index c4a964ed2..6aa10ea1e 100644 --- a/website/docs/api/interfaces/core_src.ILeakFilter.md +++ b/website/docs/api/interfaces/core_src.ILeakFilter.md @@ -92,7 +92,7 @@ module.exports = { ``` * **Source**: - * core/src/lib/Types.ts:404 + * core/src/lib/Types.ts:427 ___ @@ -146,7 +146,7 @@ memlab run --scenario --leak-filter ``` * **Source**: - * core/src/lib/Types.ts:453 + * core/src/lib/Types.ts:476 ___ @@ -205,4 +205,4 @@ memlab run --scenario --leak-filter ``` * **Source**: - * core/src/lib/Types.ts:507 + * core/src/lib/Types.ts:530 diff --git a/website/docs/api/interfaces/core_src.IScenario.md b/website/docs/api/interfaces/core_src.IScenario.md index e4957ad72..2bab7caf8 100644 --- a/website/docs/api/interfaces/core_src.IScenario.md +++ b/website/docs/api/interfaces/core_src.IScenario.md @@ -89,7 +89,7 @@ module.exports = scenario; ``` * **Source**: - * core/src/lib/Types.ts:795 + * core/src/lib/Types.ts:818 ___ @@ -119,7 +119,7 @@ Check out [this page](/docs/how-memlab-works) on why memlab needs to undo/revert the `action` callback. * **Source**: - * core/src/lib/Types.ts:820 + * core/src/lib/Types.ts:843 ___ @@ -153,7 +153,7 @@ module.exports = scenario; ``` * **Source**: - * core/src/lib/Types.ts:701 + * core/src/lib/Types.ts:724 ___ @@ -185,7 +185,7 @@ module.exports = { ``` * **Source**: - * core/src/lib/Types.ts:898 + * core/src/lib/Types.ts:921 ___ @@ -226,7 +226,7 @@ module.exports = { ``` * **Source**: - * core/src/lib/Types.ts:871 + * core/src/lib/Types.ts:894 ___ @@ -273,7 +273,7 @@ module.exports = { ``` * **Source**: - * core/src/lib/Types.ts:940 + * core/src/lib/Types.ts:963 ___ @@ -321,7 +321,7 @@ module.exports = { ``` * **Source**: - * core/src/lib/Types.ts:983 + * core/src/lib/Types.ts:1006 ___ @@ -356,7 +356,7 @@ module.exports = scenario; ``` * **Source**: - * core/src/lib/Types.ts:749 + * core/src/lib/Types.ts:772 ## Methods @@ -391,7 +391,7 @@ module.exports = scenario; ``` * **Source**: - * core/src/lib/Types.ts:672 + * core/src/lib/Types.ts:695 ___ @@ -412,7 +412,7 @@ module.exports = { * **Returns**: `number` * **Source**: - * core/src/lib/Types.ts:835 + * core/src/lib/Types.ts:858 ___ @@ -435,4 +435,4 @@ load. All objects allocated by the initial page load will be candidates for memory leak filtering. * **Source**: - * core/src/lib/Types.ts:719 + * core/src/lib/Types.ts:742 diff --git a/website/docs/api/modules/api_src.md b/website/docs/api/modules/api_src.md index c7d54eb1f..88613290a 100644 --- a/website/docs/api/modules/api_src.md +++ b/website/docs/api/modules/api_src.md @@ -6,6 +6,10 @@ sidebar_position: 0 custom_edit_url: null --- +## Enumerations + +- [ConsoleMode](../enums/api_src.ConsoleMode.md) + ## Classes - [BrowserInteractionResultReader](../classes/api_src.BrowserInteractionResultReader.md) @@ -19,6 +23,7 @@ Options for configuring browser interaction run, all fields are optional | Name | Type | Description | | :------ | :------ | :------ | +| `consoleMode?` | [`ConsoleMode`](../enums/api_src.ConsoleMode.md) | specifying the terminal output mode, default is `default`. For more details. please check out [ConsoleMode](../enums/api_src.ConsoleMode.md) | | `cookiesFile?` | `string` | the absolute path of cookies file | | `evalInBrowserAfterInitLoad?` | `AnyFunction` | function to be evaluated in browser context after the web page initial load | | `scenario?` | `IScenario` | test scenario specifying how to interact with browser (for more details view [IScenario](../interfaces/core_src.IScenario.md)) | @@ -28,7 +33,7 @@ Options for configuring browser interaction run, all fields are optional | `workDir?` | `string` | specify the working directory where you want memlab to dump heap snapshots and other meta data of the test run. If no working directory is provided, memlab will generate a random temp directory under the operating system's default directory for temporary files. Note: It's the caller's responsibility to make sure the specified working directory exists. | * **Source**: - * api/src/API.ts:45 + * api/src/API.ts:47 ___ @@ -42,7 +47,7 @@ A data structure holding the result of the [run](api_src.md#run) API call. | `runResult` | [`BrowserInteractionResultReader`](../classes/api_src.BrowserInteractionResultReader.md) | a utility for reading browser interaction results from disk | * **Source**: - * api/src/API.ts:90 + * api/src/API.ts:97 ## Functions @@ -73,17 +78,19 @@ const {analyze, takeSnapshots, StringAnalysis} = require('@memlab/api'); ``` * **Source**: - * api/src/API.ts:295 + * api/src/API.ts:317 ___ -### **findLeaks**(`runResult`) +### **findLeaks**(`runResult`, `options?`) This API finds memory leaks by analyzing heap snapshot(s). This is equivalent to `memlab find-leaks` in CLI. * **Parameters**: * `runResult`: `default` | return value of a browser interaction run + * `options`: `Object` | configure memory leak detection run + * `options.consoleMode?`: [`ConsoleMode`](../enums/api_src.ConsoleMode.md) | specify the terminal output mode (see [ConsoleMode](../enums/api_src.ConsoleMode.md)) * **Returns**: `Promise`<`ISerializedInfo`[]\> | leak traces detected and clustered from the browser interaction * **Examples**: ```javascript @@ -93,13 +100,13 @@ const {findLeaks, takeSnapshots} = require('@memlab/api'); const scenario = { url: () => 'https://www.facebook.com', }; - const result = await takeSnapshots({scenario}); - const leaks = findLeaks(result); + const result = await takeSnapshots({scenario, consoleMode: 'SILENT'}); + const leaks = findLeaks(result, {consoleMode: 'CONTINUOUS_TEST'}); })(); ``` * **Source**: - * api/src/API.ts:233 + * api/src/API.ts:245 ___ @@ -113,16 +120,17 @@ the `--baseline`, `--target`, and `--final` flags in CLI. * `baselineSnapshot`: `string` | the file path of the baseline heap snapshot * `targetSnapshot`: `string` | the file path of the target heap snapshot * `finalSnapshot`: `string` | the file path of the final heap snapshot - * `options`: `Object` | optionally, you can specify a working directory (other than the default one) for heap analysis - * `options.workDir?`: `string` + * `options`: `Object` | optionally, you can specify a mode for heap analysis + * `options.consoleMode?`: [`ConsoleMode`](../enums/api_src.ConsoleMode.md) | specify the terminal output mode (see [ConsoleMode](../enums/api_src.ConsoleMode.md)) + * `options.workDir?`: `string` | specify a working directory (other than the default one) * **Returns**: `Promise`<`ISerializedInfo`[]\> | leak traces detected and clustered from the browser interaction * **Source**: - * api/src/API.ts:254 + * api/src/API.ts:273 ___ -### **run**(`runOptions?`) +### **run**(`options?`) This API runs browser interaction and find memory leaks triggered in browser This is equivalent to running `memlab run` in CLI. @@ -130,7 +138,7 @@ This is also equivalent to warm up, and call [takeSnapshots](api_src.md#takesnap and [findLeaks](api_src.md#findleaks). * **Parameters**: - * `runOptions`: [`RunOptions`](api_src.md#runoptions) | configure browser interaction run + * `options`: [`RunOptions`](api_src.md#runoptions) * **Returns**: `Promise`<[`RunResult`](api_src.md#runresult)\> | memory leaks detected and a utility reading browser interaction results from disk * **Examples**: @@ -146,7 +154,7 @@ const {run} = require('@memlab/api'); ``` * **Source**: - * api/src/API.ts:169 + * api/src/API.ts:177 ___ @@ -171,7 +179,7 @@ const {takeSnapshots} = require('@memlab/api'); ``` * **Source**: - * api/src/API.ts:202 + * api/src/API.ts:210 ___ @@ -197,4 +205,4 @@ const {warmupAndTakeSnapshots} = require('@memlab/api'); ``` * **Source**: - * api/src/API.ts:133 + * api/src/API.ts:140 diff --git a/website/docs/api/modules/core_src.md b/website/docs/api/modules/core_src.md index f9582d4ef..2687a02fe 100644 --- a/website/docs/api/modules/core_src.md +++ b/website/docs/api/modules/core_src.md @@ -34,7 +34,7 @@ this callback until it returns `true`. This is an async callback, you can also `await` and returns `true` until some async logic is resolved. * **Source**: - * core/src/lib/Types.ts:1105 + * core/src/lib/Types.ts:1128 ___ @@ -61,7 +61,7 @@ For concrete use case, please check out [cookies](../interfaces/core_src.IScenar | `value` | `string` | Mandatory: Represents the value assigned to the cookie | * **Source**: - * core/src/lib/Types.ts:213 + * core/src/lib/Types.ts:236 ___ @@ -71,7 +71,7 @@ Data structure for holding cookies. For concrete use case, please check out [cookies](../interfaces/core_src.IScenario.md#cookies). * **Source**: - * core/src/lib/Types.ts:203 + * core/src/lib/Types.ts:226 ___ @@ -86,7 +86,7 @@ or [forEachReferrer](../interfaces/core_src.IHeapNode.md#foreachreferrer). * **Returns**: [`Optional`](core_src.md#optional)<{ `stop`: `boolean` }\> \| `void` | this API returns void * **Source**: - * core/src/lib/Types.ts:1712 + * core/src/lib/Types.ts:1735 ___ @@ -102,7 +102,7 @@ For concrete example, check out [beforeLeakFilter](../interfaces/core_src.ILeakF * **Returns**: `void` * **Source**: - * core/src/lib/Types.ts:518 + * core/src/lib/Types.ts:541 ___ @@ -118,7 +118,7 @@ For concrete examples, check out [action](../interfaces/core_src.IScenario.md#ac * **Returns**: `Promise`<`void`\> | no return value * **Source**: - * core/src/lib/Types.ts:597 + * core/src/lib/Types.ts:620 ___ @@ -146,7 +146,7 @@ function leakFilter(node, _snapshot, _leakedNodeIds) { ``` * **Source**: - * core/src/lib/Types.ts:545 + * core/src/lib/Types.ts:568 ___ @@ -232,7 +232,7 @@ const runOptions: RunOptions = { ``` * **Source**: - * core/src/lib/Types.ts:184 + * core/src/lib/Types.ts:207 ___ @@ -255,7 +255,7 @@ and [findReferrers](../interfaces/core_src.IHeapNode.md#findreferrers). * **Returns**: `boolean` | whether the entity passes the predicate check * **Source**: - * core/src/lib/Types.ts:197 + * core/src/lib/Types.ts:220 ___ @@ -288,7 +288,7 @@ function retainerReferenceFilter(edge, _snapshot, _leakedNodeIds) { ``` * **Source**: - * core/src/lib/Types.ts:581 + * core/src/lib/Types.ts:604 ___ @@ -303,7 +303,7 @@ You can retrieve the instance of this type through [getRunMetaInfo](../classes/a | `type` | `string` | type of the memlab run | * **Source**: - * core/src/lib/Types.ts:1186 + * core/src/lib/Types.ts:1209 ___