Skip to contentSkip to conversation

For review: memusage(1) man page

DISCUSSION Jan Chaloupka 5 participants 18 messages Jul 18, 2014 – Sep 1, 2014 11 messages not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

Hi,

memusage command is no documented. My collegue (95%) and I (5%) have written a man page for it. All informations come from inspecting the script code. This is the first script, others are memusagestat (1) and mtrace(1).

Feel free to comment or ask any question.

Thank you
Jan

.\" Copyright (c) 2013, Peter Schiffer ([email protected]) .\"
.\" %%%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
.TH MEMUSAGE 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools"
.SH NAME
memusage \- profile memory usage of a program
.SH SYNOPSIS
.BR memusage " [\fIOPTION\fR]... \fIPROGRAM\fR [\fIPROGRAMOPTION\fR]..." .SH DESCRIPTION
.B memusage
is a bash script which can profile memory usage of a program. It preloads .B libmemusage.so
library to the user's environment using
.B LD_PRELOAD
environment variable. The
.B libmemusage.so
library traces memory allocation by intercepting calls to
.BR malloc (3),
.BR free (3),
.BR realloc (3)
and various other calls.
.PP
.B memusage
can output text representation of the collected data, or it can use
.BR memusagestat (1)
utility (see
.B -p
option)
to create a PNG file containing graphical representation
of the collected data.
.TP
List of monitored functions:
.RS
.BI "void *malloc(size_t " "size" );
.RE
.RS
.BI "void *calloc(size_t " "nmemb" ", size_t " "size" );
.RE
.RS
.BI "void *realloc(void " "*ptr" ", size_t " "size" );
.RE
.RS
.BI "void *mmap(void " "*addr" ", size_t " "length" ", int " "prot",
.BI "int " "flags" ", int " "fd" ", off_t " "offset");
.RE
.RS
.BI "void *mremap(void " "*old_address" ", size_t " "old_size",
.BI "size_t " "new_size" ", int " "flags",
.BI "... /* void " "*new_address" " */);"
.RE
.TP
Description of a memory usage summary:
.RE
\fBheap total\fR:
.RS
Sum of \fIsize\fR arguments of all malloc calls,
sum of all product of arguments (\fInmemb\fR*\fIsize\fR) of calloc call
and sum of \fIlength\fR arguments of mmap calls.
In a case of realloc, respectively mremap, if a new size of an original malloc, respectively mremap call is bigger than an old one,
sum of all such differences (new size - old size) is added.
.RE
\fBheap peak\fR:
.RS
Maximum of all \fIsize\fR arguments of malloc,
all products of \fInmemb\fR*\fIsize\fR of calloc,
all \fIsize\fR arguments of realloc, \fIlength\fR arguments of mmap and \fInew_size\fR arguments of mremap.
.RE
\fBstack peak\fR:
.RS
Before the first call to any monitored function,
stack pointer address (base stack pointer) is saved.
After each function call, actual stack pointer address is read and
the difference between the base stack pointer computed.
Maximum of these differences is then the stack peak.
.RE

If a realloc function is called on a mallocced memory with a new size being smaller than an old one, total memory of realloc cell is not updated. This can cause sum of all cells (excluding free) of total memory being greater than free cell.
.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
Generate PNG graphic and store it in the file.
.TP
.BI \-d\ file \fR,\ \fB\-\-data= file
Generate binary data file and store it in the file.
.TP
.BI \-u\fR,\ \fB\-\-unbuffered
Do not buffer output.
.TP
.BI \-b\ size \fR,\ \fB\-\-buffer= size
Collect size entries before writing them out.
.TP
.BI \fB\-\-no-timer
Do not collect additional information through timer.
.TP
.BI \-m\fR,\ \fB\-\-mmap
Also trace mmap and friends.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.TP
The following options only apply when generating graphical output:
.TP
.BI \-t\fR,\ \fB\-\-time\-based
Make graph linear in time.
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph of total memory use.
.TP
.BI \fB\-\-title= name
Use the name as a title of the graph.
.TP
.BI \-x\ size \fR,\ \fB\-\-x\-size= size
Make graphic size pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
.SH EXIT STATUS
Exit status is equal to the exit status of profiled program. .SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
.SH SEE ALSO
.BR memusagestat (1),
.BR ld.so (8)
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

