Appearance
性能分析
¥Profiling
CPU 分析(示例)
¥CPU profiling (samply)
设置
¥Setup
首先,你需要安装 samply。你可以使用以下命令安装它:
¥First you need to install samply. You can install it with:
bash
cargo binstall samply警告
Samply 在 macOS 上运行效果不佳。我们建议使用 Xcode Instruments。
¥Samply does not work well on macOS. We recommend using Xcode Instruments instead.
构建
¥Build
要使用 samply 所需的信息构建 Rolldown,你需要使用以下命令构建:
¥To build Rolldown with the information required by samply, you need to build it with:
shell
just build-rolldown-profile性能分析
¥Profiling
构建后,你可以使用以下命令运行 Rolldown 来分析 CPU 使用情况:
¥After building, you can run Rolldown with the following command to profile CPU usage:
shell
samply record node ./path/to/script-rolldown-is-used.js如果你还想分析 JavaScript 部分,可以将 所需参数 传递给 Node:
¥If you want to profile the JavaScript part as well, you can pass the required flags to Node:
shell
samply record node --perf-prof --perf-basic-prof --perf-prof-unwinding-info --interpreted-frames-native-stack ./path/to/script-rolldown-is-used.jsCPU 分析 (Xcode Instruments)
¥CPU profiling (Xcode Instruments)
设置
¥Setup
首先,请确保你已安装 Xcode。
¥First, make sure you have Xcode installed.
构建
¥Build
要使用 Xcode Instruments 所需的信息构建 Rolldown,你需要使用以下命令构建:
¥To build Rolldown with the information required by Xcode Instruments, you need to build it with:
shell
just build-rolldown-profile性能分析
¥Profiling
构建后,你可以使用以下命令运行 Rolldown 来分析 CPU 使用情况:
¥After building, you can run Rolldown with the following command to profile CPU usage:
shell
xctrace record --template "Time Profile" --output . --launch -- node ./path/to/script-rolldown-is-used.js然后将打印输出文件路径。你可以使用以下命令打开文件:
¥then the output file path will be printed. You can open the file with:
shell
open ./Launch_node_yyyy-mm-dd_hh.mm.ss_hash.trace内存分析
¥Memory profiling
要分析内存使用情况,你可以使用 heaptrack。
¥To profile memory usage, you can use heaptrack.
设置
¥Setup
首先,你需要安装 heaptrack 和 heaptrack-gui。如果你使用的是 Ubuntu,你可以使用以下方式安装它:
¥First you need to install heaptrack and heaptrack-gui. If you are using Ubuntu, you can install it with:
bash
sudo apt install heaptrack heaptrack-gui警告
heaptrack 仅支持 Linux。它在 WSL 上运行良好。
¥heaptrack only supports Linux. It works fine on WSL.
构建
¥Build
要使用 heaptrack 所需的信息构建 Rolldown,你需要使用以下命令构建:
¥To build Rolldown with the information required by heaptrack, you need to build it with:
shell
just build-rolldown-memory-profile性能分析
¥Profiling
构建后,你可以使用以下命令运行 Rolldown 来分析内存使用情况:
¥After building, you can run Rolldown with the following command to profile memory usage:
shell
heaptrack node ./path/to/script-rolldown-is-used.js使用 asdf 或其他使用 shim 的版本管理器?
在这种情况下,你可能需要使用 Node 二进制文件的实际路径。例如,如果你使用的是 asdf,则可以使用以下命令运行它:
¥In that case, you may need to use the actual path to the Node binary. For example, if you are using asdf, you can run it with:
shell
heaptrack $(asdf which node) ./path/to/script-rolldown-is-used.js脚本运行完成后,heaptrack GUI 将自动打开。
¥The heaptrack GUI will open automatically after the script finishes running.
