Memory profiling is used to detect inefficient usage of dynamic memory and memory leaks. Some use cases for the memory profiler are:
All the userver based services could use jemalloc profiler that could be is dynamically enabled/disabled via the server::handlers::Jemalloc.
MALLOC_CONF
for your service before the service start: $ curl -X POST localhost:1188/service/jemalloc/prof/enable
OK
$ curl -s -X POST localhost:1188/service/jemalloc/prof/stat | grep ' prof.active:'
prof.active: true
$ curl -X POST localhost:1188/service/jemalloc/prof/dump OK
MALLOC_CONF
for your service before the service start: $ curl -s -X POST localhost:1188/service/jemalloc/prof/stat | grep ' prof.active:'
prof.active: true
$ curl -X POST localhost:1188/service/jemalloc/prof/dump OK
$ curl -X POST localhost:1188/service/jemalloc/prof/disable
OK
$ curl -s -X POST localhost:1188/service/jemalloc/prof/stat | grep ' prof.active:'
prof.active: false
jeprof
on the target machine and parse the resulting pdf/text file on your working machine. To install jeprof
, you can do apt install libjemalloc-dev
.$ jeprof --show_bytes --pdf build/services/userver-sample /tmp/jeprof.5503.1.m1.heap> prof.pdf
$ gnome-open prof.pdf # Open the file in PDF viewer
apt install graphviz ghostscript
packages are installed.$ jeprof --show_bytes --text --cum build/samples/userver-sample /tmp/jeprof.5503.1.m1.heap
Using local file build/services/userver-sample.
Using local file /tmp/jeprof.5503.1.m1.heap.
Q: I get mallctl() returned error: Bad address
when calling dump
.
A: You need to make sure that the directory specified in prof_prefix
is created and that the service has write access to it.