跳到主要内容
版本:0.82

Systrace

Systrace 是一个标准的基于标记的 Android 性能分析工具(在安装 Android platform-tools 包时会一并安装)。被分析的代码块被开始/结束标记包围,然后在彩色图表格式中可视化。Android SDK 和 React Native 框架都提供可可视化的标准标记。

示例​

Systrace allows you to mark JavaScript (JS) events with a tag and an integer value. Start profiling with an Android profiling tool such as Perfetto or EasyProfiler, then use these markers to identify the events in the captured trace.


参考

方法​

isEnabled()​

React TSX
static isEnabled(): boolean;

beginEvent()​

React TSX
static beginEvent(eventName: string | (() => string), args?: EventArgs);

beginEvent/endEvent 用于在同一调用栈帧内开始并结束性能分析。


endEvent()​

React TSX
static endEvent(args?: EventArgs);

beginAsyncEvent()​

React TSX
static beginAsyncEvent(
eventName: string | (() => string),
args?: EventArgs,
): number;

beginAsyncEvent/endAsyncEvent 用于开始和结束一个性能分析,其结束可能发生在另一个线程或当前栈帧之外。例如,应将返回的 cookie 变量作为输入传递给 endAsyncEvent 调用以结束性能分析。


endAsyncEvent()​

React TSX
static endAsyncEvent(
eventName: EventName,
cookie: number,
args?: EventArgs,
);

counterEvent()​

React TSX
static counterEvent(eventName: string | (() => string), value: number);

将该值注册到 systrace 时间轴上的 profileName。