mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a0f56adb07
Summary: This refactors the systrace module to: 1) Migrate it to ESM 2) Fix the typing of certain parameters (e.g.: `eventName` and `cookie` shouldn't be optional) 2) Fix TypeScript definitions 3) Add inline documentation for methods 4) Add args (metadata) to all methods where it's supported in fbsystrace (`endEvent` and `endAsyncEvent`). 5) Make `setEnabled` a no-op. The only place where this method is called is from native, when starting a profile session. The problem is that implementation for Systrace in OSS (https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/systrace/Systrace.java#L40-L42) doesn't support listeners, so this wouldn't work correctly there. It also doesn't get called with Venice, so instead of fixing it for Venice with the same Meta-internal behavior, I decided to fix it for everyone with the synchronous method. I'm not considering this a change in the public API of systrace because this module has been broken in OSS for ages and I'm assuming no one's using it at this point. Changelog: [internal] Reviewed By: rshest Differential Revision: D40095842 fbshipit-source-id: fee41b2b7ae23aefe059e390c55d139db75247c5
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
/**
|
|
* 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
|
|
*/
|
|
|
|
type EventName = string | (() => string);
|
|
type EventArgs = {[key: string]: string} | void | null;
|
|
|
|
/**
|
|
* Indicates if the application is currently being traced.
|
|
*
|
|
* Calling methods on this module when the application isn't being traced is
|
|
* cheap, but this method can be used to avoid computing expensive values for
|
|
* those functions.
|
|
*
|
|
* @example
|
|
* if (Systrace.isEnabled()) {
|
|
* const expensiveArgs = computeExpensiveArgs();
|
|
* Systrace.beginEvent('myEvent', expensiveArgs);
|
|
* }
|
|
*/
|
|
export function isEnabled(): boolean;
|
|
|
|
/**
|
|
* @deprecated This function is now a no-op but it's left for backwards
|
|
* compatibility. `isEnabled` will now synchronously check if we're actively
|
|
* profiling or not. This is necessary because we don't have callbacks to know
|
|
* when profiling has started/stopped on Android APIs.
|
|
*/
|
|
export function setEnabled(_doEnable: boolean): void;
|
|
|
|
/**
|
|
* Marks the start of a synchronous event that should end in the same stack
|
|
* frame. The end of this event should be marked using the `endEvent` function.
|
|
*/
|
|
export function beginEvent(eventName: EventName, args?: EventArgs): void;
|
|
|
|
/**
|
|
* Marks the end of a synchronous event started in the same stack frame.
|
|
*/
|
|
export function endEvent(args?: EventArgs): void;
|
|
|
|
/**
|
|
* Marks the start of a potentially asynchronous event. The end of this event
|
|
* should be marked calling the `endAsyncEvent` function with the cookie
|
|
* returned by this function.
|
|
*/
|
|
export function beginAsyncEvent(eventName: EventName, args?: EventArgs): number;
|
|
|
|
/**
|
|
* Registers a new value for a counter event.
|
|
*/
|
|
export function endAsyncEvent(
|
|
eventName: EventName,
|
|
cookie: number,
|
|
args?: EventArgs,
|
|
): void;
|
|
|
|
/**
|
|
* counterEvent registers the value to the eventName on the systrace timeline
|
|
**/
|
|
export function counterEvent(eventName: EventName, value: number): void;
|