LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2007, 01:50 AM   #1
George2
Member
 
Registered: Oct 2003
Posts: 354

Rep: Reputation: 30
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
 
Old 02-13-2007, 05:31 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.

Last edited by wjevans_7d1@yahoo.co; 02-13-2007 at 05:32 AM.
 
Old 02-13-2007, 05:51 AM   #3
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
Old 02-13-2007, 06:11 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
You might be interested in this: http://oprofile.sourceforge.net/about/
 
Old 02-13-2007, 07:13 AM   #5
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
Old 02-13-2007, 07:36 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.

Last edited by matthewg42; 02-13-2007 at 07:37 AM.
 
Old 02-13-2007, 07:52 AM   #7
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
Old 02-13-2007, 07:57 AM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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
 
Old 02-13-2007, 08:08 AM   #9
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get all invoked system API of a program George2 Programming 3 07-21-2006 02:12 AM
system profile vs user profile bonito SUSE / openSUSE 3 06-28-2006 01:02 PM
C/C++ API for retrieving system time in micro or milliseconds syseeker Programming 1 05-04-2006 07:15 AM
System profile in My LQ guideweb LQ Suggestions & Feedback 2 08-03-2005 09:36 AM
gprof - annotate source, profile directed compiling iansworld Linux - Software 0 03-25-2005 12:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration