OProfile can collect event information for the whole system in the background with very little overhead.
OProfile mainly consists of the opcontrol shell script and the oprofiled daemon.
The opcontrol script is used for configuring, starting, and stopping a profiling session, which are then recorded into sample files by oprofiled. And opreport is used to analyze these results.
Profiling setup parameters that you specify using opcontrol are cached in
Creating profile Report:
Setup:
If you don't want to profile kernal we need to exclude it from the oprofile.
to do this we need to set --no-vimlinux to tell OProfile you don't have a
Run:
Now we need to start the daemon(oprofiled) which will collect the profile data.
Collect:
To collect that session profile data you can dump it using the command
we can even save the session to the different files using --save flag
opcontrol --save <session_dir_name1>
opcontrol --save <session_dir_name2>
Stop:
When you want to stop profiling, you can do so with :
to kill the daemon do this
Analyzing profile data:
Comparing two profiles:
Often, we'd like to compare two profiles. when analyzing the performance of an application, we'd like to make code changes and examine the effect of the change. This is supported in opreport by giving a profile specification that identifies two different profiles.
or
opreport /opt/bin/my_test_pgn { ./saved_session_1 } { ./current_session }
OProfile mainly consists of the opcontrol shell script and the oprofiled daemon.
The opcontrol script is used for configuring, starting, and stopping a profiling session, which are then recorded into sample files by oprofiled. And opreport is used to analyze these results.
Profiling setup parameters that you specify using opcontrol are cached in
/root/.oprofile/daemonrc
. Subsequent runs of opcontrol --start
will continue to use these cached values until you override them with new values.Creating profile Report:
Setup:
If you don't want to profile kernal we need to exclude it from the oprofile.
to do this we need to set --no-vimlinux to tell OProfile you don't have a
vmlinux
fileopcontrol --no-vmlinuxBy default profile sample data is written to /var/lib/oprofile/samples. we can change this path using session-dir flag.
opcontrol --no-vmlinux --session-dir=/root/tmpsession
Run:
Now we need to start the daemon(oprofiled) which will collect the profile data.
opcontrol --startRun your program. if it is an infinite process let it run in background and profile for as long as a time as possible.
Collect:
To collect that session profile data you can dump it using the command
opcontrol --dumpThis ensures that any profile data collected by the oprofiled daemon has been flusehd to disk.(default: /var/lib/oprofile/samples)
we can even save the session to the different files using --save flag
opcontrol --save <session_dir_name1>
opcontrol --save <session_dir_name2>
Stop:
When you want to stop profiling, you can do so with :
opcontrol --stopBut this will not kill the daemon this will give SIGHUP to oprofiled to stop collecting profile data.
to kill the daemon do this
opcontrol --shutdown
Analyzing profile data:
opreport is the tool that can be used to analyze the collected profile data.
opreport --long-filenames will show the whole summary of the system.
to analyze particular process during the specific time or session use
opreport -lg <process path> session:<saved session>
opreport -lg /opt/bin/my_test_pgm session:saved_session_dir
-g : Show source file and line for each symbol
-l : List per-symbol information instead of a binary image summary
Often, we'd like to compare two profiles. when analyzing the performance of an application, we'd like to make code changes and examine the effect of the change. This is supported in opreport by giving a profile specification that identifies two different profiles.
opreport <shared-spec> { <first-profile> } { <second-profile> }opreport /opt/bin/my_test_pgn { ./saved_session_1 } {} #empty brasses refers to current session.
or
opreport /opt/bin/my_test_pgn { ./saved_session_1 } { ./current_session }
This will create a %diff report.