跳到主要内容
版本:Next

Systrace

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

示例

Systrace 允许你用标签和整数值标记 JavaScript(JS)事件。在 EasyProfiler 中捕获非定时的 JS 事件。


参考

方法

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 变量应当作为 input 传入 endAsyncEvent 调用,以结束该性能分析。


endAsyncEvent()

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

counterEvent()

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

将值注册到 systrace 时间线上对应的 profileName。