← 返回命令列表

Linux command

samply 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Profile a command

samply record [path/to/command] [arg1] [arg2]

Set the sampling rate

samply record --rate [1000] [path/to/command]

Record without opening

samply record --save-only --output [profile.json] -- [path/to/command]

Load a previously saved

samply load [path/to/profile.json]

Import

samply import [path/to/perf.data]

Profile a running process

samply record --pid [12345]

Attach to all processes

samply record -a

说明

samply is a sampling profiler that runs on macOS, Linux, and Windows and produces profiles in the Firefox Profiler JSON format. It periodically interrupts the target process, captures one stack trace per thread, and writes the aggregated samples to disk; when recording finishes, samply starts a tiny local web server, opens profiler.firefox.com in your default browser, and the profiler fetches the data and symbols from that server. On macOS and Windows, samply reports both on-CPU and off-CPU samples, so blocking on disk, network, or locks is visible in the flame graph. On Linux it currently reports on-CPU samples only, using the kernel's perf_event_open subsystem (no kernel module or LD_PRELOAD is required). The output is the same JSON format used by Firefox's built-in profiler, so the resulting flame graphs, marker chains, call trees, stack charts, and source views all work out of the box, including across machines: profiles can be shared by uploading them to the public Firefox Profiler instance or by exchanging the JSON file directly.

参数

--rate _hz_
Sampling frequency in samples per second. Default: _1000_.
--duration _seconds_
Stop recording after _seconds_ of wall-clock time.
--save-only
Do not open the browser; just write the profile to disk.
-o, --output _file_
Path to the output profile (default: _profile.json.gz_).
--profile-name _name_
Set the profile name shown in the Firefox Profiler UI.
--port _n_
Port for the local symbol-server (default: _3000_).
--no-open
Save the profile and start the local symbol-server, but do not launch a browser.
--presymbolicate
Resolve symbols at save time and embed them in the profile, making it portable to machines without the original binaries.
--pid _pid_
Profile an already-running process instead of spawning a new one.
-a, --all
Profile every process on the system (system-wide profiling).
--reuse-threads
Keep thread IDs stable across forks; useful for long-running daemons.

FAQ

What is the samply command used for?

samply is a sampling profiler that runs on macOS, Linux, and Windows and produces profiles in the Firefox Profiler JSON format. It periodically interrupts the target process, captures one stack trace per thread, and writes the aggregated samples to disk; when recording finishes, samply starts a tiny local web server, opens profiler.firefox.com in your default browser, and the profiler fetches the data and symbols from that server. On macOS and Windows, samply reports both on-CPU and off-CPU samples, so blocking on disk, network, or locks is visible in the flame graph. On Linux it currently reports on-CPU samples only, using the kernel's perf_event_open subsystem (no kernel module or LD_PRELOAD is required). The output is the same JSON format used by Firefox's built-in profiler, so the resulting flame graphs, marker chains, call trees, stack charts, and source views all work out of the box, including across machines: profiles can be shared by uploading them to the public Firefox Profiler instance or by exchanging the JSON file directly.

How do I run a basic samply example?

Run `samply record [path/to/command] [arg1] [arg2]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --rate _hz_ do in samply?

Sampling frequency in samples per second. Default: _1000_.