go_away

Author Topic: memory usage statistics?  (Read 6021 times)

0 Members and 1 Guest are viewing this topic.

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
memory usage statistics?
« on: May 12, 2008, 01:17:53 PM »
After compiling my program with AVR Studio, how do I figure out what my flash memory usage is?

Looking at the .lss file, the .hex, and the .hex in a disassembler, I'm still confused on how to determine memory usage . . .

Offline benji

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: memory usage statistics?
« Reply #1 on: May 12, 2008, 02:09:58 PM »
open the hex file as text,
these are the bytes thats going to be in your mcu's flash,,count em, ;D

im not sure checking the file size on the hard disk would be the same,,
good ol' BeNNy

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #2 on: May 12, 2008, 02:12:28 PM »
In your makefile then the 'sizebefore' and 'sizeafter' dependencies should surround the HEX file rather than the ELF file.

Then:-
Code: [Select]
# Display size of file.
HEXSIZE = $(SIZE) -A $(PRG).hex
ELFSIZE = $(SIZE) -A $(PRG).elf
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
sizebefore:
# @if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
@if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi

sizeafter:
# @if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
@if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi


« Last Edit: May 12, 2008, 02:19:43 PM by Webbot »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #3 on: May 12, 2008, 02:18:08 PM »
This does make assumptions about your makefile based on the $50 Robot. So (Admin) post your makefile if what I've said is garbage.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
Re: memory usage statistics?
« Reply #4 on: May 12, 2008, 03:31:09 PM »
Hmmmm webbot, I am getting this error when using your code:

make: [AVR_Fish.eep] Error 1 (ignored)


