On Wed, 22 Feb 2006, Sandeep Kumar wrote:
On 2/21/06, Gaurav Dhiman <gauravd.chd@xxxxxxxxx> wrote:
you can use -pg option of gcc along with gprof utility.
read more about this on
http://www.gnu.org/software/binutils/manual/gprof-2.9.1/gprof.html
regards,
-Gaurav
On 2/21/06, Manav Kataria <manav@xxxxxxxxxxxxx> wrote:
Greetings,
Hi I wanted to profile time taken by a particular funtion in an
application. I had been using gettimeofday() till now and calculating the
time diff b/w the call of the function and its return.
I read in a forum that even though it shows a resolution of microseconds
it is incorrect. The true resolution is only the order of microseconds. Is
the microsecond part really unreliable (fake) ??
How do I profile my code other wise ?
Thanks in advance,
MK
Try this out !!!!
static unsigned int ms = 0;
static struct timeval start_tm,cur_tm;
do_gettimeofday(&start_tm);
ms = (cur_tm.tv_sec*1000000+cur_tm.tv_usec)-
(start_tm.tv_sec*1000000+start_tm.tv_usec) + 1;
printk("%10ld.%3ld ms",ms/1000, ms%1000);
Call the system call
do_gettimeofday( &cur_tm );
ms = (cur_tm.tv_sec*1000000+cur_tm.tv_usec)-
(start_tm.tv_sec*1000000+start_tm.tv_usec) + 1;
printk("%10ld.%3ld ms",ms/1000, ms%1000);
Its provided by Srinivas in an earlier thread.
Is this a user-space application or kernel module, you want to profile?
If the first I don't understand the use of printk.
You can use oprofile.
oprofile can profile user-space as well as kernel modules.
I think oprofile can give you profile information about lines within a
function (and not only the overall cost of the function). I don't know how
accurate this is, and don't put too much trust into it myself.
I also use clock():
int func() {
...
...
start = clock();
__code to profile__
total += clock() - start;
...
}
This is not very accurate, but gives you some feeling on your code.
Hayim.
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/