# Profiling

# How to profile your system

When Sysprof profiles your system, it records stack information for all applications executing, including the Linux kernel. This can sometimes be confusing if you only want to look at a single process. If your application does not interact much with the host system, you may have more success by using Sysprof to spawn a new process.

To profile your entire system, ensure the target button is set to All Processes and click Record.

At this point, you may be asked to authorize access to profile the system. This is required as the Linux kernel's perf implementation requires root to perform whole-system profiling.

During the profiling session, you will see the number of seconds the profile has been active. Clicking the Record button again will stop the profiling session. Afterwhich, the callgraph will be displayed.

If you find that the sysprof application is showing up in your profiling callgraph, you might consider recording the profiling session with sysprof-cli. This is a command line program that will capture your profiling session to disk to be viewed at a later time.

See interpreting results for more guidance.

# Profile a new process

Often times, you may need to spawn a new process to profile. First, select the Application button next at the top of the recording window. Fill in your command and working directory, and optionally specify any environment variables you need. Your process will be started when recording begins.

If you are spawning a process that requires access to your current display, such as a GTK+ application, you will want to make sure Inherit current environment is set.

# Profiling with the sysprof-cli command line tool

For minimal overhead, you might consider using the sysprof-cli command line tool. When run without any arguments, it will record your entire system and save the output to capture.syscap. This file can be opened with the Sysprof application to view the callgraph.

If you would like to spawn a new process, use sysprof-cli -- 'command' to specify a command to be launched. The command will inherit the current environment.

# Interpreting results

The profiling results in Sysprof are split into three sections. On the top left is a list of all the functions profiled. They are sorted by how often they were called during the recording.

It is important to note that the amount of time spent in each function is not captured. That would require a tracing profiler to accurately record. The percentage is calculated by determining how often that function showed up in the current stacktrace when a sample was recorded.

After selecting a function from the functions list, all of the recorded callers of that function will be displayed on the bottom left. They are also sorted by the percentage of samples that included that function in the stacktrace.

On the right, are all of the decendants of a selected function. You can select a function either from the functions list, or the callers list.

If you see - - Context Switch - - in your results, that means that the application transitioned into or from the Linux kernel. There can be many reasons for this such as a syscall or signal.