Analysis of per-library memory usage

For more traditional unix based C compilation there are ways to determine where statically allocated memory is being used, is there some way to determine this for Arduino code?

I have a project that has become fairly complicated code wise due to using a number of libraries, both ones I've written and some 3rd party ones (such as RS485 communication, the Adafruit LED pixel library, MPR121 cap sensor library, and some others) and I've run up against an issue I suspect to be due to hitting memory limits. The compiled code leaves only 495B free and I know at least another 3-400B are allocated by the pixel and RS485 libraries at run time.

Are there any tools (other than manual code inspection) to determine how much statically allocated memory is being used by the various modules or cpp files being used here?

(I'm currently using Arduino 2 if that makes any difference to the available tools)

pen and paper - just scan through the lib id the data structures (of what ever kind) and total them up if you find that more than 60/70% of ram is in use then your in trouble.

Mark

I'm currently using Arduino 2

There is no Arduino 2. There is an Arduino Uno and an Arduino Due.

What do you really have?

I think the new beta compiler estimates the ram.

But 495 bytes is very little for a stack. If you have Arduino Uno, you should upgrade to Arduino Mega.
I don't know any Arduino 2.

Sorry, by "Arduino 2" I mean the Arduino beta IDE.

The actual hardware I'm using is an Arduino Nano, so ATMega328P. This is for a project where I'll be producing my own PCBs with ATMega328's on them, so the final thing won't be on a standard Arduino.

I'd rather avoid changing chips at this point. While I could move up to ATmega1284P's for the much larger RAM, I'd rather optimize things within the 2K limit as the bigger chips are also much more expensive and the final project will involve at least a dozen of the modules I'm working on.

Sorry, by "Arduino 2" I mean the Arduino beta IDE.

How do you get 2 out of

Arduino 1.5.6-r2 BETA (with support for Arduino Yún and Arduino Due boards)

PaulS:

Sorry, by "Arduino 2" I mean the Arduino beta IDE.

How do you get 2 out of

Arduino 1.5.6-r2 BETA (with support for Arduino Yún and Arduino Due boards)

Apparently through the magic of MacOS automatic naming. I left Arduino 1.X installed, when I installed Arduino 1.5.6-r2 BETA the app was installed as "Arduino 2".

If you don't need the Serial library in the final product, you can omit that.
I use a "DEBUG" define that uses the Serial library only during debugging.
You could also use a common buffer, and use it temporary for many things.

Carefully read your code again, and move as much strings and data to flash memory as possible.
For example this: const char text[] = "Hello";
That uses ram, since it is copied from flash memory to ram during startup.
Also this: Serial.println("Hello");
That uses also the string "Hello" in ram.

For the libraries, you have to read the source code.

My code is (I believe) pretty thoroughly optimized. All strings are within F() statements, all print statements are #def'd out (see ArduinoLibs/Debug.h at master · aphelps/ArduinoLibs · GitHub), etc. If needed I can go through all the included libraries and inspect the code, but I'm hoping that someone can point me to a method of determining library memory usage via tools.

At this point I'm sort of suspecting that these don't currently exist, at least within the generic Arduino IDE ecosystem.

They don't exist as far as I know.

You can generate a listing, but that doesn't show per library the ram usage.
And the Arduino compiler/linker is able to remove unused parts, so it can be hard to tell what the resulting usage will be.

I read once that it would be possible in the future to add custom compiler flags. I don't know if that is implemented yet. The avr-gcc compiler can do a lot of optimizing tricks that are not yet used by the Arduino. Long time ago I tried a few optimizing flags and the result are astonishing.
As far as I know, the Arduino uses an older version of the avr-gcc, since the newer version was changed too much and no longer compatible with the Arduino IDE.

Perhaps you could replace a library with a smaller version. If you can determine the most memory-hungry library.