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 中。