Title: Profiling time spent in I/O C++
Tags: c++;linux;profiling
Question: I have a function which it taking 11 seconds.
I want to profile how much time it is spending in I/O.
Is there any tool for for profiling I/O time spend inside a function ?
Which can give statics like
Total Time  I/O TIME Function Name
x           y        f
Comment: Do you have a clear definition of what time spent in I/O really means? Linux has quite good file system caching, and it impacts the time spent on I/O. Just try to run several times the same program with the same inputs...

Comment: Disabling the file cache is not simple, and is not representative of common runtime situations.

Comment: Don't disable the file cache (and I don't know how to do that), because it is not representative of usual runtime situations. The usual user is expecting the file system cache to work.

Comment: http://stackoverflow.com/questions/3922206/profiling-line-by-line-in-c

Comment: @cnicutar sorry I am new to gprof. sample gprof example
0.00      0.06     0.00        1     0.00    50.00  main
from this how can I make out how much time it spend in I/O ?

Comment: @Basile Starynkevitch
I will try by disabling file cache.

Comment: @tauran
I tried looking old question. But other question are focused on profiling by excluding I/O time.
But my question is I need all times
Total Time , I/O time and cpu times for profile data.

Comment: @tauran That is focus on windows and visual studio. my question is about linux.

Comment: @Basile Starynkevitch
Then I will run a cron job to drop cache. :)
Is there any better idea to disable file cache ?

Here is the accepted answer: This method will tell you.
Just pause it like 10 times.
Each time look at the stack.
If you catch it in the process of doing IO on, say, 6 of those pauses, that means about 60% of its time is in IO.
If you want to know how much of that was spent in IO requested by function F, just count the number of samples that were doing IO when function F was on the stack.
(gprof will not tell you this, because it suspends sampling during IO.)
Added: Alternatively, you could just stub out the IO calls in function F, and measure overall time with and without IO.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 9, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:04/10/12', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<c++><linux><profiling>', 'Title': 'Profiling time spent in I/O C++', 'ViewCount': 1507, 'id': 10085268, 'user_AboutMe': '', 'user_AccountId': 189393.0, 'user_DisplayName': 'Vivek Goel', 'user_Reputation': 21714.0, 'user_Views': 1148.0, 'user_id': 428705.0}}