memusage command is no documented. My collegue (95%) and I (5%) have written a man page for it. All informations come from inspecting the script code. This is the first script, others are memusagestat (1) and mtrace(1).

This, memusagestat, and mtrace should rather be put into the glibc manual. mtrace is already (though partially) documented there, and much of the details regarding the mtrace functions. Having the corresponding commands documented would be awesome though.

#2 lore raw
Quoted 7 lines · Alfred M. Szmidt

memusage command is no documented. My collegue (95%) and I (5%) have written a man page for it. All informations come from inspecting the script code. This is the first script, others are memusagestat (1) and mtrace(1).

This, memusagestat, and mtrace should rather be put into the glibc manual.

Having for example malloc in man pages, it is reasonable for me to put these three man pages here too. Searching manual for memusagestat help is time consuming. But yes, it should me in the manual too.

Quoted 3 lines

mtrace is already (though partially) documented there, and
much of the details regarding the mtrace functions. Having the corresponding commands documented would be awesome though.

A message that is not in the archive (sent off-list or not yet received): E1X84Kh-00041J-2z-iW7gFb+/I3LZHJUXO5efmti2O/[email protected]

#4 lore raw
Quoted 10 lines · Alfred M. Szmidt

memusage command is no documented. My collegue (95%) and I (5%) have written a man page for it. All informations come from inspecting the script code. This is the first script, others are memusagestat (1) and mtrace(1).

This, memusagestat, and mtrace should rather be put into the glibc manual. mtrace is already (though partially) documented there, and much of the details regarding the mtrace functions. Having the corresponding commands documented would be awesome though. .

I must say that this is an odd position to take. While it would be nice to have documentation in the glibc manual, the glibc developers did not bother to add anything to the manual when writing these interfaces, so it hardly seems like anyone else is obligated to do so (assuming that person wanted to even jump the CLA hurdle...). In any case, man pages does (good) pages that describe the libc interfaces (including commands).

Cheers,

Michael

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Jan, are you willing to assign copyright for those documenation bits to the FSF? I'll happily convert them into texinfo.

I must say that this is an odd position to take. While it would be nice to have documentation in the glibc manual, the glibc developers did not bother to add anything to the manual when writing these interfaces, so it hardly seems like anyone else is obligated to do so (assuming that person wanted to even jump the CLA hurdle...). In any case, man pages does (good) pages that describe the libc interfaces (including commands).

Someone sends a useful patch for glibc, but glibc is not documented using man pages so the natural thing is to have it in a format that can be accepted into glibc.

What is odd is to dismiss such a contribution and start making excuses as to why one should not "bother" updating the offical, and canonical documentation for glibc. And accusing people because they "couldn't be bothered" is quite an unfriendly attidue. We all have things to do, and only have so much time to try and do everything.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): E1X9VbA-0002Bk-Ox-iW7gFb+/I3LZHJUXO5efmti2O/[email protected]

#8 lore raw
Quoted 2 lines · Alfred M. Szmidt

Jan, are you willing to assign copyright for those documenation bits to the FSF? I'll happily convert them into texinfo.

Alfred, can you be more specific? What would it imply for me, Peter and man pages? Is there a problem with GPLv2+ or the copyright? What should be changed?

Quoted 12 lines

I must say that this is an odd position to take. While it would be nice to have documentation in the glibc manual, the glibc developers did not bother to add anything to the manual when writing these interfaces, so it hardly seems like anyone else is obligated to do so (assuming that person wanted to even jump the CLA hurdle...). In any case, man pages does (good) pages that describe the libc interfaces (including commands).

Someone sends a useful patch for glibc, but glibc is not documented using man pages so the natural thing is to have it in a format that can be accepted into glibc.

Quoted 5 lines

What is odd is to dismiss such a contribution and start making excuses as to why one should not "bother" updating the offical, and canonical documentation for glibc. And accusing people because they "couldn't be bothered" is quite an unfriendly attidue. We all have things to do, and only have so much time to try and do everything.

Because you responded it means you don't have problems being bothered. Please, lets close this discussion. No need to continue. --
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw
Quoted 2 lines

Jan, are you willing to assign copyright for those documenation bits to the FSF? I'll happily convert them into texinfo.

