2014-09-01 10:45:34 +00:00
|
|
|
.\" Copyright (c) 2013, Peter Schiffer <pschiffe@redhat.com>
|
2014-09-01 15:16:36 +00:00
|
|
|
.\" and Copyright (C) 2014, Michael Kerrisk <mtk.manpages@gmail.com>
|
2014-09-01 08:50:43 +00:00
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
|
|
|
|
.\" This is free documentation; you can redistribute it and/or
|
|
|
|
.\" modify it under the terms of the GNU General Public License as
|
|
|
|
.\" published by the Free Software Foundation; either version 2 of
|
|
|
|
.\" the License, or (at your option) any later version.
|
|
|
|
.\"
|
|
|
|
.\" The GNU General Public License's references to "object code"
|
|
|
|
.\" and "executables" are to be interpreted as the output of any
|
|
|
|
.\" document formatting or typesetting system, including
|
|
|
|
.\" intermediate and printed output.
|
|
|
|
.\"
|
|
|
|
.\" This manual is distributed in the hope that it will be useful,
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
.\" GNU General Public License for more details.
|
|
|
|
.\"
|
|
|
|
.\" You should have received a copy of the GNU General Public
|
|
|
|
.\" License along with this manual; if not, see
|
|
|
|
.\" <http://www.gnu.org/licenses/>.
|
|
|
|
.\" %%%LICENSE_END
|
iconv.1, locale.1, memusage.1, memusagestat.1, pldd.1, sprof.1, _syscall.2, add_key.2, adjtimex.2, bind.2, bpf.2, chown.2, clone.2, close.2, copy_file_range.2, eventfd.2, fanotify_init.2, fanotify_mark.2, fork.2, fsync.2, futex.2, getdents.2, getrlimit.2, getxattr.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, ioctl_fat.2, ioctl_getfsmap.2, ioctl_ns.2, ioctl_tty.2, ioctl_userfaultfd.2, kcmp.2, keyctl.2, listen.2, listxattr.2, mbind.2, membarrier.2, memfd_create.2, mkdir.2, move_pages.2, mremap.2, msync.2, nfsservctl.2, open.2, perf_event_open.2, pidfd_send_signal.2, pipe.2, pivot_root.2, pkey_alloc.2, process_vm_readv.2, ptrace.2, readlink.2, readv.2, recv.2, recvmmsg.2, rename.2, request_key.2, s390_runtime_instr.2, sched_setaffinity.2, seccomp.2, send.2, sendmmsg.2, sigaltstack.2, signalfd.2, socket.2, socketpair.2, splice.2, spu_create.2, spu_run.2, statfs.2, syscall.2, sysctl.2, sysfs.2, tee.2, timer_getoverrun.2, timer_settime.2, umount.2, userfaultfd.2, utimensat.2, wait4.2, INFINITY.3, __ppc_get_timebase.3, __setfpucw.3, abort.3, aio_cancel.3, aio_error.3, aio_read.3, aio_return.3, atexit.3, backtrace.3, basename.3, bsearch.3, bswap.3, cacos.3, cacosh.3, catan.3, catanh.3, cexp2.3, clock_getcpuclockid.3, clog2.3, cmsg.3, confstr.3, div.3, dl_iterate_phdr.3, dlerror.3, dlinfo.3, dlopen.3, dlsym.3, duplocale.3, encrypt.3, end.3, endian.3, envz_add.3, err.3, expm1.3, fdim.3, flockfile.3, fmtmsg.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo_a.3, getauxval.3, getdate.3, getdtablesize.3, getgrent_r.3, getgrouplist.3, gethostbyname.3, getline.3, getnameinfo.3, getopt.3, getprotoent_r.3, getpwent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, getutent.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_ntop.3, inet_pton.3, insque.3, killpg.3, makecontext.3, mallinfo.3, malloc.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbsnrtowcs.3, mbstowcs.3, mcheck.3, mempcpy.3, mq_getattr.3, mq_notify.3, mtrace.3, newlocale.3, nextafter.3, ntp_gettime.3, offsetof.3, open_memstream.3, pow.3, printf.3, pthread_attr_init.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setstack.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_detach.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_join.3, pthread_mutex_consistent.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_spin_init.3, pthread_testcancel.3, pthread_tryjoin_np.3, ptsname.3, qsort.3, rand.3, random.3, remainder.3, rpmatch.3, rtime.3, rtnetlink.3, scalb.3, scalbln.3, scandir.3, sem_getvalue.3, sem_wait.3, setaliasent.3, setlogmask.3, sigwait.3, sincos.3, sockatmark.3, stdarg.3, stpcpy.3, strcat.3, strfmon.3, strptime.3, strtod.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, tsearch.3, uselocale.3, wcstok.3, wcstombs.3, wordexp.3, y0.3, loop.4, vcs.4, veth.4, charmap.5, core.5, filesystems.5, gai.conf.5, hosts.5, hosts.equiv.5, locale.5, nss.5, repertoiremap.5, securetty.5, shells.5, ttytype.5, ascii.7, complex.7, cpuset.7, credentials.7, fanotify.7, hier.7, inotify.7, ip.7, mount_namespaces.7, mq_overview.7, netlink.7, network_namespaces.7, pid_namespaces.7, pkeys.7, rtld-audit.7, rtnetlink.7, sem_overview.7, signal-safety.7, sock_diag.7, spufs.7, standards.7, symlink.7, tcp.7, time_namespaces.7, unix.7, user_namespaces.7, xattr.7, ldconfig.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-06-09 12:43:54 +00:00
|
|
|
.TH MEMUSAGE 1 2020-06-09 "GNU" "Linux user manual"
|
2014-09-01 08:50:43 +00:00
|
|
|
.SH NAME
|
|
|
|
memusage \- profile memory usage of a program
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.BR memusage " [\fIoption\fR]... \fIprogram\fR [\fIprogramoption\fR]..."
|
|
|
|
.SH DESCRIPTION
|
|
|
|
.B memusage
|
2014-09-01 10:45:34 +00:00
|
|
|
is a bash script which profiles memory usage of the program,
|
|
|
|
.IR program .
|
|
|
|
It preloads the
|
2014-09-01 08:50:43 +00:00
|
|
|
.B libmemusage.so
|
2014-09-01 10:45:34 +00:00
|
|
|
library into the caller's environment (via the
|
2014-09-01 08:50:43 +00:00
|
|
|
.B LD_PRELOAD
|
2014-09-01 10:45:34 +00:00
|
|
|
environment variable; see
|
|
|
|
.BR ld.so (8)).
|
|
|
|
The
|
2014-09-01 08:50:43 +00:00
|
|
|
.B libmemusage.so
|
|
|
|
library traces memory allocation by intercepting calls to
|
|
|
|
.BR malloc (3),
|
2014-09-01 10:45:34 +00:00
|
|
|
.BR calloc (3),
|
2014-09-01 08:50:43 +00:00
|
|
|
.BR free (3),
|
2014-09-01 10:45:34 +00:00
|
|
|
and
|
|
|
|
.BR realloc (3);
|
|
|
|
optionally, calls to
|
|
|
|
.BR mmap (2),
|
|
|
|
.BR mremap (2),
|
|
|
|
and
|
|
|
|
.BR munmap (2)
|
|
|
|
can also be intercepted.
|
2014-09-01 08:50:43 +00:00
|
|
|
.PP
|
|
|
|
.B memusage
|
2014-09-01 10:45:34 +00:00
|
|
|
can output the collected data in textual form, or it can use
|
2014-09-01 08:50:43 +00:00
|
|
|
.BR memusagestat (1)
|
2014-09-01 10:45:34 +00:00
|
|
|
(see the
|
2020-07-01 22:05:53 +00:00
|
|
|
.B \-p
|
2014-09-01 10:45:34 +00:00
|
|
|
option, below)
|
2014-09-01 08:50:43 +00:00
|
|
|
to create a PNG file containing graphical representation
|
|
|
|
of the collected data.
|
2014-09-01 10:45:34 +00:00
|
|
|
.SS Memory usage summary
|
|
|
|
The "Memory usage summary" line output by
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B memusage
|
2014-09-01 10:45:34 +00:00
|
|
|
contains three fields:
|
|
|
|
.RS 4
|
|
|
|
.TP
|
|
|
|
\fBheap total\fR
|
|
|
|
Sum of \fIsize\fR arguments of all
|
|
|
|
.BR malloc (3)
|
|
|
|
calls,
|
|
|
|
products of arguments (\fInmemb\fR*\fIsize\fR) of all
|
|
|
|
.BR calloc (3)
|
|
|
|
calls,
|
|
|
|
and sum of \fIlength\fR arguments of all
|
|
|
|
.BR mmap (2)
|
|
|
|
calls.
|
2014-09-01 15:14:10 +00:00
|
|
|
In the case of
|
|
|
|
.BR realloc (3)
|
|
|
|
and
|
|
|
|
.BR mremap (2),
|
|
|
|
if the new size of an allocation is larger than the previous size,
|
|
|
|
the sum of all such differences (new size minus old size) is added.
|
2014-09-01 10:45:34 +00:00
|
|
|
.TP
|
|
|
|
.B "heap peak"
|
|
|
|
Maximum of all \fIsize\fR arguments of
|
|
|
|
.BR malloc (3),
|
|
|
|
all products of \fInmemb\fR*\fIsize\fR of
|
|
|
|
.BR calloc (3),
|
|
|
|
all \fIsize\fR arguments of
|
|
|
|
.BR realloc (3),
|
|
|
|
.I length
|
|
|
|
arguments of
|
|
|
|
.BR mmap (2),
|
|
|
|
and
|
|
|
|
\fInew_size\fR arguments of
|
|
|
|
.BR mremap (2).
|
|
|
|
.TP
|
|
|
|
.B "stack peak"
|
2014-09-01 08:50:43 +00:00
|
|
|
Before the first call to any monitored function,
|
2014-09-01 10:45:34 +00:00
|
|
|
the stack pointer address (base stack pointer) is saved.
|
|
|
|
After each function call, the actual stack pointer address is read and
|
|
|
|
the difference from the base stack pointer computed.
|
|
|
|
The maximum of these differences is then the stack peak.
|
2014-09-01 08:50:43 +00:00
|
|
|
.RE
|
2014-09-01 10:45:34 +00:00
|
|
|
.PP
|
2014-09-01 15:14:10 +00:00
|
|
|
Immediately following this summary line, a table shows the number calls,
|
2014-09-07 12:04:07 +00:00
|
|
|
total memory allocated or deallocated,
|
2014-09-01 15:14:10 +00:00
|
|
|
and number of failed calls for each intercepted function.
|
2014-09-01 15:29:58 +00:00
|
|
|
For
|
|
|
|
.BR realloc (3)
|
|
|
|
and
|
|
|
|
.BR mremap (2),
|
|
|
|
the additional field "nomove" shows reallocations that
|
|
|
|
changed the address of a block,
|
|
|
|
and the additional "dec" field shows reallocations that
|
|
|
|
decreased the size of the block.
|
|
|
|
For
|
|
|
|
.BR realloc (3),
|
|
|
|
the additional field "free" shows reallocations that
|
|
|
|
caused a block to be freed (i.e., the reallocated size was 0).
|
iconv.1, locale.1, localedef.1, memusage.1, memusagestat.1, mtrace.1, pldd.1, sprof.1, time.1, iconvconfig.8, ld.so.8, ldconfig.8, sln.8: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 00:52:54 +00:00
|
|
|
.PP
|
2014-09-01 15:14:10 +00:00
|
|
|
The "realloc/total memory" of the table output by
|
|
|
|
.B memusage
|
|
|
|
does not reflect cases where
|
2014-09-01 10:45:34 +00:00
|
|
|
.BR realloc (3)
|
|
|
|
is used to reallocate a block of memory
|
2014-09-01 15:14:10 +00:00
|
|
|
to have a smaller size than previously.
|
|
|
|
This can cause sum of all "total memory" cells (excluding "free")
|
|
|
|
to be larger than the "free/total memory" cell.
|
2014-09-01 10:45:34 +00:00
|
|
|
.SS Histogram for block sizes
|
|
|
|
The "Histogram for block sizes" provides a breakdown of memory
|
|
|
|
allocations into various bucket sizes.
|
2014-09-01 08:50:43 +00:00
|
|
|
.SH OPTIONS
|
|
|
|
.TP
|
|
|
|
.BI \-n\ name \fR,\ \fB\-\-progname= name
|
|
|
|
Name of the program file to profile.
|
|
|
|
.TP
|
|
|
|
.BI \-p\ file \fR,\ \fB\-\-png= file
|
2014-09-01 10:45:34 +00:00
|
|
|
Generate PNG graphic and store it in
|
|
|
|
.IR file .
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
|
|
|
.BI \-d\ file \fR,\ \fB\-\-data= file
|
2014-09-01 10:45:34 +00:00
|
|
|
Generate binary data file and store it in
|
|
|
|
.IR file .
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B \-u\fR,\ \fB\-\-unbuffered
|
2014-09-01 08:50:43 +00:00
|
|
|
Do not buffer output.
|
|
|
|
.TP
|
|
|
|
.BI \-b\ size \fR,\ \fB\-\-buffer= size
|
2014-09-01 10:45:34 +00:00
|
|
|
Collect
|
|
|
|
.I size
|
|
|
|
entries before writing them out.
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
intro.1, localedef.1, memusage.1, memusagestat.1, bpf.2, execve.2, fork.2, keyctl.2, request_key.2, sigaction.2, signal.2, socket.2, dlopen.3, getauxval.3, gnu_get_libc_version.3, pthread_atfork.3, sem_post.3, setjmp.3, strftime.3, veth.4, locale.5, nscd.conf.5, resolv.conf.5, address_families.7, armscii-8.7, ascii.7, capabilities.7, cgroups.7, charsets.7, cp1251.7, cp1252.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, keyrings.7, koi8-r.7, koi8-u.7, libc.7, locale.7, man.7, network_namespaces.7, persistent-keyring.7, session-keyring.7, signal.7, unicode.7, uri.7, user-keyring.7, user-session-keyring.7: ffix: replace - with real\-
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-07-06 12:28:51 +00:00
|
|
|
.B \-\-no\-timer
|
2014-09-01 10:45:34 +00:00
|
|
|
Disable timer-based
|
|
|
|
.RB ( SIGPROF )
|
|
|
|
sampling of stack pointer value.
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B \-m\fR,\ \fB\-\-mmap
|
2014-09-01 10:45:34 +00:00
|
|
|
Also trace
|
|
|
|
.BR mmap (2),
|
|
|
|
.BR mremap (2),
|
|
|
|
and
|
2015-02-26 14:23:25 +00:00
|
|
|
.BR munmap (2).
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B \-?\fR,\ \fB\-\-help
|
2014-09-01 08:50:43 +00:00
|
|
|
Print help and exit.
|
|
|
|
.TP
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B \-\-usage
|
2014-09-01 08:50:43 +00:00
|
|
|
Print a short usage message and exit.
|
|
|
|
.TP
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B \-V\fR,\ \fB\-\-version
|
2014-09-01 08:50:43 +00:00
|
|
|
Print version information and exit.
|
|
|
|
.TP
|
2015-01-28 09:11:54 +00:00
|
|
|
The following options apply only when generating graphical output:
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B \-t\fR,\ \fB\-\-time\-based
|
2014-09-01 10:45:34 +00:00
|
|
|
Use time (rather than number of function calls) as the scale for the X axis.
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1: tfix, use a one-font macro for a single argument
1) Use a single capital font macro for a genuine single argument.
The output is unchanged.
2) Remove quotation marks (") around a single argument.
The output is unchanged.
3) Change ".IR ab()" to ".IR ab ()"
A font is changed in the output.
mtk: I verified that the output is unchanged (other than fonts)
by comparing the output of:
for a in *.1; do man $a >> out.txt; done
before and after the patch.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-12-24 00:20:29 +00:00
|
|
|
.B \-T\fR,\ \fB\-\-total
|
2014-09-01 10:45:34 +00:00
|
|
|
Also draw a graph of total memory use.
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
|
|
|
.BI \fB\-\-title= name
|
2014-09-01 10:45:34 +00:00
|
|
|
Use
|
|
|
|
.I name
|
|
|
|
as the title of the graph.
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
|
|
|
.BI \-x\ size \fR,\ \fB\-\-x\-size= size
|
2014-09-01 10:45:34 +00:00
|
|
|
Make the graph
|
|
|
|
.I size
|
|
|
|
pixels wide.
|
2014-09-01 08:50:43 +00:00
|
|
|
.TP
|
|
|
|
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
|
2014-09-01 10:45:34 +00:00
|
|
|
Make the graph
|
|
|
|
.I size
|
|
|
|
pixels high.
|
2014-09-01 08:50:43 +00:00
|
|
|
.SH EXIT STATUS
|
|
|
|
Exit status is equal to the exit status of profiled program.
|
2016-08-07 19:08:01 +00:00
|
|
|
.SH BUGS
|
|
|
|
To report bugs, see
|
|
|
|
.UR http://www.gnu.org/software/libc/bugs.html
|
|
|
|
.UE
|
2020-05-21 08:00:37 +00:00
|
|
|
.SH EXAMPLES
|
2014-09-07 12:04:07 +00:00
|
|
|
Below is a simple program that reallocates a block of
|
2014-09-01 15:16:36 +00:00
|
|
|
memory in cycles that rise to a peak before then cyclically
|
|
|
|
reallocating the memory in smaller blocks that return to zero.
|
|
|
|
After compiling the program and running the following commands,
|
|
|
|
a graph of the memory usage of the program can be found in the file
|
|
|
|
.IR memusage.png :
|
iconv.1, locale.1, localedef.1, memusage.1, memusagestat.1, mtrace.1, pldd.1, sprof.1, time.1, iconvconfig.8, ld.so.8, ldconfig.8, sln.8: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 00:52:54 +00:00
|
|
|
.PP
|
2014-09-01 15:16:36 +00:00
|
|
|
.in +4n
|
2017-08-16 09:14:04 +00:00
|
|
|
.EX
|
2017-08-19 19:42:31 +00:00
|
|
|
$ \fBmemusage \-\-data=memusage.dat ./a.out\fP
|
2014-09-01 15:16:36 +00:00
|
|
|
\&...
|
|
|
|
Memory usage summary: heap total: 45200, heap peak: 6440, stack peak: 224
|
|
|
|
total calls total memory failed calls
|
|
|
|
malloc| 1 400 0
|
|
|
|
realloc| 40 44800 0 (nomove:40, dec:19, free:0)
|
|
|
|
calloc| 0 0 0
|
|
|
|
free| 1 440
|
|
|
|
Histogram for block sizes:
|
2017-08-19 19:42:31 +00:00
|
|
|
192\-207 1 2% ================
|
2014-09-01 15:16:36 +00:00
|
|
|
\&...
|
2017-08-19 19:42:31 +00:00
|
|
|
2192\-2207 1 2% ================
|
|
|
|
2240\-2255 2 4% =================================
|
|
|
|
2832\-2847 2 4% =================================
|
|
|
|
3440\-3455 2 4% =================================
|
|
|
|
4032\-4047 2 4% =================================
|
|
|
|
4640\-4655 2 4% =================================
|
|
|
|
5232\-5247 2 4% =================================
|
|
|
|
5840\-5855 2 4% =================================
|
|
|
|
6432\-6447 1 2% ================
|
2014-09-01 15:16:36 +00:00
|
|
|
$ \fBmemusagestat memusage.dat memusage.png\fP
|
2017-08-16 09:14:04 +00:00
|
|
|
.EE
|
2014-09-01 15:16:36 +00:00
|
|
|
.in
|
|
|
|
.SS Program source
|
memusage.1, clone.2, eventfd.2, futex.2, getdents.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, keyctl.2, mmap.2, mprotect.2, msgop.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, setns.2, tee.2, timer_create.2, timerfd_create.2, unshare.2, userfaultfd.2, wait.2, __ppc_get_timebase.3, backtrace.3, bswap.3, clock_getcpuclockid.3, dl_iterate_phdr.3, dlinfo.3, dlopen.3, duplocale.3, end.3, endian.3, fmemopen.3, fopencookie.3, frexp.3, ftw.3, getdate.3, getgrouplist.3, getifaddrs.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, mq_getattr.3, mq_notify.3, newlocale.3, offsetof.3, posix_spawn.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, scandir.3, sem_wait.3, strcat.3, strftime.3, strtok.3, strtol.3, strverscmp.3, loop.4, core.5, aio.7, fanotify.7, feature_test_macros.7, inotify.7, pkeys.7, unix.7, user_namespaces.7: Use .EX/.EE for EXAMPLE programs
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 08:44:33 +00:00
|
|
|
.EX
|
2014-09-01 15:16:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define CYCLES 20
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2020-09-04 07:51:08 +00:00
|
|
|
int i, j;
|
|
|
|
size_t size;
|
|
|
|
int *p;
|
2014-09-01 15:16:36 +00:00
|
|
|
|
2020-09-04 07:51:08 +00:00
|
|
|
size = sizeof(*p) * 100;
|
2020-09-04 07:52:02 +00:00
|
|
|
printf("malloc: %zu\en", size);
|
2020-09-04 07:51:08 +00:00
|
|
|
p = malloc(size);
|
2014-09-01 15:16:36 +00:00
|
|
|
|
2020-09-04 07:51:08 +00:00
|
|
|
for (i = 0; i < CYCLES; i++) {
|
|
|
|
if (i < CYCLES / 2)
|
|
|
|
j = i;
|
|
|
|
else
|
|
|
|
j--;
|
2014-09-01 15:16:36 +00:00
|
|
|
|
2020-09-04 07:51:08 +00:00
|
|
|
size = sizeof(*p) * (j * 50 + 110);
|
2020-09-04 07:52:02 +00:00
|
|
|
printf("realloc: %zu\en", size);
|
2020-09-04 07:51:08 +00:00
|
|
|
p = realloc(p, size);
|
2014-09-01 15:16:36 +00:00
|
|
|
|
2020-09-04 07:51:08 +00:00
|
|
|
size = sizeof(*p) * ((j + 1) * 150 + 110);
|
2020-09-04 07:52:02 +00:00
|
|
|
printf("realloc: %zu\en", size);
|
2020-09-04 07:51:08 +00:00
|
|
|
p = realloc(p, size);
|
|
|
|
}
|
2014-09-01 15:16:36 +00:00
|
|
|
|
2020-09-04 07:51:08 +00:00
|
|
|
free(p);
|
|
|
|
exit(EXIT_SUCCESS);
|
2014-09-01 15:16:36 +00:00
|
|
|
}
|
memusage.1, clone.2, eventfd.2, futex.2, getdents.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, keyctl.2, mmap.2, mprotect.2, msgop.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, setns.2, tee.2, timer_create.2, timerfd_create.2, unshare.2, userfaultfd.2, wait.2, __ppc_get_timebase.3, backtrace.3, bswap.3, clock_getcpuclockid.3, dl_iterate_phdr.3, dlinfo.3, dlopen.3, duplocale.3, end.3, endian.3, fmemopen.3, fopencookie.3, frexp.3, ftw.3, getdate.3, getgrouplist.3, getifaddrs.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, mq_getattr.3, mq_notify.3, newlocale.3, offsetof.3, posix_spawn.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, scandir.3, sem_wait.3, strcat.3, strftime.3, strtok.3, strtol.3, strverscmp.3, loop.4, core.5, aio.7, fanotify.7, feature_test_macros.7, inotify.7, pkeys.7, unix.7, user_namespaces.7: Use .EX/.EE for EXAMPLE programs
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 08:44:33 +00:00
|
|
|
.EE
|
2014-09-01 08:50:43 +00:00
|
|
|
.SH SEE ALSO
|
|
|
|
.BR memusagestat (1),
|
2020-05-16 23:34:25 +00:00
|
|
|
.BR mtrace (1),
|
2014-09-01 08:50:43 +00:00
|
|
|
.BR ld.so (8)
|