Thank you Milian Wolff and Eliot Moss,
When attempting to profile the total memory usage of my small application,
which I called tail according to the Excercise 5-13 of the C Programming
Language (second edition) by Brian W. Kernighan and Denis M. Richie, if I
try to run valgrind like this:
cat ~/my_lfs_7_4_notes_for_1.6.2.txt | valgrind --tool=massif --stacks=yes
--time-unit=B ./tail -n1000
It looks like the program uses a max of 3,360 bytes of memory (all stack
usage).
But in 2 of my source files I have allocations like this:
#define MAXLINES 1000L /* max lines to be stored */
static char *lineptr[MAXLINES]; /* pointers to text lines */
#define BUFSIZE 33000UL /* size of available buffer space */
static char buf[BUFSIZE]; /* array of BUFSIZE to store lines */
#define MAXLENGTH 1000 /* set the maximum line length stored */
char s[MAXLENGTH]; /* storage for get_line function */
>From this I estimate memory usage should be in excess of 42,000 bytes.
The closest that I can seem to get to a real representation of memory used
is if I subtract the amount reported for an empty program from the amount
reported for this program when I use the option --pages-as-heap=yes as
follows:
cat ~/my_lfs_7_4_notes_for_1.6.2.txt | valgrind --tool=massif
--pages-as-heap=yes --time-unit=B ./tail -n1000
valgrind --tool=massif --pages-as-heap=yes --time-unit=B ./just_return
Then calculate the difference in memory usage reported for the 2 runs...
6,234,112 - 6,189,056 = 45,056
This seems more like the impact that my code has had on memory usage and
represents the part I can change or optimize, since I have no control over
whatever created the other 6 million bytes of usage even with an entirely
empty c program (or whether the libraries are shared or not). Is this a
fair assessment?
I'm guessing the C code stored on disk is also in memory somewhere when the
program is loaded. Though I have difficulty seeing that in these memory
outputs and can only guess how the size of my compiled code affects memory
usage.
Thank you for the feedback. Books and documentation just never seems to be
enough to learn this stuff.
Rob Taylor
On Wed, May 14, 2014 at 2:43 AM, Milian Wolff <m...@milianw.de> wrote:
> On Tuesday 13 May 2014 19:13:23 Eliot Moss wrote:
> > On 5/13/2014 6:49 PM, Rob Taylor wrote:
> > > I recently discovered valgrind while searching for a way to see how
> much
> > > memory (total memory footprint) my small program represented.
> > >
> > > I was perplexed by the results I was seeing, since I expected at most
> to
> > > use perhaps tens of thousands of bites not Millions. My application is
> > > not dynamically requesting/allocating memory, all memory consumed is in
> > > the form of statically assigned character arrays, automatic stack usage
> > > etc..
> > >
> > > So I did a test by running valgrind against an empty C program. The
> > > program does nothing but return. Can someone explain why the output
> shows
> > > continually increasing memory used and in total over a 6 MB peak?
> >
> > Dynamically linked libraries and their data. Some of that
> > (most of the code areas) can be shared in real memory with
> > other programs using the same library. There's a lot of
> > mechanism there, even if you are not using much of it, and
> > even if you are using parts of it without realizing it ...
>
> Yep, you are investigating on the page level, which is different from what
> you
> allocate. Remove that argument, but try --stacks=yes instead.
>
> Bye
>
> --
> Milian Wolff
> m...@milianw.de
> http://milianw.de
>
>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform
> available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> Valgrind-users mailing list
> Valgrind-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users