6

I have been looking for a way to monitor the memory consumption for matlab, but have been unable to do so. What I am interested in is the peak memory for built in functions and that cannot be measured with the matlab profiler, since these functions are already compiled.

Peak memory issues is seldom documented in matlab, which means that to find out what the problem is I will need to monitor the memory usage myself. I have already tried to use the resource manager in windows, but I had problems finding anything. I could be that there is no problem but, it can also mean that the sampling rate is to low. I use windows 7.

This question may not be related only to matlab, but since I have problems in matlab I will tag it so.

patrik
  • 4,506
  • 6
  • 24
  • 48
  • What about Matlab's [`memory`](http://es.mathworks.com/help/matlab/ref/memory.html) function? – Luis Mendo Oct 22 '14 at 11:34
  • 1
    @LuisMendo I have not tried it yet, but somehow I doubt it will work. The thing is that I want to be able to measure (and if possible log) memory dynamically to, for example to find out peak memory inside the compiled built in functions in matlab. Assume that you for some reason wanted to find minimum product of any two elements of a vector. This can for example be solved with help of matrix multiplication (v*v.') where v is [Nx1]. This would for however generate potentially huge peak memory, even if input and output is moderate. If the function is built in I cannot see this with the profiler – patrik Oct 22 '14 at 13:14
  • You are right. You would have to issue `memory` while the operaton (matrix multiplication) is running. Perhaps a `timer` could be used to periodically call`memory`? If the period is small enough, one such call could interrupt your operation in the middle – Luis Mendo Oct 22 '14 at 13:45

1 Answers1

4

There is a nice script on the Matlab File Exchange that monitors Matlab's memory usage over time. It basically updates a figure at a specified time interval in background. (Since it relies on Matlab's memory function, it is unfortunately only working on Windows systems.)

I don't know if this suits your needs, but since memory measures the total memory used by the Matlab process, this should also include that of the built-in functions.

However, when Matlab is under heavy load, other functions might take execution preference and the figure might not get updated as desired. In this case, one should consider monitoring the memory outside of Matlab, using tools like e.g. perfmon or Process Explorer, see this question for a more detailed treatise.

Community
  • 1
  • 1
jurgispods
  • 745
  • 8
  • 19
  • Perfmon does only seem to update every second. Can that be fixed? Also, can process explorer update faster? – patrik Oct 23 '14 at 07:37
  • I haven't used any of those tools lately - I'm working on Linux and OS X most of the time - so I don't know. But if your peak memory allocation happens on such a short time scale, you might not even be able to see it in the monitor program, if it is running on the same core, even using a very small refresh interval... you would have to make sure it is running on a different core. – jurgispods Oct 23 '14 at 08:04