Thread: profiling for memory usage

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    53

    profiling for memory usage

    I want to profile program for memory usage (both physical and virtual) per functions.
    More precisely i've tried both valgrind and grof with no luck.
    Is there for debian smth better?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    What do you mean 'profile' memory usage?

    Code:
    void foo ( char *p ) {
      for ( i = 0 ; i < n ; i += 100 ) *p = 0;
    }
    void bar ( char *p ) {
      for ( i = 0 ; i < n ; i++ ) *p = 1;
    }
    int main ( ) {
      char *p = malloc(n);
      bar(p);
      foo(p);
      free(p);
    }
    All 3 functions use the same amount of memory (from one point of view at least).
    From another point of view, main doesn't use any, and foo uses only 1% of what bar uses.

    Would cachegrind help?
    Valgrind
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    53
    By profiling memory usage i mean output like that:
    <func_name> <mem allocated inside> <mem deallocated inside>
    ... ... ...

    cachegrind? No, it's for simulating of processor cache (or at least i don't see, maybe i'm wrong?). Memcheck should do so, bt it isn't.


    Now i'm trying to work with gperftools with no luck yet because it seems buggy

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    So for my example program
    main.c:8 allocated n bytes
    main.c:11 freed n bytes

    And so on, for each unique block of allocated memory.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    53
    what is about? valgrind --tools=cachegrind?

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    53
    moreover i need tool to be able to print whole stack if memory changes even inside library (a static one with debug symbols).

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    53
    Wonderful link
    But nothing works proprerly, CCMALLOC too old and have Seg Fault inside, Under gperftools i'm suffering on:
    this
    tried Dmalloc, - too complicated, and seems to be unusable for external library.
    What else do you propose?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory / CPU Usage
    By javaeyes in forum C Programming
    Replies: 3
    Last Post: 02-27-2012, 06:19 PM
  2. Memory Usage
    By MK27 in forum Linux Programming
    Replies: 2
    Last Post: 07-16-2009, 05:52 PM
  3. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  4. Memory profiling and debugging tools
    By nickname_changed in forum Linux Programming
    Replies: 4
    Last Post: 09-14-2004, 03:58 PM
  5. Memory Usage
    By ghe1 in forum Linux Programming
    Replies: 0
    Last Post: 03-18-2002, 09:43 AM