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。