Alfred, can you be more specific? What would it imply for me, Peter and man pages? Is there a problem with GPLv2+ or the copyright? What should be changed?

Please see:

https://sourceware.org/glibc/wiki/Contribution%20checklist#FSF_copyright_Assignment

It should explain everything.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): E1X9XoF-0007Vz-Lm-iW7gFb+/I3LZHJUXO5efmti2O/[email protected]

#12 lore raw

Hi, Alfred,

I, as a Red Hat employee, am covered by Red Hat's standing copyright assignment with the FSF.

Quoted 7 lines · Alfred M. Szmidt
Quoted 2 lines

Jan, are you willing to assign copyright for those documenation bits to the FSF? I'll happily convert them into texinfo.

Alfred, can you be more specific? What would it imply for me, Peter and man pages? Is there a problem with GPLv2+ or the copyright? What should be changed?

Quoted 5 lines

Please see:

https://sourceware.org/glibc/wiki/Contribution%20checklist#FSF_copyright_Assignment

It should explain everything.

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

I, as a Red Hat employee, am covered by Red Hat's standing copyright assignment with the FSF.

Didn't know that such a thing existed, if it does you are.

A message that is not in the archive (sent off-list or not yet received): E1XADPx-0007U6-2t-iW7gFb+/I3LZHJUXO5efmti2O/[email protected]

#15 lore raw

I know it from today :)

Quoted 4 lines · Alfred M. Szmidt

I, as a Red Hat employee, am covered by Red Hat's standing copyright assignment with the FSF.

Didn't know that such a thing existed, if it does you are.

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw
In reply to a message not in the archive

Hello Alfred,

Quoted 11 lines · Alfred M. Szmidt

Jan, are you willing to assign copyright for those documenation bits to the FSF? I'll happily convert them into texinfo.

I must say that this is an odd position to take. While it would be nice to have documentation in the glibc manual, the glibc developers did not bother to add anything to the manual when writing these interfaces, so it hardly seems like anyone else is obligated to do so (assuming that person wanted to even jump the CLA hurdle...). In any case, man pages does (good) pages that describe the libc interfaces (including commands).

Quoted 3 lines

Someone sends a useful patch for glibc, but glibc is not documented using man pages so the natural thing is to have it in a format that can be accepted into glibc.

My problem was with your earlier statement: "This, memusagestat, and mtrace should rather be put into the glibc manual." Perhaps it is just a language misstep, but "should" implies that the author is in some sense obliged to send documentation patches to the glibc manual, rather than elsewhere (e.g., man pages). I don't agree. (But, I'll repeat what I said earlier that it would be good if the doc is in the glibc manual, also.)

Quoted 1 line

What is odd is to dismiss such a contribution

I did not dismiss any contribution (or I am misunderstanding your point).

Quoted 3 lines

and start making excuses
as to why one should not "bother" updating the offical, and canonical documentation for glibc.

I'm not making excuses. But, I am suggesting that the CLA is a rather pointless hurdle. Yes, we can argue that one; I've already made my position clear and public elsewhere [1].

And, I can't help but make the observation that man-pages provides documentation of the glibc interfaces that is frequently more thorough, complete, and up-to-date than the "official and canonical" glibc manual. I leave others to speculate how that situation could come about.

Quoted 3 lines

And accusing people because they "couldn't
be bothered" is quite an unfriendly attidue. We all have things to do, and only have so much time to try and do everything.

I did not "accuse" anyone of anything, but it seems clear that there are many cases where documentation was considered unimportant. And, I probably could have expressed myself a little better and more temperately; I was reacting a little to what I perceived was your implication (as I describe above).

Mostly, I was expressing frustration with a too common developer attitude that the job ends at coding. For, without documentation (i.e., a formal or informal spec), how can one tell where the developer's implementation differs from their intention (i.e., a bug)? Personally speaking, I've never considered a development project complete if I did not also provide (extensive) documentation.

Cheers,

Michael

https://lwn.net/Articles/529522/

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

I did not "accuse" anyone of anything, but it seems clear that there are many cases where documentation was considered unimportant.

There is a different team doing work now -- what might have been in the past is not what is now, documentation is not unimportant.

To twist it, it would be very nice to merge whatever changes, additions, and improvments that the man pages have with regard to the glibc manual. Anyone who would like to take a stab at doing that? A good start would be a list of undocumented interfaces, tools, and such.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw

