mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52827 Changelog: [internal] This adds **support for creating Hermes/JS sampling profiler traces in Fantom**, which is especially useful when running benchmarks. Usage: ``` FANTOM_PROFILE_JS=1 yarn fantom Animated-benchmark ``` Output: {F1980642216} After this, the trace is fully symbolicated. Can be opened directly in Google Chrome: {F1980642229} Or in the built-in viewer in VSCode: {F1980642242} {F1980642240} {F1980642241} When collapsing frames in the Flame Chart viewer in VSCode, we can quickly identify opportunities for optimizations. This also supports multi-config environments. In that case, trace file names are created using a short representation of the configuration. User guide for benchmarks in Fantom, including how to use this, will be done in a future diff. NOTE: This still doesn't work in OSS because we don't support optimized mode there. In dev mode, there's a segmentation fault coming from this line: `hermesRuntime->sampledTraceToStreamInDevToolsFormat(fileStream)` Reviewed By: sammy-SC Differential Revision: D78905646 fbshipit-source-id: 382ddd5034db601309bd118cedde2fe0d57fde98
83 lines
2.3 KiB
JavaScript
83 lines
2.3 KiB
JavaScript
/**
|
|
* 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.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import type {SnapshotConfig} from '../runtime/snapshotContext';
|
|
import type {FantomRuntimeConstants} from '../src/Constants';
|
|
import type {FantomTestConfig} from './getFantomTestConfigs';
|
|
|
|
import * as EnvironmentOptions from './EnvironmentOptions';
|
|
import formatFantomConfig from './formatFantomConfig';
|
|
|
|
module.exports = function entrypointTemplate({
|
|
testPath,
|
|
setupModulePath,
|
|
featureFlagsModulePath,
|
|
testConfig,
|
|
snapshotConfig,
|
|
jsTraceOutputPath,
|
|
}: {
|
|
testPath: string,
|
|
setupModulePath: string,
|
|
featureFlagsModulePath: string,
|
|
testConfig: FantomTestConfig,
|
|
snapshotConfig: SnapshotConfig,
|
|
jsTraceOutputPath: ?string,
|
|
}): string {
|
|
const constants: FantomRuntimeConstants = {
|
|
isOSS: EnvironmentOptions.isOSS,
|
|
isRunningFromCI: EnvironmentOptions.isCI,
|
|
forceTestModeForBenchmarks: EnvironmentOptions.forceTestModeForBenchmarks,
|
|
fantomConfigSummary: formatFantomConfig(testConfig),
|
|
jsTraceOutputPath,
|
|
};
|
|
|
|
return `/**
|
|
* 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.
|
|
*
|
|
* ${'@'}generated
|
|
* @noformat
|
|
* @noflow
|
|
*/
|
|
|
|
import {registerTest} from '${setupModulePath}';
|
|
import {setConstants} from '@react-native/fantom/src/Constants';
|
|
|
|
${
|
|
Object.keys(testConfig.flags.jsOnly).length > 0
|
|
? `import * as ReactNativeFeatureFlags from '${featureFlagsModulePath}';
|
|
|
|
ReactNativeFeatureFlags.override({
|
|
${Object.entries(testConfig.flags.jsOnly)
|
|
.map(([name, value]) => ` ${name}: () => ${JSON.stringify(value)},`)
|
|
.join('\n')}
|
|
});`
|
|
: ''
|
|
}
|
|
${
|
|
Object.keys(testConfig.flags.reactInternal).length > 0
|
|
? `import ReactNativeInternalFeatureFlags from 'ReactNativeInternalFeatureFlags';
|
|
${Object.entries(testConfig.flags.reactInternal)
|
|
.map(
|
|
([name, value]) =>
|
|
`ReactNativeInternalFeatureFlags.${name} = ${JSON.stringify(value)};`,
|
|
)
|
|
.join('\n')}`
|
|
: ''
|
|
}
|
|
|
|
setConstants(${JSON.stringify(constants)});
|
|
|
|
registerTest(() => require('${testPath}'), ${JSON.stringify(snapshotConfig)});
|
|
`;
|
|
};
|