A spinning beachball tells me nothing. I would like to know where the app is stuck, and macOS has a built-in way to look inside.
According to the man page, sample suspends a process at set intervals, records the call stacks of all its threads, and resumes it. At the end it condenses the data into a text call tree. Give it a process ID or part of the name:
sample Safari 5 -file ~/Desktop/safari-sample.txt
The first number is the duration in seconds, and the default is 10. An optional second number sets the interval in milliseconds, with a default of 1. Without -file the report goes to stdout and is also saved in /tmp, in a file named after the app, the date and the time.
A few more options from the same page:
-waitwaits for the process to exist and then starts sampling, which lets you sample from an app’s launch-mayDiegrabs the symbol locations immediately, in case the app exits or crashes during sampling-fullPathsshows full source paths where debug information is available-eopens the output in TextEdit when sampling is done
The call tree shows which functions were on the stack and how they were called. The man page says longer durations give better data, but can also be confusing if the app does many different things in that time.
The caveat: sampling only looks at the state of the program at the sampling points, so it can miss functions that were not running at those moments. For a graphical view, the page points to the Time Profiler in Instruments. Also read the report before you send it to anyone, because it can contain file paths from the app you sampled.
Further reading: sample man page