Jan,

Quoted 8 lines · Jan Chaloupka

Hi,

memusage command is no documented. My collegue (95%) and I (5%) have written a man page for it. All informations come from inspecting the script code. This is the first script, others are memusagestat (1) and mtrace(1).

Feel free to comment or ask any question.

Thanks for these submissions. It will take me a while to get to looking at them more closely. My time is very limited at the moment.

I'll eventually have some other comments, but it strikes me that this page could use a small example, if it is feasible to create one. Would you (or Peter) be willing to have a go at that?

Cheers,

Michael

Quoted 162 lines

Thank you
Jan

.\" Copyright (c) 2013, Peter Schiffer ([email protected]) .\"
.\" %%%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
.TH MEMUSAGE 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools"
.SH NAME
memusage \- profile memory usage of a program
.SH SYNOPSIS
.BR memusage " [\fIOPTION\fR]... \fIPROGRAM\fR [\fIPROGRAMOPTION\fR]..." .SH DESCRIPTION
.B memusage
is a bash script which can profile memory usage of a program. It preloads .B libmemusage.so
library to the user's environment using
.B LD_PRELOAD
environment variable. The
.B libmemusage.so
library traces memory allocation by intercepting calls to
.BR malloc (3),
.BR free (3),
.BR realloc (3)
and various other calls.
.PP
.B memusage
can output text representation of the collected data, or it can use
.BR memusagestat (1)
utility (see
.B -p
option)
to create a PNG file containing graphical representation
of the collected data.
.TP
List of monitored functions:
.RS
.BI "void *malloc(size_t " "size" );
.RE
.RS
.BI "void *calloc(size_t " "nmemb" ", size_t " "size" );
.RE
.RS
.BI "void *realloc(void " "*ptr" ", size_t " "size" );
.RE
.RS
.BI "void *mmap(void " "*addr" ", size_t " "length" ", int " "prot",
.BI "int " "flags" ", int " "fd" ", off_t " "offset");
.RE
.RS
.BI "void *mremap(void " "*old_address" ", size_t " "old_size",
.BI "size_t " "new_size" ", int " "flags",
.BI "... /* void " "*new_address" " */);"
.RE
.TP
Description of a memory usage summary:
.RE
\fBheap total\fR:
.RS
Sum of \fIsize\fR arguments of all malloc calls,
sum of all product of arguments (\fInmemb\fR*\fIsize\fR) of calloc call
and sum of \fIlength\fR arguments of mmap calls.
In a case of realloc, respectively mremap, if a new size of an original malloc,
respectively mremap call is bigger than an old one,
sum of all such differences (new size - old size) is added.
.RE
\fBheap peak\fR:
.RS
Maximum of all \fIsize\fR arguments of malloc,
all products of \fInmemb\fR*\fIsize\fR of calloc,
all \fIsize\fR arguments of realloc, \fIlength\fR arguments of mmap and \fInew_size\fR arguments of mremap.
.RE
\fBstack peak\fR:
.RS
Before the first call to any monitored function,
stack pointer address (base stack pointer) is saved.
After each function call, actual stack pointer address is read and
the difference between the base stack pointer computed.
Maximum of these differences is then the stack peak.
.RE

If a realloc function is called on a mallocced memory with a new size being smaller than an old one, total memory of realloc cell is not updated. This can cause sum of all cells (excluding free) of total memory being greater than free cell.
.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
Generate PNG graphic and store it in the file.
.TP
.BI \-d\ file \fR,\ \fB\-\-data= file
Generate binary data file and store it in the file.
.TP
.BI \-u\fR,\ \fB\-\-unbuffered
Do not buffer output.
.TP
.BI \-b\ size \fR,\ \fB\-\-buffer= size
Collect size entries before writing them out.
.TP
.BI \fB\-\-no-timer
Do not collect additional information through timer.
.TP
.BI \-m\fR,\ \fB\-\-mmap
Also trace mmap and friends.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.TP
The following options only apply when generating graphical output:
.TP
.BI \-t\fR,\ \fB\-\-time\-based
Make graph linear in time.
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph of total memory use.
.TP
.BI \fB\-\-title= name
Use the name as a title of the graph.
.TP
.BI \-x\ size \fR,\ \fB\-\-x\-size= size
Make graphic size pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
.SH EXIT STATUS
Exit status is equal to the exit status of profiled program. .SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
.SH SEE ALSO
.BR memusagestat (1),
.BR ld.so (8)

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#21 lore raw
Quoted 5 lines · Michael Kerrisk (man-pages)

