Why does profiler include idle time?

3 views (last 30 days)
The Matlab profiler is behaving in ways I do not expect. For example, I have a very simple function that looks like this:
function ptest(N)
a=fftn(randn(N,N,N));
Now If I paste this text into the matlab command window:
profile on
tic
ptest(300);
toc
profile report
I get a profile report that tells me that the function ptest ran for 0.94 seconds (fairly consistent with toc) with the fft line taking nearly all the time and being called exactly once... so far so good!
However, if I then type this code into the profiler:
profile on
tic
ptest(300);
toc
pause(8)
toc
profile report
I have two toc lines... one gives 1.09 seconds and the other gives 9.10 seconds (all this makes sense). However, the profiler tells me that the function call took 8.923 seconds! In fact, if I wait another 10 seconds and type profile report again, it tells me the function call took 19 seconds!
  4 Comments
Jed
Jed on 13 May 2015
Thanks for checking... something wrong with my specific configuration, I guess. A colleague running windows got the right answer like you did... I tried adding the (optional?) "end" statement, and still got the same weird result.
Jed
Jed on 14 May 2015
Edited: Jed on 14 May 2015
@per isakson: Thanks so much for checking this! The proposed answer by Philip below could explain this behavior if you are using windows. If he is correct, I would expect windows to still have the following problem, which I would try to verify if I had Matlab for windows:
type in the command window:
profile on
ptest(300)
Now wait 10 seconds and then type
profile report
If Philip is right, I would expect that even the windows version of matlab would give funny results because everything would be normalized to the wall clock time between the initial command "profile on" and the eventual command "profile report"

Sign in to comment.

Accepted Answer

Philip Borghesani
Philip Borghesani on 14 May 2015
Edited: Philip Borghesani on 14 May 2015
This is a bug/feature in recent versions of the profiler through R2015a. On Mac/Linux the profiler times with processor time by default and on Windows it times with a wall clock timer. In both cases the time is normalized to the wall clock duration after profiling. Pause uses no processor time so on Linux you get 0 or nearly 0 time for the pause statement. The normalization process hides the fact that if you have 4 cores the fft statement might have used 4 seconds of processor time in 1 second of wall clock time.
Unfortunately the normalization also distorts the times in the presence of functions like pause that use no processor time.
To get the same results on both platforms issue the command:
profile -timer real
  4 Comments
Jed
Jed on 15 May 2015
A friend of mine tested this out under windows and it did not behave this way. He ran code that took 10 seconds using cputime. Whether he asked for the profile report immediately or waited an additional 10 seconds before opening the report, the profiler gave the correct answer. If it can be fixed for windows, why not linux?
Anyway, I will use your suggestion and run the profiler like you suggest going forward. Thanks. I hope others benefit from your suggestion.
Philip Borghesani
Philip Borghesani on 15 May 2015
Windows does not show the issue because sitting at the command prompt, though not visible in profiler output, is timed and added to the total for compensation purposes but on Linux it is timed with CPU time which will again be near zero.
The best I can say about any bug fix is point out the opening sentence of my answer: This is a bug/feature in recent versions of the profiler through R2015a

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!