OProfile, generates statistical profiles of performance in Ubuntu

about OProfile

In the next article we are going to take a look at OProfile. This is a performance profiler for Gnu / Linux. You may be wondering why you would need a tool like this since there are so many Analysis tools which work very well and are available by default on most Gnu / Linux distributions. This is an open source project that includes a statistical profiler for Gnu / Linux systems, capable of create profiles of all running code.

This package of utilities that not only performs your analysis at a deep level. As well saves data and allows us to produce performance reports. These reports provide a wealth of information that can help us debug even the most complex performance problem.

OProfile is a powerful tool that connects to the lowest level available in Gnu / Linux to obtain performance counters and metrics that will provide us with valuable information about our programs. We now have the ability to know precisely what our system is doing and how to improve it (if we have the necessary knowledge). By studying the reports generated by OProfile, we will be able to make data-driven decisions to fine-tune our system.

This application It takes advantage of CPU hardware performance counters to allow profiling of a wide variety of interesting statistics, which can also be used for the basic time spent profile. All code is outlined: hardware and software interrupt handlers, kernel modules, kernel, shared libraries, and applications. We will also have available varias post-profiling tools to convert profile data into human-readable information.

OProfile is not just for developers. In a desktop environment, OProfile can help us track CPU-intensive background tasks or I / O calls that slow down our system and are not immediately apparent. That being said, developers will certainly get the most out of OProfile. For more information about the program, whoever needs it can turn to the project website.

Install OProfile on Ubuntu 17.10

There is a very important note to keep in mind before delving into OProfile. We may not be able to install it in a virtualized environment. If you are running Gnu / Linux within a VirtualBox, VMWare, or similar VM environment, OProfile may not be able to access the performance counters required to collect the data.

Several Gnu / Linux distributions have OProfile in their package management systems. To install this program in our Ubuntu 17.10 we will only have to open a terminal (Ctrl + Alt + T) and write:

sudo apt install oprofile

A simple example

The command "ls»It is probably the one you use the most in your time in front of the console. It just displays a list of files and folders in the current directory. We are going to trace its output by typing in the terminal (Ctrl + Alt + T):

operf ls

sudo operf ls

You will see something similar to the screenshot above. Once the profiler has finished, the terminal will show us the message «profiling done«. These data have been saved in a folder called oprofile_data located in the user's home that can be used to generate a report.

Running the opreport command (without sudo in this case) generates a report similar to the following:

opreport exit

In this example, the default report shows the number of samples when CPU was not in HALT state (in other words, I was actively doing something). kallsyms provides the symbol search used by the profiler, and ld.so y libc.so they are part of the glibc package. The latter is a common library linked to almost all Gnu / Linux executables. Provides basic functionality that developers can use to provide a generic level of cross-system compatibility.

Steps to follow when finished

Once we are done with the report, it is a good idea delete the data folder or save it for future analysis. As in this example we execute the command with sudo, we must delete the folder with sudo.

sudo rm -Rf oprofile_data

It is important to note that although OProfile should not interfere with the operation of your programs, it will create a bit of overhead. Therefore it will slow down the execution of these. Because of this, I don't think it's a good idea to use this program in a production server environment. Unless we are faced with a critical performance issue that needs to be resolved on the spot. Even in this case, you would only use it long enough to find the problem.

If anyone needs more examples of what can be done with this program, you can check the ones from the official website They make available to users.

Uninstall OProfile

We will be able to eliminate this program from our system by typing in the terminal (Ctrl + Alt + T) the following:

sudo apt remove oprofile && sudo apt autoremove

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.