Jan,

Quoted 2 lines · Jan Chaloupka

Hi,

Quoted 8 lines
Quoted 6 lines

memusage command is no documented. My collegue (95%) and I (5%) have written a man page for it. All informations come from inspecting the script code. This is the first script, others are memusagestat (1) and mtrace(1).

Feel free to comment or ask any question.

Thanks for these submissions. It will take me a while to get to looking at them more closely. My time is very limited at the moment.

Thank you for review.

Quoted 3 lines

I'll eventually have some other comments, but it strikes me that this page could use a small example, if it is feasible to create one. Would you (or Peter) be willing to have a go at that?

I will create one.

Quoted 168 lines

Cheers,

Michael

Quoted 162 lines

Thank you
Jan

.\" Copyright (c) 2013, Peter Schiffer ([email protected]) .\"
.\" %%%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
.TH MEMUSAGE 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools"
.SH NAME
memusage \- profile memory usage of a program
.SH SYNOPSIS
.BR memusage " [\fIOPTION\fR]... \fIPROGRAM\fR [\fIPROGRAMOPTION\fR]..." .SH DESCRIPTION
.B memusage
is a bash script which can profile memory usage of a program. It preloads .B libmemusage.so
library to the user's environment using
.B LD_PRELOAD
environment variable. The
.B libmemusage.so
library traces memory allocation by intercepting calls to
.BR malloc (3),
.BR free (3),
.BR realloc (3)
and various other calls.
.PP
.B memusage
can output text representation of the collected data, or it can use
.BR memusagestat (1)
utility (see
.B -p
option)
to create a PNG file containing graphical representation
of the collected data.
.TP
List of monitored functions:
.RS
.BI "void *malloc(size_t " "size" );
.RE
.RS
.BI "void *calloc(size_t " "nmemb" ", size_t " "size" );
.RE
.RS
.BI "void *realloc(void " "*ptr" ", size_t " "size" );
.RE
.RS
.BI "void *mmap(void " "*addr" ", size_t " "length" ", int " "prot",
.BI "int " "flags" ", int " "fd" ", off_t " "offset");
.RE
.RS
.BI "void *mremap(void " "*old_address" ", size_t " "old_size",
.BI "size_t " "new_size" ", int " "flags",
.BI "... /* void " "*new_address" " */);"
.RE
.TP
Description of a memory usage summary:
.RE
\fBheap total\fR:
.RS
Sum of \fIsize\fR arguments of all malloc calls,
sum of all product of arguments (\fInmemb\fR*\fIsize\fR) of calloc call
and sum of \fIlength\fR arguments of mmap calls.
In a case of realloc, respectively mremap, if a new size of an original malloc,
respectively mremap call is bigger than an old one,
sum of all such differences (new size - old size) is added.
.RE
\fBheap peak\fR:
.RS
Maximum of all \fIsize\fR arguments of malloc,
all products of \fInmemb\fR*\fIsize\fR of calloc,
all \fIsize\fR arguments of realloc, \fIlength\fR arguments of mmap and \fInew_size\fR arguments of mremap.
.RE
\fBstack peak\fR:
.RS
Before the first call to any monitored function,
stack pointer address (base stack pointer) is saved.
After each function call, actual stack pointer address is read and
the difference between the base stack pointer computed.
Maximum of these differences is then the stack peak.
.RE

