跳到主要内容

Systrace

Systrace 是一个标准的 Android 基于标记的性能分析工具(当你安装 Android 平台工具包时会一并安装)。被分析的代码块由开始/结束标记包围,这些标记随后会以多彩图表的形式可视化。Android SDK 和 React Native 框架都提供了你可以标准化的标记。

示例

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


参考

方法

isEnabled()

tsx
static isEnabled(): boolean;

beginEvent()

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

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


endEvent()

tsx
static endEvent(args?: EventArgs);

beginAsyncEvent()

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

beginAsyncEvent/endAsyncEvent 用于启动并结束性能分析,其中结束操作可以在另一个线程上或当前堆栈帧之外发生,例如,await 返回的 cookie 变量应作为 endAsyncEvent 调用的输入来结束性能分析。


endAsyncEvent()

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

counterEvent()

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

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