Why does profiler include idle time?

조회 수: 9 (최근 30일)
Jed
Jed 2015년 5월 13일
편집: Philip Borghesani 2015년 5월 15일
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
Jed
Jed 2015년 5월 13일
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 2015년 5월 14일
편집: Jed 2015년 5월 14일
@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"

댓글을 달려면 로그인하십시오.

채택된 답변

Philip Borghesani
Philip Borghesani 2015년 5월 14일
편집: Philip Borghesani 2015년 5월 14일
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
Jed
Jed 2015년 5월 15일
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 2015년 5월 15일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by