If a realloc function is called on a mallocced memory with a new size being smaller than an old one, total memory of realloc cell is not updated. This can cause sum of all cells (excluding free) of total memory being greater than free cell.
.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
Generate PNG graphic and store it in the file.
.TP
.BI \-d\ file \fR,\ \fB\-\-data= file
Generate binary data file and store it in the file.
.TP
.BI \-u\fR,\ \fB\-\-unbuffered
Do not buffer output.
.TP
.BI \-b\ size \fR,\ \fB\-\-buffer= size
Collect size entries before writing them out.
.TP
.BI \fB\-\-no-timer
Do not collect additional information through timer.
.TP
.BI \-m\fR,\ \fB\-\-mmap
Also trace mmap and friends.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.TP
The following options only apply when generating graphical output:
.TP
.BI \-t\fR,\ \fB\-\-time\-based
Make graph linear in time.
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph of total memory use.
.TP
.BI \fB\-\-title= name
Use the name as a title of the graph.
.TP
.BI \-x\ size \fR,\ \fB\-\-x\-size= size
Make graphic size pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
.SH EXIT STATUS
Exit status is equal to the exit status of profiled program. .SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
.SH SEE ALSO
.BR memusagestat (1),
.BR ld.so (8)

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#23 lore raw

Adding example with small C code to demonstrate progress of memory usage

.\" Copyright (c) 2013, Peter Schiffer ([email protected]) .\"
.\" %%%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
.TH MEMUSAGESTAT 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools"
.SH NAME
memusagestat \- generate graphic from memory profiling data
.SH SYNOPSIS
.BR memusagestat " [\fIOPTION\fR]... \fIDATAFILE\fR [\fIOUTFILE\fR]"
.SH DESCRIPTION
.B memusagestat
can create a PNG file with graphical representation of memory profiling data.
Red line in the graph shows the heap usage (allocated memory),
green line shows the stack usage,
x-scale number of memory handling functions calls or time (\fB-t\fR option).
.I DATAFILE
is a binary data file generated by
.BR memusage (1)
utility with
.B -d
option.
.SH OPTIONS
.TP
.BI \-o\ file \fR,\ \fB\-\-output= file
Name of the output file.
.TP
.BI \-s\ string \fR,\ \fB\-\-string= string
Title string used in the output graphic.
.TP
.BI \-t\fR,\ \fB\-\-time
Generate output linear to time
(default is linear to number of function calls).
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph for total memory consumption.
.TP
.BI \-x\ size \fR,\ \fB\-\-x-size= size
Make graphic size pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.SH EXAMPLES
Here is a simple program \fImemusagestatexample.c\fR simulating increase and decrease of memory usage:

.RS 4
#include <stdio.h>
.RS 0
#include <stdlib.h>
.RE
.RS 0
#define CYCLES 20
.RE

int main(int argc, char ** argv) {
        int i, j;
        int *p = NULL;
        printf("malloc: %d\\n", sizeof(int)*100);
        p = malloc(sizeof(int)*100);

        for (i = 0; i < CYCLES; i++) {
                if (i < CYCLES/2) j = i; else j--;
                printf("realloc: %d\\n", sizeof(int)*((j)*50 + 110));
                p = realloc(p, sizeof(int)*(j*50 + 100));
                printf("realloc: %d\\n", sizeof(int)*((j+1)*150 + 110));
                p = realloc(p, sizeof(int)*((j+1)*150 + 110));
        }
        free(p);
        return 0;

.RS 0
}
.RE
.RE

After compiling and running the following, you can see progress of memory usage (memusagestatexample.png):

memusage --data=memusagestatexample.dat ./memusagestatexample .RS 0
memusagestat memusagestatexample.dat memusagestatexample.png .RE

.SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
.SH SEE ALSO
.BR memusage (1)
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#25 lore raw

ping

Quoted 118 lines · Jan Chaloupka

Adding example with small C code to demonstrate progress of memory usage

.\" Copyright (c) 2013, Peter Schiffer ([email protected]) .\"
.\" %%%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
.TH MEMUSAGESTAT 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools"
.SH NAME
memusagestat \- generate graphic from memory profiling data
.SH SYNOPSIS
.BR memusagestat " [\fIOPTION\fR]... \fIDATAFILE\fR [\fIOUTFILE\fR]"
.SH DESCRIPTION
.B memusagestat
can create a PNG file with graphical representation of memory profiling data.
Red line in the graph shows the heap usage (allocated memory),
green line shows the stack usage,
x-scale number of memory handling functions calls or time (\fB-t\fR option).
.I DATAFILE
is a binary data file generated by
.BR memusage (1)
utility with
.B -d
option.
.SH OPTIONS
.TP
.BI \-o\ file \fR,\ \fB\-\-output= file
Name of the output file.
.TP
.BI \-s\ string \fR,\ \fB\-\-string= string
Title string used in the output graphic.
.TP
.BI \-t\fR,\ \fB\-\-time
Generate output linear to time
(default is linear to number of function calls).
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph for total memory consumption.
.TP
.BI \-x\ size \fR,\ \fB\-\-x-size= size
Make graphic size pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.SH EXAMPLES
Here is a simple program \fImemusagestatexample.c\fR simulating increase and decrease of memory usage:

