08.06.2015, 15:10, "Peter Toft" <[email protected]>:
> Hi guys
>
> I have some C/C++ programs that use very odd memory usage. I have made a
> small replica below
> (it can also be taken from http://pastebin.com/1ammgpCE)
> Save e.g. as memfun.c
>
> In the C-code I generate 20 peaks of very short memory peaks, and you
> can compile (on Linux) and run as this:
> gcc -o memfun memfun.c -lm
> valgrind --tool=massif --massif-out-file=massif.out ./memfun
> massif-visualizer massif.out
> or
> ms_print massif.out > massif.txt; less massif.txt)
>
> (BTW; Thanx to the maintainers of massif-visualizer - this rocks)
>
> However with the standard settings I only get 3 memory peaks detected -
> not 20.
> Obviously I can tweak --threshold= and --peak-inaccuracy= but it seems
> that
> I in general can be sure that I can catch all peaks. Please comment :-)
>
> Are these something that I miss here? Are there other tools that are
> better suited for
> detecting memory peaks like this memory-hedgehog....
Use --time-unit=B
>
> Thanx mates
>
> Best
>
> Peter
>
> ----------------
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
>
> /*
> Demo program:
> gcc -o memfun memfun.c -lm
> valgrind --tool=massif --massif-out-file=massif.out ./memfun
> massif-visualizer massif.out
> (or ms_print massif.out > massif.txt; less massif.txt)
> */
>
> int main(void)
> {
> int ii,jj;
> int *pt;
> int *pt2;
> float ac;
> int numberOfPeaks = 0;
>
> for (ii=0;ii<100;ii++) {
> /* Allocate some small linearly increasing memory block */
> pt = (int *)malloc((1000*ii+1)*sizeof(int));
> if (ii%5 == 0) {
> /* Allocate some gigantic memory block - but only every 10th
> iteration */
> pt2 = (int *)malloc((1000000)*sizeof(int));
> printf("Allocating large memory block\n");
> numberOfPeaks++;
> } else {
> /* Allocate just one element for every 9/10 iteration */
> pt2 = (int *)malloc((1)*sizeof(int));
> }
> /* Put in data and print it */
> pt2[0] = ii;
> printf(" Found value %i\n",pt2[0]);
> /* Free the memory - note that the peak */
> free(pt2);
>
> /* Spend time on "something" - the actual work does not matter*/
> ac = 1;
> for (jj=0;jj<10000*(1 + ii);jj++) {
> ac += sin(jj*0.01) + cos(jj*0.01 + 0.3);
> }
> printf(" Found dummy value %f\n",ac);
> /* Free the memory */
> free(pt);
> }
> printf("I made %i memory peaks\n",numberOfPeaks);
> return 0;
> }
>
> --
> Peter Toft <[email protected]>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Valgrind-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
--
Regards,
Konstantin
------------------------------------------------------------------------------
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users