Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory profiling of MATLAB columns meaning

Tags:

memory

matlab

I'm using MATLAB profile to observe memory using the command

profile -memory on
profile clear
% my code
profile report

and i got this table enter image description here

1- i want to ask about the meaning of Allocated Memory,Freed Memory, SelfMemory, and Peak Memory

2- what is the meaning of negative self memory?

like image 380
Sara S. Avatar asked Feb 24 '14 19:02

Sara S.


People also ask

What is profiling in MATLAB?

What Is Profiling? Profiling is a way to measure the time it takes to run your code and identify where MATLAB® spends the most time. After you identify which functions are consuming the most time, you can evaluate them for possible performance improvements.

What is a memory Profiler?

The Memory Profiler is a component in the Android Profiler that helps you identify memory leaks and memory churn that can lead to stutter, freezes, and even app crashes. It shows a realtime graph of your app's memory use and lets you capture a heap dump, force garbage collections, and track memory allocations.

What is memory management in MATLAB?

When a MEX function returns control to MATLAB®, it returns the results of its computations in the output arguments—the mxArray s contained in the left-side arguments plhs[] . These arrays must have a temporary scope, so do not pass arrays created with the mexMakeArrayPersistent function in plhs .

What does the Profiler track in MATLAB?

Description. Use the Profiler to track execution time. Knowing the execution time of your MATLAB® code helps you to debug and optimize it. For information on the user interface to the Profiler, see Profile Your Code to Improve Performance.


1 Answers

After a quick google, it would seem that no-one knows, except perhaps MathWorks and they aren't telling. (I jest, but in truth I found very little information on the subject).

Logically however I would interpret the column names as follows:

Allocated memory = the total amount of memory allocated within the function and any it calls.

Freed memory = the total amount of memory released within the function and any it calls.

Peak Memory = the maximum amount of memory in use at any one time during the execution of the function.

Self Memory = the amount of memory used by the function, but not including any functions it calls.

I would hypothesize that a negative 'Self Memory' would indicate that the function frees more memory than it allocates. This could be that it has ownership of a piece of data passed to it, which it then clears. E.g.:

function A()
  foo = B();
  clear foo
end

function foo = B()
  foo = rand(10000,10000);
end

In the example above, the data is created in the call to B and since Matlab employs a lazy copy memory management, this case works pretty much as pass-by-reference for the return value. So, B allocates the memory, and A frees it.

Indeed, running that code with the profiling method in the question produces the following output, which supports my hypothesis.

profile report

like image 111
Alan Avatar answered Nov 10 '22 20:11

Alan