-
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.
Summary: PR changes: * Adds `--output [text/json]` CLI option which sets the `outputFormat` config flag * When output is set to JSON, it implies the `--sc` option and directs all logs to `stderr`. This allows to easily capture a clean JSON output using `memlab > result.json`. * Adds `getJSONifyableObject` to the interfaces of nodes and edges * Updates `printNodeListInTerminal` and `printReferencesInTerminal` to support JSON output * Updates `CollectionsHoldingStaleAnalysis` to support JSON output Open questions: * Should all analyses support JSON output? I only added the ones I need at the moment. * The output from `getJSONifyableObject` has inconsistent casing (e.g. snake `self_size` vs. camel `incomingEdgeCount`). Is it a breaking change to change this so it's all the same? Which case is preferrred? Fixes #127 Pull Request resolved: #128 Reviewed By: twobassdrum Differential Revision: D61724639 Pulled By: JacksonGL fbshipit-source-id: 13a056be1c421999ffbd988ee5f85026d66c860d
- Loading branch information
1 parent
88bce92
commit d2ce836
Showing
18 changed files
with
378 additions
and
115 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
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
48 changes: 48 additions & 0 deletions
48
packages/heap-analysis/src/options/HeapAnalysisOutputOption.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,48 @@ | ||
/** | ||
* 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, OutputFormat, utils} from '@memlab/core'; | ||
import {BaseOption} from '@memlab/core'; | ||
|
||
export default class HeapAnalysisOutputOption extends BaseOption { | ||
getOptionName(): string { | ||
return 'output'; | ||
} | ||
|
||
getDescription(): string { | ||
return 'specify output format of the analysis (defaults to text)'; | ||
} | ||
|
||
getExampleValues(): string[] { | ||
return ['text', 'json']; | ||
} | ||
|
||
async parse(config: MemLabConfig, args: ParsedArgs): Promise<void> { | ||
const name = this.getOptionName(); | ||
const format = `${args[name]}` ?? 'text'; | ||
config.outputFormat = HeapAnalysisOutputOption.parseOutputFormat(format); | ||
if (config.outputFormat === OutputFormat.Json) { | ||
config.isContinuousTest = true; | ||
} | ||
} | ||
|
||
private static parseOutputFormat(s: string): OutputFormat { | ||
switch (s.toLowerCase()) { | ||
case 'text': | ||
return OutputFormat.Text; | ||
case 'json': | ||
return OutputFormat.Json; | ||
default: | ||
utils.haltOrThrow('Invalid output format, valid output: text, json'); | ||
return OutputFormat.Text; | ||
} | ||
} | ||
} |
Oops, something went wrong.