Difference between revisions of "ProfilingWesnoth"
From The Battle for Wesnoth Wiki
Pentarctagon (talk | contribs) (→gperftools) |
Pentarctagon (talk | contribs) (→perf) |
||
Line 26: | Line 26: | ||
=== perf === | === perf === | ||
+ | To use [https://perf.wiki.kernel.org/index.php/Main_Page perf]: | ||
+ | # Install the packages <code>linux-tools-common</code> and <code>linux-tools-<kernel version></code>, ie linux-tools-5.8.0-55-generic. | ||
+ | # Run <code>perf record <executable></code>. To do this you will need to either: | ||
+ | ## Run the executable as root | ||
+ | ## Switch to root and run <code>echo 2 > /proc/sys/kernel/perf_event_paranoid</code> | ||
+ | ## Create a new group that has rights to use perf and add your user to it, ie: | ||
+ | <code> | ||
+ | cd /usr/bin | ||
+ | groupadd perf_users | ||
+ | |||
+ | chgrp perf_users perf | ||
+ | |||
+ | chmod o-rwx perf | ||
+ | |||
+ | setcap cap_sys_admin,cap_sys_ptrace,cap_syslog=ep perf | ||
+ | </code> | ||
+ | |||
+ | Once that's complete, there will be a <code>perf.data</code> file created, and commands like <code>perf report</code> can be run. | ||
=== gcov === | === gcov === |
Revision as of 07:06, 9 June 2021
Contents
Linux
When using either scons or cmake to build, there are four options available for profiling which are listed below. For cmake use -DPROFILER=<name>
, for scons use profiler=<name>
.
gperftools
To use gperftools:
- Install the packages
google-perftools
(needed later for running google-pprof) andlibgoogle-perftools-dev
(needed in order to use the -lprofiler linker option). - In a terminal, export the
CPUPROFILE
variable, such asexport CPUPROFILE=./wesnoth-prof
. - Build any executable while setting either
-DPROFILER=gperftools
(cmake) orprofiler=gperftools
(scons). - Run the executable and have it do any task(s) as needed to get relevant profiling information.
- Generate the human-readable profiling output using the command
google-pprof <executable> <profiling info> > prof.txt
for a text file, orgoogle-pprof -gif <executable> <profiling info> > prof.gif
for a viewable gif image.
Unfortunately, the output, whether graphical or text, doesn't provide any labels for what the values mean. For the text output, the columns are:
- The number of profiling samples in this function
- The percentage of profiling samples in this function
- The percentage of profiling samples in the functions printed so far
- The number of profiling samples in this function and its callees
- The percentage of profiling samples in this function and its callees
- The function name
For the graphical output, each square will contain:
- The namespace/class/method profiled, each of those on a separate line
- The number of profiling samples in this function
- The percentage of profiling samples in this function (in parenthesis)
- The number of profiling samples in this function and its callees
- The percentage of profiling samples in this function and its callees (in parenthesis)
perf
To use perf:
- Install the packages
linux-tools-common
andlinux-tools-<kernel version>
, ie linux-tools-5.8.0-55-generic. - Run
perf record <executable>
. To do this you will need to either:- Run the executable as root
- Switch to root and run
echo 2 > /proc/sys/kernel/perf_event_paranoid
- Create a new group that has rights to use perf and add your user to it, ie:
cd /usr/bin
groupadd perf_users
chgrp perf_users perf
chmod o-rwx perf
setcap cap_sys_admin,cap_sys_ptrace,cap_syslog=ep perf
Once that's complete, there will be a perf.data
file created, and commands like perf report
can be run.