Glossary/When something goes wrong

Sample Process

Also: sample an app, process sample

Quick answer

Sample Process is an Activity Monitor tool that records what a selected process is doing over a few seconds and produces a text report of where its threads spend their time. Developers use these reports to find why an app is slow, busy, or hung.

Apple describes Sample Process as creating a report on a selected process over a period of 3 seconds. The report lists each thread and the functions it was running, with counts showing how often each one appeared.

You do not need to read the report yourself. It is most useful when an app is stuck or using a lot of CPU and you want to send the developer something concrete.

How to sample a process in Activity Monitor

Select the process, then click the More button (the three dots) at the top of the window and choose Sample Process. You can also double-click the process and click Sample in the window that opens.

When the report appears, you can save it as a text file and attach it to a bug report or support request.

How to sample a process from Terminal

Run sample <PID> 5 to sample a process for 5 seconds. You can use part of the process name instead of the PID. The report is printed and saved to a file, and the path is shown when it finishes.

How to read a sample report

The report starts with a header: the process name and PID, its path, its parent process, the code type, and the macOS version. The part that matters comes next, under Call graph.

The call graph lists each thread. The main thread, the one that handles clicks and key presses, is labeled com.apple.main-thread. Under each thread, functions are indented to show which function called which. The number at the start of a line is how many times that function was on the stack when a sample was taken.

  • Follow the lines with the largest numbers down to the deepest indent. That is where the thread spent most of its time.
  • If the deepest lines on the main thread are waiting calls such as mach_msg, __psynch_cvwait or __semwait_signal, the thread was blocked waiting on something else.
  • If the deepest lines are the app's own functions with large counts, the thread was busy doing work.
  • The "Sort by top of stack" section near the end lists the functions that were running most often, which is a quick summary of the same data.
  • The Binary Images list at the end names the frameworks and libraries loaded in the process.

How to save a sample to a file from Terminal

The sample command gives you more control than Activity Monitor. Its default length is 10 seconds, and you can change it.

  1. Open Terminal from Applications > Utilities.
  2. Find the process ID with pgrep -lx Safari, replacing Safari with the process name.
  3. Run sample <PID> 10 -file ~/Desktop/sample.txt while the problem is happening.
  4. Open the file on your Desktop, or attach it to a bug report.

When a sample helps and when it does not

A sample is a snapshot of one process. Use it when you already know which app is the problem.

  • Helpful: an app is frozen, one process keeps a high % CPU, or an app is slow at a specific task you can repeat.
  • Less helpful: the whole Mac is slow and you do not know why. A spindump, which covers every process, fits that better.
  • Not helpful: the problem has already passed. A sample only shows what happened while it ran.

How to send a sample to a developer

A sample on its own is useful, but a short note makes it much easier to act on.

  1. Take the sample while the app is frozen or busy, not after it recovers.
  2. Save the report as a text file instead of copying part of it. Developers need the whole call graph and the Binary Images list.
  3. Write down what you were doing when the problem started, such as the file you opened or the button you clicked.
  4. Include the app's version and your macOS version. Both also appear in the report header, next to Version and OS Version.
  5. Send it through the app's support page or bug tracker, or to Apple through Feedback Assistant if the app is from Apple.

Questions people ask

What does Sample Process do in Activity Monitor?

It records what a process is doing for about 3 seconds and shows a report of its threads and the code they were running. Developers use it to diagnose hangs and high CPU.

Is it safe to sample a process?

Yes. Sampling only observes the process. It does not change or stop it.

When should I sample a process?

Sample while the problem is happening, such as when an app is frozen or using a lot of CPU. A sample taken after it recovers will not show the cause.

How long does Sample Process take?

In Activity Monitor it records about 3 seconds. The `sample` command in Terminal records 10 seconds by default, or the number of seconds you pass.

Does a sample report contain personal information?

It contains the process name, file paths and loaded libraries, and paths can include your user name. Read it before posting it anywhere public.

Why does the sample show question marks instead of function names?

Symbol names were not available for those parts of the app. The developer can still match the addresses to their code, so send the report as it is.

Related

Looking for something better than Activity Monitor? See the best Activity Monitor alternatives for Mac, or browse every term in the glossary.