Skip to content

Service profiling

Yuri Voinov edited this page Dec 5, 2023 · 7 revisions

To profile a service, you can use both interactive launch of the service in the console, and background execution by the operating system service.

When profiling a service, it is recommended to save the profiler log to a file. In general, the solution for all operating systems is approximately the same - for the service, you need to define two environment variables MEMLOGGER_LOG_FILENAME and LD_PRELOAD, restart the service, let it work for some time, if necessary with a load, and stop the service/shutdown it, or send one of the termination signals to the service daemon SIGHUP/SIGTERM/SIGINT.

Note: When MEMLOGGER_LOG_FILENAME specified, allocation report will flush on disk every TIMER_INTERVAL seconds. You can check report during service profiling.

Note: Signals can overlap with the service's own signals. It is recommended that you first try to correctly stop the service using OS methods.

Note: Make sure that the bitness of the profiler matches the bitness of the service. Please check that you are using the correct preload variable.

Linux systemd

For Linux systemd units, you can use best practice, as shown here.

The config for the service might look like this:

[Unit]
After=multi-user.target

[Service]
Environment="MEMLOGGER_LOG_FILENAME=/tmp/memory.log"
Environment="LD_PRELOAD=/usr/local/lib/libmemlogger.so"

Running service will looks like that:

изображение

Solaris SMF

On Solaris SMF you can use following commands to set FMRI environment (example):

svccfg -s serviceFMRI setenv MEMLOGGER_LOG_FILENAME /tmp/memory.log
svccfg -s serviceFMRI setenv LD_PRELOAD_64 /usr/local/lib/64/libmemlogger.so
svcadm refresh serviceFMRI
svcadm restart serviceFMRI

After running for some time and the service is finished or terminated, you can view the profiler report with the cat command:

# cat /tmp/memory.log
Clone this wiki locally