tracing
is used to record the internal processes of Rspack compilation, which can be used for performance analysis as well as narrow down the location of a bug.
Tracing can be enabled in two ways:
@rspack/cli
or Rsbuild: Enable it by setting the RSPACK_PROFILE
environment variable@rspack/core
: Enable it through rspack.experiments.globalTrace.register
and rspack.experiments.globalTrace.cleanup
. You can check how we implement RSPACK_PROFILE
in @rspack/cli
for more information.The generated trace.json
file can be viewed and analyzed in ui.perfetto.dev.
Rspack supports two types of layers: chrome
and logger
:
chrome
: The default value, generates a trace.json file conforming to the chrome trace event
format, which can be exported to perfetto for complex performance analysislogger
: Outputs logs directly to the terminal, suitable for simple log analysis or viewing compilation processes in CI environmentsYou can specify the layer through the RSPACK_TRACE_LAYER
environment variable:
You can specify the output location for traces:
logger
layer is stdout
chrome
layer is trace.json
You can customize the output location through the RSPACK_TRACE_OUTPUT
environment variable:
You can configure the data to be filtered through RSPACK_PROFILE
. Rspack provides two preset options:
RSPACK_PROFILE=OVERVIEW
: The default value, only shows the core build process, generating a smaller JSON fileRSPACK_PROFILE=ALL
: Includes all trace events, used for more complex analysis, generating a larger JSON fileApart from the presets, other strings will be passed directly to Env Filter, supporting more complex filtering strategies:
The supported tracing levels are: TRACE
, DEBUG
, INFO
, WARN
, and ERROR
. You can filter by level:
EnvFilter supports mixed use of multiple filtering conditions to implement more complex filtering strategies: