Product SiteDocumentation Site

20.2. Using operf

operf is the recommended profiling mode that does not require initial setup before starting. All settings are specified as command-line options and there is no separate command to start the profiling process. To stop operf, press Ctrl+C. The typical operf command syntax looks as follows:
operf options range command args
Replace options with the desired command-line options to specify your profiling settings. Full set of options is described in operf(1) manual page. Replace range with one of the following:
--system-wide - this setting allows for global profiling, see Using operf in System-wide Mode
--pid=PID - this is to profile a running application, where PID is the process ID of the process you want to profile.
With command and args, you can define a specific command or application to be profiled, and also the input arguments that this command or application requires. Either command, --pid or --system-wide is required, but these cannot be used simultaneously.
When you invoke operf on a command line without setting the range option, data will be collected for the children processes.

Using operf in System-wide Mode

To run operf --system-wide, you need root authority. When finished profiling, you can stop operf with Ctrl+C.
If you run operf --system-wide as a background process (with &), stop it in a controlled manner in order to process the collected profile data. For this purpose, use:
kill -SIGINT operf-PID 
When running operf --system-wide, it is recommended that your current working directory is /root or a subdirectory of /root so that sample data files are not stored in locations accessible by regular users.

20.2.1. Specifying the Kernel

To monitor the kernel, execute the following command:
operf --vmlinux=vmlinux_path
With this option, you can specify a path to a vmlinux file that matches the running kernel. Kernel samples will be attributed to this binary, allowing post-processing tools to attribute samples to the appropriate kernel symbols. If this option is not specified, all kernel samples will be attributed to a pseudo binary named "no-vmlinux".