but if I do this:
Code: [Select]
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
sizebefore:
# @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
@if [ -f $(TARGET).hex ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi

sizeafter:
# @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
@if [ -f $(TARGET).hex ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi

Then I get this:
Quote
Size before:
   text       data        bss        dec        hex    filename
      0      17826          0      17826       45a2    AVR_Fish.hex


Creating load file for EEPROM: AVR_Fish.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex AVR_Fish.elf AVR_Fish.eep
c:\Program Files\WinAVR\bin\avr-objcopy.exe: there are no sections to be copied!
c:\Program Files\WinAVR\bin\avr-objcopy.exe: --change-section-lma .eeprom=0x00000000 never used
make: [AVR_Fish.eep] Error 1 (ignored)

Size after:
   text       data        bss        dec        hex    filename
      0      17826          0      17826       45a2    AVR_Fish.hex

That still has an error in it (why?), but at least it gives me size info. Sooooo . . . this means it uses 17.8kb? Why is size before and after the same?

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: memory usage statistics?
« Reply #5 on: May 12, 2008, 03:52:18 PM »
Just for the info:

Anybody using PIC mcu's can load their project in mplab then goto view->memory usage gauge and this will tell you how much flash memory is being used as well as any data or ram memory.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #6 on: May 12, 2008, 04:46:42 PM »
Quote
Hmmmm webbot, I am getting this error when using your code:

As with all things software - I get a completely different output in my make cycle!!

Can you attach your makefile?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline benji

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: memory usage statistics?
« Reply #7 on: May 13, 2008, 02:35:44 AM »
Admin,
-right click on the hex file chooose properties

-there is somthing called SIZE ,, this is how much flash its gonna consume.
watch out its NOT the SIZE ON DISK

this is according to windown vista ,, i think its the same on other ones.


good ol' BeNNy

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: memory usage statistics?
« Reply #8 on: May 13, 2008, 04:24:27 AM »
dude, are you talking about program memory? cause I have a hunch you're onto RAM usage here.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
Re: memory usage statistics?
« Reply #9 on: May 13, 2008, 07:11:42 AM »
makefile is attached

benji, according to XP, its 49kb which I highly doubt is the actual amount of memory space it takes up on my micro . . . its just too large . . .

Quote
cause I have a hunch you're onto RAM usage here.
I wouldn't mind an automated way to determine RAM usage too . . .

Offline benji

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: memory usage statistics?
« Reply #10 on: May 13, 2008, 09:01:22 AM »
Quote
benji, according to XP, its 49kb which I highly doubt is the actual amount of memory space it takes up on my micro . . . its just too large . . .
weird, are you sure its not the size on disk?

anyways another way to know it is to open the hex file in notepad
,it would looklike this

:A7SF9C0F8DS0F9DS9G8VBD09D8DFG989
:S8F0G0D78F7F0HGDG0F098DFF09DF8093
:H9D0F9S7DF0G8DFG0DFG7DF9GD7GD0FG
:DFGDFGDFGDVS9F8VSDVDS68F7S9SS8D9

so you simply put the cursor after the last byte of the program which is 9 in the above program
then look at the status bar it shows you line number and column number.
so just do (line num * column number)=number of bytes is what you get

maybe the status bar in the notepad wont be available by default so just go to view / states bar
good ol' BeNNy

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #11 on: May 13, 2008, 11:13:56 AM »
Hey admin try this:

Code: [Select]
# Display size of file.
HEXSIZE = $(SIZE) -C --mcu=$(MCU) $(PRG).hex
ELFSIZE = $(SIZE) -C --mcu=$(MCU) $(PRG).elf

MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
sizebefore:
@if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
# @if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi

sizeafter:
@if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
# @if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi


I get an output like this:-

Size before:
AVR Memory Usage
----------------
Device: atmega8

Program:    3748 bytes (45.8% Full)
(.text + .data + .bootloader)

Data:        190 bytes (18.6% Full)
(.data + .bss + .noinit)



avr-g++  -g -Wall -Os -mmcu=atmega8 -D F_CPU=8000000   -c -o main.o main.cpp
avr-g++ -g -Wall -Os -mmcu=atmega8 -D F_CPU=8000000  -Wl -o SonarSRF05.elf main.
o ..\..\bin\cpplib.a

Creating load file for Flash: SonarSRF05.hex
avr-objcopy -O ihex -R .eeprom -g --strip-debug SonarSRF05.elf SonarSRF05.hex
avr-objdump -h -S SonarSRF05.elf > SonarSRF05.lst

Size after:
AVR Memory Usage
----------------
Device: atmega8

Program:    3748 bytes (45.8% Full)
(.text + .data + .bootloader)

Data:        190 bytes (18.6% Full)
(.data + .bss + .noinit)
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #12 on: May 13, 2008, 11:25:26 AM »
Admin - you may also have noticed that in your makefile:
Code: [Select]
# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the
#     processor frequency. You can then use this symbol in your source code to
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
#     Typical values are:
#         F_CPU =  1000000
#         F_CPU =  1843200
#         F_CPU =  2000000
#         F_CPU =  3686400
#         F_CPU =  4000000
#         F_CPU =  7372800
#         F_CPU =  8000000
#         F_CPU = 11059200
#         F_CPU = 14745600
         F_CPU = 16000000
#         F_CPU = 18432000
#         F_CPU = 20000000
#         F_CPU = 3686400

Doesn't actually do anything! Which is why you have to redefine it in a header file in your project.
If you change your makefile:-
From:
Code: [Select]
# Place -D or -U options here
CDEFS =

To:
Code: [Select]
# Place -D or -U options here
CDEFS =-D F_CPU=$(F_CPU)

Then you can get rid of its redefinition in your headerfile and just control it from your makefile.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
Re: memory usage statistics?
« Reply #13 on: May 13, 2008, 01:07:42 PM »
Webbot, it appears you are using the auto-generated makefile and not the external one?

I tried your code but still no luck . . . this time it didn't print anything but this:
Quote
Creating load file for Flash: AVR_Fish.hex
avr-objcopy -O ihex -R .eeprom AVR_Fish.elf AVR_Fish.hex
avr-objcopy: AVR_Fish.elf: File format not recognized
make: *** [AVR_Fish.hex] Error 1
Build succeeded with 0 Warnings...


Im trying to interpret this:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=62498&start=all&postdays=0&postorder=asc
It basically says a .hex file size has little to do with memory usage, because .hex is in ascii and has additional info (address, checksum, etc) that the uploaded binary wouldn't have.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #14 on: May 13, 2008, 01:33:44 PM »
Have you made the change from my post that starts: 'Hey admin try this:' ?

The changes there work with the .elf file not the .hex file.

Quote
using the auto-generated makefile and not the external one?
I'm just using Notepad to write my code and then using 'make' at the command line prompt.

Looks like your error is in turning the elf file to a hex file. Have you tried doing a 'clean' and then a fresh 'make' ?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
Re: memory usage statistics?
« Reply #15 on: May 13, 2008, 01:37:02 PM »
I tried hex2bin.exe and got this:

Quote
Z:\>HEX2BIN AVR_Fish.hex binary.bin [/Z:]


 HEX2BIN.EXE v3.1 - Converts Intel,Motorola and Tektronixs HEX files to BINARY
                       Supports 16,24 and 32 bit addressing formats
                                   Copyright (c) 1994,1996

 Read 1117 lines.  Wrote 17840 bytes

and since that is the same byte count as when I modded the makefile:
Quote
Size after:
   text       data        bss        dec        hex    filename
      0      17840          0      17840       45b0    AVR_Fish.hex

I am assuming my memory usage is 17840 bytes, right?


I don't have time to fully investigate why your suggestions aren't working . . . I tried rebuilding everything but still no luck . . . on with the next problem! :P

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #16 on: May 13, 2008, 01:46:53 PM »
Quote
I am assuming my memory usage is 17840 bytes, right?
It'll probably be just under that as the hex file also contains any initialised data
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline benji

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: memory usage statistics?
« Reply #17 on: May 13, 2008, 03:16:20 PM »
yea true , experimenting with that the hex file has nothing to do with the flash size
i have my compiler telling me how much flash does the program consumes,
i guess the only way is to use such a software,,
good ol' BeNNy

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: memory usage statistics?
« Reply #18 on: May 13, 2008, 04:46:44 PM »
Didn't any one check the wiki;)
Basically you can add up the first two digit hex value of each line and that is how many bytes will be written to flash when you program. Normally the first tow digit hex value is 10 (or 16 in decimal) so it's just as easy to count rows and multiply for a rough guess. If you are getting close enough to really really care, it's probably time to buy a bigger micro anyways.

As far as RAM usage... I don't know yet...
« Last Edit: May 13, 2008, 04:49:40 PM by JesseWelling »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: memory usage statistics?
« Reply #19 on: May 13, 2008, 07:46:58 PM »
Quote
Didn't any one check the wiki.

Well no - coz hex files are a mix of data and code etc. I'm kinda happy with my makefile change above that shows code and data sizes as well % used for the controller.

Admin seemed a bit busy to pursue it, which is fine, but  - has anyone else except me got this to work?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here