5

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  
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
  • 1
    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... – Basile Starynkevitch Apr 10 '12 at 08:21
  • @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 ? – Vivek Goel Apr 10 '12 at 09:10
  • @Basile Starynkevitch I will try by disabling file cache. – Vivek Goel Apr 10 '12 at 09:11
  • @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. – Vivek Goel Apr 10 '12 at 09:13
  • http://stackoverflow.com/questions/3922206/profiling-line-by-line-in-c – tauran Apr 10 '12 at 09:50
  • @tauran That is focus on windows and visual studio. my question is about linux. – Vivek Goel Apr 10 '12 at 10:05
  • 1
    Disabling the file cache is not simple, and is not representative of common runtime situations. – Basile Starynkevitch Apr 10 '12 at 10:10
  • @Basile Starynkevitch Then I will run a cron job to drop cache. :) Or Is there any better idea to disable file cache ? – Vivek Goel Apr 10 '12 at 10:23
  • 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. – Basile Starynkevitch Apr 10 '12 at 10:36

1 Answers1

3

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.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135