LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Gprof does not profile system API? (https://www.linuxquestions.org/questions/programming-9/gprof-does-not-profile-system-api-528553/)

George2 02-13-2007 01:50 AM

Gprof does not profile system API?
 
Hello everyone,


I have used gprof to generat the time elapsed in each of the function in my little program. But the time elapsed in system API have not been calculated, like open, read, close, memset, etc.

I am wondering how to enable gprof to calculate time elapsed in system API?


thanks in advance,
George

wjevans_7d1@yahoo.co 02-13-2007 05:31 AM

I don't think you can, directly.

The only thing you can do is write wrapper functions for each of the system calls in which you're interested.

For example, if you're interested in including all your read() calls, write a wrapper function Read() with the same type as read() and whose parameters have the same type as the parameters for read(). Have Read() call read() and return the value that read() does. Then replace all your calls to read() (except the one in Read()) with calls to Read().

There are other reasons for writing wrapper functions for system calls. These reasons concern maintainability of your program. For example, if you later want to come back to your program and do something special for error recovery for all open() calls in your program, you can put that error recovery in just one place: your Open() function. It's also good for debugging, if you want to place a breakpoint (or do a debugging display of data) for every open() call, for example.

George2 02-13-2007 05:51 AM

Thanks wjevans_7d1!


Quote:

Originally Posted by wjevans_7d1@yahoo.co
I don't think you can, directly.

The only thing you can do is write wrapper functions for each of the system calls in which you're interested.

For example, if you're interested in including all your read() calls, write a wrapper function Read() with the same type as read() and whose parameters have the same type as the parameters for read(). Have Read() call read() and return the value that read() does. Then replace all your calls to read() (except the one in Read()) with calls to Read().

There are other reasons for writing wrapper functions for system calls. These reasons concern maintainability of your program. For example, if you later want to come back to your program and do something special for error recovery for all open() calls in your program, you can put that error recovery in just one place: your Open() function. It's also good for debugging, if you want to place a breakpoint (or do a debugging display of data) for every open() call, for example.

I have found that the total time reported on the flat profile is not equal to the whole run time of the program, is it because that the elapsed time in system API is not considered in the report of gprof flat profile?

(I calculate roughly in this way, the top function consumes 10 seconds, and it takes 10% of total time as displayed in gprof report, so the total time in gprof should be 100 seconds. But I have manually calculated that the whole time should be roughly 200 seconds.)


regards,
George

matthewg42 02-13-2007 06:11 AM

You might be interested in this: http://oprofile.sourceforge.net/about/

George2 02-13-2007 07:13 AM

Thanks matthewg42, I will try it. :-)

Currently, why I use gprof is because I need to run it for various machines (x86 and other architecture). I am not sure whether the tool you introduced has the capability.

Anyway, could you answer my original question please?

my original question,

--------------------
I have found that the total time reported on the flat profile is not equal to the whole run time of the program, is it because that the elapsed time in system API is not considered in the report of gprof flat profile?

(I calculate roughly in this way, the top function consumes 10 seconds, and it takes 10% of total time as displayed in gprof report, so the total time in gprof should be 100 seconds. But I have manually calculated that the whole time should be roughly 200 seconds.)
--------------------

Quote:

Originally Posted by matthewg42
You might be interested in this: http://oprofile.sourceforge.net/about/


regards,
George

matthewg42 02-13-2007 07:36 AM

gprof will only give you profiling for routines built to include the profiling code. Since you'll be linking to libraries which are not compiled with the profiling code, you won't see stats for functions in those libraries (unless you built them yourself and turned profiling on).

I'm not certain, but I suspect you'd need to use another mechanism to profile kernel routines.

oprofile uses a different mechanism to extract profiling data.

George2 02-13-2007 07:52 AM

Thanks matthewg42,


Seems oprofile is more appropriate. :-)

I will use cross compile tool (for example, Monta Vista Linux) to compile my program, and run it on various H/W. I want to profile the time elapsed on each real H/W (other than the machine I compile/link my program) for my program. I am not sure whether oprofile could meet with my requirement.


Quote:

Originally Posted by matthewg42
gprof will only give you profiling for routines built to include the profiling code. Since you'll be linking to libraries which are not compiled with the profiling code, you won't see stats for functions in those libraries (unless you built them yourself and turned profiling on).

I'm not certain, but I suspect you'd need to use another mechanism to profile kernel routines.

oprofile uses a different mechanism to extract profiling data.


regards,
George

matthewg42 02-13-2007 07:57 AM

I haven't used it extensively, and certainly not across multiple platforms. I'd be interested to know what you find out - if it does what you need.

Good luck

George2 02-13-2007 08:08 AM

Thanks matthewg42. I am not sure whether whether there are some oprofile experts here could answer.


Quote:

Originally Posted by matthewg42
I haven't used it extensively, and certainly not across multiple platforms. I'd be interested to know what you find out - if it does what you need.

Good luck


regards,
George


All times are GMT -5. The time now is 03:02 AM.