Skip to Content
开发文档ContributingECMAScript MinifierProfiling

常见分析步骤

¥Common Profiling Steps

如果你在内存分配方面遇到 SWC 最小化问题并且你使用的是 Mac,则可以使用 ddt 来分析内存使用情况。此外,许多步骤对于任何类型的分析都是通用的。

¥If you have a problem with SWC minifier about memory allocation and you are on mac, you can use ddt to profile the memory usage. Also, many steps are common to any kind of profiling.

步骤 1.准备输入

¥Step 1. Prepare the inputs

如果你想检查示例目录中的输入,你可以查看 https://github.com/kdy1/swc-minifier-inputs。这些输入文件是从 github 上公开提供的真实 next.js 项目中提取的。详细信息请参见 debugging-nextjs-app

¥If you want to check the example directory for inputs, you can take a look at https://github.com/kdy1/swc-minifier-inputs. These input files are extracted from real next.js projects publicly available on github. See debugging-nextjs-app for more details.

在此示例中,我们假设上面的链接已克隆到 ~/projects/minifier-inputs。(即 git clone https://github.com/kdy1/swc-minifier-inputs.git ~/projects/minifier-inputs

¥In this example, we will assume that the link above is cloned to ~/projects/minifier-inputs. (i.e. git clone https://github.com/kdy1/swc-minifier-inputs.git ~/projects/minifier-inputs)

将以下命令中的 ~/projects/minifier-inputs 替换为包含输入文件的目录。它可以是文件或包含输入文件的目录。所有 .js 文件都将被最小化,而不会将结果写入磁盘。

¥Replace ~/projects/minifier-inputs in the commands below with the directory containing your input files. It can be either a file or a directory containing the input files. All .js files will be minified, without writing the result to the disk.

步骤 2.克隆存储库

¥Step 2. Clone the repository

git clone https://github.com/swc-project/swc.git cd ./swc/crates/swc_ecma_minifier

分析时间使用情况

¥Profiling Time Usage

步骤 3.运行分析器

¥Step 3. Run the profiler

你有两个选择。一种是使用跨平台的 samply,另一种是使用仅在 Mac 上可用的 XCode Instruments。

¥You have two options. One is to use samply, which is cross-platform, and the other is to use XCode Instruments, which is only available on mac.

使用 samply

¥Using samply

CARGO_PROFILE_RELEASE_DEBUG=1 RUST_LOG=off ddt profile samply cargo --release --features concurrent --example minify-all -- ~/projects/minifier-inputs to the directory containing your input files. It can be either a file or a directory containing the input files. All .js files will be minified (without writing the result to the disk)

分析完成后,这将在你的浏览器中打开一个选项卡。

¥This will open a tab in your browser once the profiling is done.

使用 XCode 工具

¥Using XCode Instruments

CARGO_PROFILE_RELEASE_DEBUG=1 RUST_LOG=off ddt profile instruments cargo -t time --release --features concurrent --example minify-all -- ~/projects/minifier-inputs to the directory containing your input files. It can be either a file or a directory containing the input files. All .js files will be minified (without writing the result to the disk)

分析完成后,这将打开 Instruments 应用。

¥This will open the Instruments app once the profiling is done.

分析内存使用情况

¥Profiling Memory Usage

步骤 3.运行分析器

¥Step 3. Run the profiler

运行分析器的命令如下:

¥The command to run the profiler is as follows:

CARGO_PROFILE_RELEASE_DEBUG=1 RUST_LOG=off ddt profile instruments cargo -t 'Memory' --release --features concurrent --example minify-all -- ~/projects/minifier-inputs to the directory containing your input files. It can be either a file or a directory containing the input files. All .js files will be minified (without writing the result to the disk)

分析完成后,这将打开 Instruments 应用。

¥This will open the Instruments app once the profiling is done.


Last updated on
SWC v1.12 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站