.RS 4
#include <stdio.h>
.RS 0
#include <stdlib.h>
.RE
.RS 0
#define CYCLES 20
.RE

int main(int argc, char ** argv) {
        int i, j;
        int *p = NULL;
        printf("malloc: %d\\n", sizeof(int)*100);
        p = malloc(sizeof(int)*100);

        for (i = 0; i < CYCLES; i++) {
                if (i < CYCLES/2) j = i; else j--;
                printf("realloc: %d\\n", sizeof(int)*((j)*50 + 110));
                p = realloc(p, sizeof(int)*(j*50 + 100));
                printf("realloc: %d\\n", sizeof(int)*((j+1)*150 + 110));
                p = realloc(p, sizeof(int)*((j+1)*150 + 110));
        }
        free(p);
        return 0;

.RS 0
}
.RE
.RE

After compiling and running the following, you can see progress of memory usage (memusagestatexample.png):

memusage --data=memusagestatexample.dat ./memusagestatexample .RS 0
memusagestat memusagestatexample.dat memusagestatexample.png .RE

.SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
.SH SEE ALSO
.BR memusage (1)

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 11 lines
Jan Chaloupka
------------------------------
* Software Engineer          *
* ENG Base Operating Systems *
* Red Hat Czech, s. r. o.    *
* UTC+1 (CET), jchaloup      *

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#26 lore raw
In reply to a message not in the archive

Hi Jan,

You resubmitted this page in the meusage(1) thread, but it's a page for memusagestat(1). I'm getting a little confused as I try to review these threads.

Could I ask you to create two new threads that submit the current memusage.1 and memusagestat.1 pages. Along the way, could you convert the keywords in the command lines to lowercase+italic (\fI). (See for example the current mtrace.1 in Git.)

My apologies for being so slow to follow up on this.

Thanks,

Michael

Quoted 118 lines · Jan Chaloupka

Adding example with small C code to demonstrate progress of memory usage

.\" Copyright (c) 2013, Peter Schiffer ([email protected]) .\"
.\" %%%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
.TH MEMUSAGESTAT 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools" .SH NAME
memusagestat \- generate graphic from memory profiling data
.SH SYNOPSIS
.BR memusagestat " [\fIOPTION\fR]... \fIDATAFILE\fR [\fIOUTFILE\fR]"
.SH DESCRIPTION
.B memusagestat
can create a PNG file with graphical representation of memory profiling data.
Red line in the graph shows the heap usage (allocated memory),
green line shows the stack usage,
x-scale number of memory handling functions calls or time (\fB-t\fR option). .I DATAFILE
is a binary data file generated by
.BR memusage (1)
utility with
.B -d
option.
.SH OPTIONS
.TP
.BI \-o\ file \fR,\ \fB\-\-output= file
Name of the output file.
.TP
.BI \-s\ string \fR,\ \fB\-\-string= string
Title string used in the output graphic.
.TP
.BI \-t\fR,\ \fB\-\-time
Generate output linear to time
(default is linear to number of function calls).
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph for total memory consumption.
.TP
.BI \-x\ size \fR,\ \fB\-\-x-size= size
Make graphic size pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.SH EXAMPLES
Here is a simple program \fImemusagestatexample.c\fR simulating increase and decrease of memory usage:

.RS 4
#include <stdio.h>
.RS 0
#include <stdlib.h>
.RE
.RS 0
#define CYCLES 20
.RE

int main(int argc, char ** argv) {
         int i, j;
         int *p = NULL;
         printf("malloc: %d\\n", sizeof(int)*100);
         p = malloc(sizeof(int)*100);

         for (i = 0; i < CYCLES; i++) {
                 if (i < CYCLES/2) j = i; else j--;
                 printf("realloc: %d\\n", sizeof(int)*((j)*50 + 110));
                 p = realloc(p, sizeof(int)*(j*50 + 100));
                 printf("realloc: %d\\n", sizeof(int)*((j+1)*150 + 110));
                 p = realloc(p, sizeof(int)*((j+1)*150 + 110));
         }
         free(p);
         return 0;

.RS 0
}
.RE
.RE

