Thread: programming profiling using profil

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    10

    programming profiling using profil

    Hi,

    I want to profile my multithreaded (pthreads) program, and I found that I can use profil tool of linux. (man profil).

    But it does require arguments like:
    int profil(char *samples, size_t size, u_long offset, u_int scale);
    and I really dont know how to provide these arguments. Does any body has experience in writing program using profil, or perhaps write a sample code to let me know to specify a specific code in a thread to profile

    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This page: http://linux.about.com/library/cmd/blcmdl3_profil.htm
    says:
    buffer is a block or memoyr, bufsiz it's size.
    offset and scale are used to scale down the results to fit into a smaller buffer.

    Offset would be the first address that you want to profile.
    Scale allows you to determine how fine-grained the profiling should be - if you want to profile every byte, give it a value of 65536 - that essentially means that your buffer needs to be 2 x the size of the code you are profiling. A smaller scale gives you less precise results, but you don't need as large a buffer.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    10
    thanks,

    how to specify the block of memory, if i want to profile between two points in a thread:

    thread ()
    {
    ....
    point1:
    ...

    point2:

    profile(.....)
    }
    how do i specify the block of memory for these two points. and how do i know the size of the block in memory.
    so for i understand offset if the beginning address of the block, size is how long is the block, but how to specify these parameters. Also when the profiling returns does it return the count of the clock ticks.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If we assume that point1 and point2 isn't many megabytes of code apart (reasonable assumption if it's a thread function, I believe), then I would set the scale to 65536, and try to figure out the size fo the thread function itself - for example by taking the address of the thread function and the function after - allocate that size times sizeof(u_short).

    If thread calls a lot of other functions, find the first function and the end of the last function that you call, and use that for size.

    If you want to save a bit of memory, set scale to 32768 and half the allocation size - or 16384 and a quarter of the allocation size.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    10
    If I am right I can get address of a function like this

    void (*foo)() = NULL;
    foo = &thread;

    but it does return me 1 always, any idea to get it correctly?

    how to make the buf to point to the block of memory in between two functions?

    Thanks

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, you don't want buf to point to the code - you want buf to point to a chunk of memory with a size corresponding to the size of code you want to profile (e.g. that size * sizeof(u_short)) - for example, you can allocate it using malloc, or have a fixed size array of u_short buffer[2000] if you think 2000 bytes will cover your function).

    Not sure how &thread can be 1. But &thread would be a good value for "offset".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. profiling
    By zaac in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2009, 10:06 AM
  2. Profiling for c code in eclipse
    By hai12345 in forum C Programming
    Replies: 2
    Last Post: 10-10-2008, 04:46 PM
  3. I can't get profiling to work with Visual Studio 6
    By Darkness in forum C++ Programming
    Replies: 7
    Last Post: 12-30-2004, 10:37 PM
  4. Memory profiling and debugging tools
    By nickname_changed in forum Linux Programming
    Replies: 4
    Last Post: 09-14-2004, 03:58 PM
  5. Enabling Profiling in VS.NET
    By xds4lx in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-17-2002, 01:10 PM