Commit 75ba13f9 authored by Sasha Goldshtein's avatar Sasha Goldshtein

Updated manual, examples, and usage with new interval and count options

parent 40e55baa
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
.SH NAME .SH NAME
memleak \- Print a summary of outstanding allocations and their call stacks to detect memory leaks. Uses Linux eBPF/bcc. memleak \- Print a summary of outstanding allocations and their call stacks to detect memory leaks. Uses Linux eBPF/bcc.
.SH SYNOPSIS .SH SYNOPSIS
.B memleak [-h] [-p PID] [-t] [-i INTERVAL] [-a] [-o OLDER] [-c COMMAND] [-s SAMPLE_RATE] .B memleak [-h] [-p PID] [-t] [-a] [-o OLDER] [-c COMMAND] [-s SAMPLE_RATE] [INTERVAL] [COUNT]
.SH DESCRIPTION .SH DESCRIPTION
memleak traces and matches memory allocation and deallocation requests, and memleak traces and matches memory allocation and deallocation requests, and
collects call stacks for each allocation. memleak can then print a summary collects call stacks for each allocation. memleak can then print a summary
...@@ -27,10 +27,13 @@ Trace this process ID only (filtered in-kernel). This traces malloc and free fro ...@@ -27,10 +27,13 @@ Trace this process ID only (filtered in-kernel). This traces malloc and free fro
\-t \-t
Print a trace of all allocation and free requests and results. Print a trace of all allocation and free requests and results.
.TP .TP
\-i INTERVAL INTERVAL
Print a summary of oustanding allocations and their call stacks every INTERVAL seconds. Print a summary of oustanding allocations and their call stacks every INTERVAL seconds.
The default interval is 5 seconds. The default interval is 5 seconds.
.TP .TP
COUNT
Print the outstanding allocations summary COUNT times and then exit.
.TP
\-a \-a
Print a list of allocations that weren't freed (and their sizes) in addition to their call stacks. Print a list of allocations that weren't freed (and their sizes) in addition to their call stacks.
.TP .TP
...@@ -47,7 +50,7 @@ Record roughly every SAMPLE_RATE-th allocation to reduce overhead. ...@@ -47,7 +50,7 @@ Record roughly every SAMPLE_RATE-th allocation to reduce overhead.
.TP .TP
Print outstanding kernel allocation stacks every 3 seconds: Print outstanding kernel allocation stacks every 3 seconds:
# #
.B memleak -i 3 .B memleak 3
.TP .TP
Print user outstanding allocation stacks and allocation details for the process 1005: Print user outstanding allocation stacks and allocation details for the process 1005:
# #
......
...@@ -150,7 +150,7 @@ EXAMPLES: ...@@ -150,7 +150,7 @@ EXAMPLES:
allocations every 5 seconds allocations every 5 seconds
./memleak.py -p $(pidof allocs) -t ./memleak.py -p $(pidof allocs) -t
Trace allocations and display each individual call to malloc/free Trace allocations and display each individual call to malloc/free
./memleak.py -p $(pidof allocs) -a -i 10 ./memleak.py -ap $(pidof allocs) 10
Trace allocations and display allocated addresses, sizes, and stacks Trace allocations and display allocated addresses, sizes, and stacks
every 10 seconds for outstanding allocations every 10 seconds for outstanding allocations
./memleak.py -c "./allocs" ./memleak.py -c "./allocs"
......
...@@ -110,26 +110,35 @@ To avoid false positives, allocations younger than a certain age (500ms by ...@@ -110,26 +110,35 @@ To avoid false positives, allocations younger than a certain age (500ms by
default) are not printed. To change this threshold, use the -o switch. default) are not printed. To change this threshold, use the -o switch.
By default, memleak prints its output every 5 seconds. To change this By default, memleak prints its output every 5 seconds. To change this
interval, use the -i switch. interval, pass the interval as a positional parameter to memleak. You can
also control the number of times the output will be printed before exiting.
For example:
# ./memleak.py 1 10
... will print the outstanding allocation statistics every second, for ten
times, and then exit.
USAGE message: USAGE message:
# ./memleak.py -h # ./memleak.py -h
usage: memleak.py [-h] [-p PID] [-t] [-i INTERVAL] [-a] [-o OLDER] usage: memleak.py [-h] [-p PID] [-t] [-a] [-o OLDER] [-c COMMAND]
[-c COMMAND] [-s SAMPLE_RATE] [-s SAMPLE_RATE]
[interval] [count]
Trace outstanding memory allocations that weren't freed. Trace outstanding memory allocations that weren't freed.
Supports both user-mode allocations made with malloc/free and kernel-mode Supports both user-mode allocations made with malloc/free and kernel-mode
allocations made with kmalloc/kfree. allocations made with kmalloc/kfree.
interval interval in seconds to print outstanding allocations
count number of times to print the report before exiting
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-p PID, --pid PID the PID to trace; if not specified, trace kernel -p PID, --pid PID the PID to trace; if not specified, trace kernel
allocs allocs
-t, --trace print trace messages for each alloc/free call -t, --trace print trace messages for each alloc/free call
-i INTERVAL, --interval INTERVAL
interval in seconds to print outstanding allocations
-a, --show-allocs show allocation addresses and sizes as well as call -a, --show-allocs show allocation addresses and sizes as well as call
stacks stacks
-o OLDER, --older OLDER -o OLDER, --older OLDER
...@@ -147,7 +156,16 @@ EXAMPLES: ...@@ -147,7 +156,16 @@ EXAMPLES:
allocations every 5 seconds allocations every 5 seconds
./memleak.py -p $(pidof allocs) -t ./memleak.py -p $(pidof allocs) -t
Trace allocations and display each individual call to malloc/free Trace allocations and display each individual call to malloc/free
./memleak.py -p $(pidof allocs) -a -i 10 Trace allocations and display allocated addresses, sizes, and stacks every 10 seconds for outstanding allocations ./memleak.py -c "./allocs" Run the specified command and trace its allocations ./memleak.py Trace allocations in kernel mode and display a summary of outstanding allocations every 5 seconds ./memleak.py -o 60000 Trace allocations in kernel mode and display a summary of outstanding allocations that are at least one minute (60 seconds) old ./memleak.py -ap $(pidof allocs) 10
Trace allocations and display allocated addresses, sizes, and stacks
every 10 seconds for outstanding allocations
./memleak.py -c "./allocs"
Run the specified command and trace its allocations
./memleak.py
Trace allocations in kernel mode and display a summary of outstanding
allocations every 5 seconds
./memleak.py -o 60000
Trace allocations in kernel mode and display a summary of outstanding
allocations that are at least one minute (60 seconds) old
./memleak.py -s 5 ./memleak.py -s 5
Trace roughly every 5th allocation, to reduce overhead Trace roughly every 5th allocation, to reduce overhead
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment