-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli(feat): support diffing memory leaks from single heap snapshots
Summary: Add support for diffing memory leak clusters based on a single heap snapshot from the control or treatment group: Example: diff heap snapshots from a treatment working directory vs a single heap snapshot file location for a control run ``` memlab diff-leaks --treatment-work-dir /tmp/memlab-test/ --control-snapshot /tmp/memlab-test/data/cur/memlab-plugin.heapsnapshot ``` Or we can use snapshot options only: ``` memlab diff-leaks --treatment-snapshot /tmp/treatment.heapsnapshot --control-snapshot /tmp/control.heapsnapshot ``` Reviewed By: tulga1970 Differential Revision: D52713530 fbshipit-source-id: 03ece7de7ecc8a3f5fb22bc2c5327a234a89eb2c
- Loading branch information
1 parent
fb6c134
commit ec905b1
Showing
9 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/cli/src/options/experiment/SetControlSnapshotOption.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* 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 {ParsedArgs} from 'minimist'; | ||
import {MemLabConfig, Nullable} from '@memlab/core'; | ||
|
||
import {BaseOption, info} from '@memlab/core'; | ||
import optionConstants from '../lib/OptionConstant'; | ||
import { | ||
createTransientWorkDirFromSingleHeapSnapshot, | ||
validateHeapSnapshotFileOrThrow, | ||
} from './utils/ExperimentOptionsUtils'; | ||
|
||
export default class SetControlWorkDirOption extends BaseOption { | ||
getOptionName(): string { | ||
return optionConstants.optionNames.CONTROL_SNAPSHOT; | ||
} | ||
|
||
getDescription(): string { | ||
return 'set the single (target) snapshot of control run'; | ||
} | ||
|
||
async parse( | ||
config: MemLabConfig, | ||
args: ParsedArgs, | ||
): Promise<{controlWorkDirs?: Nullable<string[]>}> { | ||
let dirs = null; | ||
const optionName = this.getOptionName(); | ||
if (optionName in args) { | ||
const snapshotFile = validateHeapSnapshotFileOrThrow(args[optionName]); | ||
dirs = [createTransientWorkDirFromSingleHeapSnapshot(snapshotFile)]; | ||
} | ||
if (config.verbose && dirs && dirs[0]) { | ||
info.lowLevel(`creating control working directory: ${dirs[0]}`); | ||
} | ||
return {controlWorkDirs: dirs}; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/cli/src/options/experiment/SetTreatmentSnapshotOption.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* 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 {ParsedArgs} from 'minimist'; | ||
import {MemLabConfig, Nullable} from '@memlab/core'; | ||
|
||
import {BaseOption, info} from '@memlab/core'; | ||
import optionConstants from '../lib/OptionConstant'; | ||
import { | ||
createTransientWorkDirFromSingleHeapSnapshot, | ||
validateHeapSnapshotFileOrThrow, | ||
} from './utils/ExperimentOptionsUtils'; | ||
|
||
export default class SetTreatmentWorkDirOption extends BaseOption { | ||
getOptionName(): string { | ||
return optionConstants.optionNames.TREATMENT_SNAPSHOT; | ||
} | ||
|
||
getDescription(): string { | ||
return 'set the single (target) snapshot of treatment run'; | ||
} | ||
|
||
async parse( | ||
config: MemLabConfig, | ||
args: ParsedArgs, | ||
): Promise<{treatmentWorkDirs?: Nullable<string[]>}> { | ||
let dirs = null; | ||
const optionName = this.getOptionName(); | ||
if (optionName in args) { | ||
const snapshotFile = validateHeapSnapshotFileOrThrow(args[optionName]); | ||
dirs = [createTransientWorkDirFromSingleHeapSnapshot(snapshotFile)]; | ||
} | ||
if (config.verbose && dirs && dirs[0]) { | ||
info.lowLevel(`creating treatment working directory: ${dirs[0]}`); | ||
} | ||
return {treatmentWorkDirs: dirs}; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/cli/src/options/experiment/utils/ExperimentOptionsUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* 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 {AnyValue, MemLabConfig, fileManager, utils} from '@memlab/core'; | ||
import {existsSync} from 'fs-extra'; | ||
|
||
export function validateHeapSnapshotFileOrThrow(file: AnyValue): string { | ||
if (typeof file !== 'string') { | ||
throw utils.haltOrThrow( | ||
`Heap snapshot file must be a string, but got ${typeof file}`, | ||
); | ||
} | ||
if (!file.endsWith('.heapsnapshot')) { | ||
throw utils.haltOrThrow( | ||
`Heap snapshot file must end with .heapsnapshot, but got ${file}`, | ||
); | ||
} | ||
if (!existsSync(file)) { | ||
throw utils.haltOrThrow(`Heap snapshot file ${file} does not exist`); | ||
} | ||
return file; | ||
} | ||
|
||
export function createTransientWorkDirFromSingleHeapSnapshot( | ||
file: string, | ||
): string { | ||
const config = MemLabConfig.resetConfigWithTransientDir(); | ||
fileManager.createOrOverrideVisitOrderMetaFileForExternalSnapshot(file); | ||
return config.workDir; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters