1

I am trying to learn to use profvis. Here is a link with a reproducible example:

profvis example

I am not able to see why there are TWO numbers for Memory ie. -3.5 and 9.5 (where Time = 1290) in the first example in this page.

Can someone explain how to interpret the 2 numbers for Memory?

user2338823
  • 501
  • 1
  • 3
  • 16

1 Answers1

0

The positive numbers are allocated memory and the negative numbers are deallocated memory (between the previous and current sample).

From the docs:

Memory: Memory allocated or deallocated (for negative numbers) for a given call stack. This is represented in megabytes and aggregated over all the call stacks over the code in the given row

Also note that

Interpreting this information can be a little tricky, because it does not necessarily reflect memory allocated and deallcated at that line of code. The sampling profiler records information about memory allocations that happen between the previous sample and the current one. This means that the allocation/deallocation values on that line may have actually occurred in a previous line of code.

  • So a number to the left of the line in memory will always be negative (corresponding to deallocation) and a number on the right of the line will always be positive (corresponding to allocation)? Suppose I need to compute the maximum possible memory used by a program at any point in time to determine hardware(RAM) requirements for the program. An upper bound on the memory used by the code will be = max ( positive - negative numbers ) in each line because we may have allocation BEFORE deallocation. Is that correct? Can I not compute the precise maximum amount of RAM used by a program? – user2338823 May 15 '18 at 06:44
  • I now think the maximum amount of RAM used at any point in the code will = max(a_i + b_i + a_j, here b_i is negative since it is a deallocation) where a_i's are the allocations and b_i's are deallocations, where i and j are successive (not necessarily in consecutive lines) allocations / deallocations. – user2338823 May 15 '18 at 06:59
  • That should be the case, yes. – Mikael Poul Johannesson May 15 '18 at 12:04
  • Is there a software which can do this computation for a big file where manual work is a little tough ? – user2338823 May 16 '18 at 04:23
  • Please see the [profmem](https://cran.r-project.org/web/packages/profmem/index.html) package. – Mikael Poul Johannesson May 16 '18 at 17:10
  • profmem does NOT log memory deallocations. All it does is log EACH memory allocation and report each allocation + the total memory allocated. This will not report the max memory used at any point in time by the code which is what I am looking for. – user2338823 May 17 '18 at 05:13
  • The community would gladly help you with this follow-up question if you ask it as a new question ([please see here](https://meta.stackoverflow.com/questions/266767/what-is-the-the-best-way-to-ask-follow-up-questions)). In addition, if you do not think the above answer adequately addresses your original question, please consider clarifying why. – Mikael Poul Johannesson May 17 '18 at 13:51