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 用于开始并结束一次性能分析,结束操作可以发生在线程之外或当前栈帧外,例如 await。返回的 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 注册该值。