1

G'day, I am on look-out for some kind of tool or library I can use with Ada95 for to check or report current runtime memory used/in use.

So far I've not had much luck. I am here because perhaps one of the community has had such a challenge and you could have a good method or approach to isolate growing memory use with Ada. A little background ...

The program is quite stable. As far as I can see, 95% + use fixed arrays and fixed strings, no explicit memory allocation going on so far (searching with grep).

I'm putting log messages in for open/close files. At this point it is unclear what else could be consuming memory. Is there anything or library that can help track this wampus?

Ideally something that can "instrument" Ada would be lovely. You can get these toys for C/C++ -- Anything like-minded for Ada? Many thanks in advance.

will
  • 4,799
  • 8
  • 54
  • 90

2 Answers2

4

I've had success in the past with valgrind. Basically, forget that this is Ada, compile with debug info and profile for memory leaks as usual. There will be a few non-important, non-growing by the Ada runtime, and hopefully yours will become evident.

Also use Gnat's Debug_Pool for your types using dynamic allocation. But not together with valgrind because the memory is not released, it is kept for diagnostics (or it used to be years ago).

Not-so-evident memory leaks you might have: freeing a task type before it is 'Terminated is the only one I can think of right now.

Álex
  • 1,587
  • 11
  • 17
3

Lots of possible answers on this. Tools like gnatmem can give you some information, but only after your program has terminated, I believe. Tools like valgrind (on linux) have similar capabilities.

If you want to monitor memory allocated by Ada code only, one way to do it is by replacing the implementation in System.Memory. The GNATComponents collection (GNATCOLL) has one such package in GNATCOLL.Memory.

We have recently added to the development version of GNATCOLL.Memory some bindings to system calls that allow you to get information on resident memory usage by your application (any language, not just Ada). This is integrated with GNATCOLL.Traces, so that your log file can include such information automatically. The C code on which this is based was from http://NadeauSoftware.com/, to which we added a simple Ada binding with pragma Import.

manuBriot
  • 2,755
  • 13
  • 21
  • By the way, one of the usage of memory that you might be missing are functions returning unconstrained data types (array of class wide objects for instance), for which memory is allocated in what is called the secondary stack. – manuBriot Mar 19 '15 at 13:18