最近火狐会莫名其妙得导致 CPU 100%, 需要探查一下原因. 以下内容来自Firefox Profiler

  1. Capture a profile with perf.
  2. Convert it into a text form.
  3. Load the text file in profiler.firefox.com.

Step 1: Capture the profile

To attach to an existing process with PID , use:

perf record -g -F 999 -p <pid>
# Stop with Ctrl+C once you've collected enough

To launch a new process under the profiler, use

perf record -g -F 999 program options
# Stop with Ctrl+C once you've collected enough

For Firefox, this would be:

perf record -g -F 999 firefox -P profile -no-remote

The perf record command writes the profile into a file called perf.data in the current directory.

Step 2: Convert the profile

After exiting perf, convert the perf data into something the Firefox Profiler can read:

perf script -F +pid > /tmp/test.perf

The perf script command takes the perf.data file that was written by the perf record command as its implicit input.

Step 3: View the profile in profiler.firefox.com

You can now load the .perf file into profiler.firefox.com: just tell the Firefox Profiler to open the file and it should be auto-identified and loaded. Note that there will be no markers and no categories. Many stack frames will say [unknown]. There will be no JavaScript stacks, unless you do extra work as described below. Symbols might be mangled.