Find the answer to your Linux question:
Results 1 to 6 of 6
Hi,, the gprof tool in order to get the information, the application should return from main() or call exit(). what if a program runs into a while loop all the ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29

    profiling "gprof" inquiry??

    Hi,,
    the gprof tool in order to get the information, the application should return from main() or call exit(). what if a program runs into a while loop all the time i.e. while(1)
    how we can get over this issue to generate "gmon.out" ??
    thanks

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I did this at the command line:
    Code:
    man gprof
    and got text which included this:
    Code:
           The profiled program must call "exit"(2) or return nor-
           mally for the profiling information to be saved in the
           gmon.out file.
    So it would seem that your only way to solve this is to grab the gprof code and add a new feature.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29

    reply1

    Quote Originally Posted by wje_lf View Post
    So it would seem that your only way to solve this is to grab the gprof code and add a new feature.
    HI,,
    it seems to be difficult for me in this stage to modify gprof. do u know any alternative way to compute the execution time of certain functions or how many times were calls, etcc....
    Thanks

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    The only alternative that comes to mind is to place code within each function that modifies a global count and a global number of runtime seconds or microseconds.

    What might make that easier is to define two macros: one which is used at the beginning of each function of interest, and one which is used at each exit point (the end of the function and just before each return statement) of that function.

    If the code is sufficiently regular, you might want to develop a Perl script or something to modify the code for you, and then go through and clean up the modifications if necessary.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Dec 2007
    Posts
    29
    Quote Originally Posted by wje_lf View Post
    The only alternative that comes to mind is to place code within each function that modifies a global count and a global number of runtime seconds or microseconds.
    thanks
    could u give me hint or what functions/system calls can be used for that?
    thanks

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    The only useful function you might not already use is gettimeofday(), which shows the time of day down to the microsecond. Remember, though, that although the precision is down to the microsecond, the accuracy is likely to be much less, maybe down to 10 milliseconds. But for gathering statistics on runtimes, you're not likely to need anything more accurate than that.

    If your application is I/O bound and you're also interested in compute time, you might also want to use times(). In addition to providing compute time, it will also provide you with the amount of time elapsed since an arbitrary point in the past, which is useful if it's possible that you'll be running these tests while the system's time of day is being reset, either manually or because of change between standard time and daylight time. gettimeofday() would give you false elapsed time measurements in this case.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...