After compiling and running the following, you can see progress of memory usage (memusagestatexample.png):

memusage --data=memusagestatexample.dat ./memusagestatexample .RS 0
memusagestat memusagestatexample.dat memusagestatexample.png .RE

.SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
.SH SEE ALSO
.BR memusage (1)

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#28 lore raw

Hello, Michael

Quoted 5 lines · Michael Kerrisk (man-pages)

Hi Jan,

You resubmitted this page in the meusage(1) thread, but it's a page for memusagestat(1). I'm getting a little confused as I try to review these threads.

Oh, sorry about that. Man pages resent with changelog.

Quoted 7 lines

Could I ask you to create two new threads that submit the current memusage.1 and memusagestat.1 pages. Along the way, could you convert the keywords in the command lines to lowercase+italic (\fI). (See for example the current mtrace.1 in Git.)

My apologies for being so slow to follow up on this.

No big deal. These man pages are of low priority.

Quoted 127 lines

Thanks,

Michael

Quoted 118 lines · Jan Chaloupka

Adding example with small C code to demonstrate progress of memory usage

.\" Copyright (c) 2013, Peter Schiffer ([email protected]) .\"
.\" %%%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
.TH MEMUSAGESTAT 1 2013-04-10 "GNU glibc 2.18" "Memory diagnostic tools" .SH NAME
memusagestat \- generate graphic from memory profiling data
.SH SYNOPSIS
.BR memusagestat " [\fIOPTION\fR]... \fIDATAFILE\fR [\fIOUTFILE\fR]"
.SH DESCRIPTION
.B memusagestat
can create a PNG file with graphical representation of memory profiling data.
Red line in the graph shows the heap usage (allocated memory),
green line shows the stack usage,
x-scale number of memory handling functions calls or time (\fB-t\fR option). .I DATAFILE
is a binary data file generated by
.BR memusage (1)
utility with
.B -d
option.
.SH OPTIONS
.TP
.BI \-o\ file \fR,\ \fB\-\-output= file
Name of the output file.
.TP
.BI \-s\ string \fR,\ \fB\-\-string= string
Title string used in the output graphic.
.TP
.BI \-t\fR,\ \fB\-\-time
Generate output linear to time
(default is linear to number of function calls).
.TP
.BI \-T\fR,\ \fB\-\-total
Also draw graph for total memory consumption.
.TP
.BI \-x\ size \fR,\ \fB\-\-x-size= size
Make graphic size pixels wide.
.TP
.BI \-y\ size \fR,\ \fB\-\-y\-size= size
Make graphic size pixels high.
.TP
.BI \-?\fR,\ \fB\-\-help
Print help and exit.
.TP
.BI \fB\-\-usage
Print a short usage message and exit.
.TP
.BI \-V\fR,\ \fB\-\-version
Print version information and exit.
.SH EXAMPLES
Here is a simple program \fImemusagestatexample.c\fR simulating increase and decrease of memory usage:

.RS 4
#include <stdio.h>
.RS 0
#include <stdlib.h>
.RE
.RS 0
#define CYCLES 20
.RE

int main(int argc, char ** argv) {
          int i, j;
          int *p = NULL;
          printf("malloc: %d\\n", sizeof(int)*100);
          p = malloc(sizeof(int)*100);

          for (i = 0; i < CYCLES; i++) {
                  if (i < CYCLES/2) j = i; else j--;
                  printf("realloc: %d\\n", sizeof(int)*((j)*50 + 110));
                  p = realloc(p, sizeof(int)*(j*50 + 100));
                  printf("realloc: %d\\n", sizeof(int)*((j+1)*150 + 110));
                  p = realloc(p, sizeof(int)*((j+1)*150 + 110));
          }
          free(p);
          return 0;

.RS 0
}
.RE
.RE

After compiling and running the following, you can see progress of memory usage (memusagestatexample.png):

memusage --data=memusagestatexample.dat ./memusagestatexample .RS 0
memusagestat memusagestatexample.dat memusagestatexample.png .RE

.SH BUGS
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
.SH SEE ALSO
.BR memusage (1)

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html