Go Down

Topic: AVR SRAM Usage Script (Windows) (Read 3069 times) previous topic - next topic

mrburnette

Oct 29, 2013, 02:43 pm Last Edit: Oct 29, 2013, 05:47 pm by mrburnette Reason: 1
Updated: Please see my 2nd post where I have a modified script which runs against a non-clean TEMP directory.

Prerequisite:
Navigate to your %TEMP% directory and clean-up before starting any applications, especially Arduino.  I have an automatic script that does this at shutdown/reboot.  Do NOT be afraid if you are told that a file/directory is in-use, simply skip that.  Just ensure that you do not have the Arduino GUI running.

Cleanup by:  (select one of)

  • Opening a Command Prompt
    Typing CD  %temp%
    Typing Start  .   (yes, start + space + period & press Enter)
    Using Explorer to delete all directories beginning with "build" and ending with ".tmp"

  • Type %temp% into any explorer path window
    Hilight all "build<.......>.tmp directories and shift-shift delete


The reason this is necessary is that Windows date-time sort works only withing directories and not across all directories.  Arudino GUI does not generate a temporary hash name that respects any temporal order; that is, the ASCII sort value is inconsistent across a wide date range.  A The solution is a custom Win32 executable to process all .cpp.elf files perform the sort across the universe.  It could (perhaps) be done is a very complex script. <<-- See new script in separate post below.

Reference:
http://ccrma.stanford.edu/planetccrma/man/man1/avr-size.1.html

Quote
The GNU size utility lists the section sizes---and the total size---for
      each of the object or archive files objfile in its argument  list.   By
      default,  one  line of output is generated for each object file or each
      module in an archive.


I have been playing around with the AVR-SIZE utility which is installed during the Arduino installation.  On version 1.0.5 and on my Vista notebook, my installation path is:
Code: [Select]
C:\Program Files\Arduino_105\hardware\tools\avr\bin
Note: Your installation path may be different.

If you have worked with Arduino on Windows for any length of time, you know that the sketch compiles are processed in a user temporary directory.  This directory can look quiet menacing: see the graphic of my %temp% directory.

I wrote a script that I use to ferret through the clutter and process the avr-size utility on the last Arduino compile.  I have tested it and it seems to work over sketches processed over several days, always selecting the most recent sketch on which to execute.  I believe the script will run on WinXP forward, but it is only tested on Windows Vista SP2.  You may need to modify the script for other versions of Windows.
Here is the script:
Code: [Select]

PATH=%path%;C:\Program Files\Arduino_105\hardware\tools\avr\utils\bin;
CD %TEMP%
DIR %temp%\*.cpp.elf /s /b /O:-D /T:W >ElfRhere
SET /P ELF= <ElfRhere
ECHO %ELF% >MemUsage.txt
AVR-SIZE -C %ELF% >>MemUsage.txt
NOTEPAD MemUsage.txt
SET ELF=""


I have this script named "MemoryUsage.cmd" and I stuck in my Arduino home folder:
Code: [Select]
C:\Users\owner\Documents\Arduino\hardware\MemoryUsage.cmd  I created a desktop shortcut called MemUsage to run the script.

Double-clicking to invoke the script will scan through the %temp% directory used by Arduino and sort the most recent .ELF file, passing that as a runline argument to the avr-size utility.  Please adjust your path in the first line of the script to properly identify where your AVR tools are installed.

As mentioned, I have tested this but I'm sure it can be improved upon.  If you find a error or a better approach, please post in this thread to benefit everyone.

USING THE SCRIPT

  • Invoke the script by double-clicking the shortcut or the .cmd script

  • Notepad will open automatically displaying the SRAM and FLASH requirements of your last compile

  • Click "X" on Notepad to close the Notepad and close the CMD prompt



Example listing:
Quote

C:\Users\owner\AppData\Local\Temp\build1837131614995510111.tmp\sketch_oct28a.cpp.elf
AVR Memory Usage
----------------
Device: Unknown

Program:     444 bytes
(.text + .data + .bootloader)

Data:          9 bytes
(.data + .bss + .noinit)


Enjoy,

Ray

JChristensen


mrburnette

The following script should  allow you to run against a temp directory that is NOT clean.  The downside is that I have to recursively go through the %temp% directory looking for all .elf files and copy these into a single holding directory ONLY if they are newer than the previous collection.  Therefore, it takes a weebit longer to run and there is the duplication of the .elf files; although the storage requirements should be minimum.

Code: [Select]

PATH=%path%;C:\Program Files\Arduino_105\hardware\tools\avr\utils\bin;
CD %TEMP%
MD %PUBLIC%\ELFtemp
for /R %TEMP% %%f in (*.elf) do XCOPY /D /Y %%f %PUBLIC%\ELFtemp\
DIR %PUBLIC%\ELFtemp\*.elf /s /b /O:-D /T:W >ElfRhere
SET /P ELF= <ElfRhere
ECHO %ELF% >MemUsage.txt
AVR-SIZE -C %ELF% >>MemUsage.txt
NOTEPAD MemUsage.txt
SET ELF=""


Things you need to think about and adjust!
- Where to build the holding directory for collection of ELF files?
I built mine in the %PUBLIC% section, but you may wish to change this to somewhere in your home folder, generally %USERPROFILE% is the variable for the logged in user on Vista.

- Housecleaning!  Sooner or later, you may want to prune the collection folder.  In theory, you could do this EVERY time you run the script, then the folder would match your %TEMP% Arduino folder one-for-one.

Explanation of some of the commands in the script:
Code: [Select]
PATH=%path%;C:\Program Files\Arduino_105\hardware\tools\avr\utils\bin;
Prep the environment PATH variable so that the script will resolve any utility referenced by short-name.

Code: [Select]
MD %PUBLIC%\ELFtemp
In the Windows Vista installation, %PUBLIC% resolves to:  C:\Users\Public therefore the script will always ensure that the path C:\Users\Public\ELFtemp\ is valid.

Code: [Select]
for /R %TEMP% %%f in (*.elf) do XCOPY /D /Y %%f %PUBLIC%\ELFtemp\
Recursively look for all ELF files in the current directory and xcopy them to the path C:\Users\Public\ELFtemp\ using the xcopy switches /D to copy ONLY IF the date-time stamp is more recent and the /Y switch permits OVERWRITES without prompts.

Code: [Select]
DIR %PUBLIC%\ELFtemp\*.elf /s /b /O:-D /T:W >ElfRhere
Directory list all files in the holding directory of type *.ELF and sort the output by most recent first into the output file ElfRhere

Code: [Select]
SET /P ELF= <ElfRhere
Set a memory variable in the running script to represent the fully qualified path of the first line in the file ElfRhere.  All subsequent lines are ignored.

Code: [Select]
ECHO %ELF% >MemUsage.txt
Create a file called MemUsage.txt with the first line the fully qualified path and filename of the most recent Arduino compile... this is then the Header for the file when listed.

Code: [Select]
AVR-SIZE -C %ELF% >>MemUsage.txt
Run the utility AVR-SIZE.EXE using the fully-qualified filename contained in the memory variable ELF.  Redirect the utility output as an append to the filename MemUsage.txt

Code: [Select]
NOTEPAD MemUsage.txt
Start-up Notepad and load the MemUsage.txt file to display.


K5CZ

Try to use PowerShell:

File Get_Newest_elf_file.PS1
Code: [Select]

$cesta = [System.Environment]::ExpandEnvironmentVariables("%TEMP%")
$items = Get-ChildItem -recurse -include "*.cpp.elf" -Path $cesta | Sort-Object -Property CreationTime -Descending
foreach ($item in $items)
{
      if ($item.Attributes -ne "Directory")
      {
            Write-Host $item.Name
            $item.FullName | Out-File -encoding OEM ElfRhere
            Break
      }
}


File DO.BAT
Code: [Select]

PUSHD "%~dp0"
powershell Set-ExecutionPolicy -ExecutionPolicy UnRestricted
powershell ./get_newest_elf_file.ps1>MemUsage.txt
ECHO.>>MemUsage.txt
ECHO.>>MemUsage.txt
powershell Set-ExecutionPolicy -ExecutionPolicy Restricted
SET /P ELF= <ElfRhere
DEL ElfRhere
"%ProgramFiles(x86)%\Arduino-1.5.4 nightly\hardware\tools\avr\bin\avr-size.exe" -C "%ELF%" >>MemUsage.txt
SET "ELF="
NOTEPAD.EXE MemUsage.txt
POPD


Simply place both files to same directory. Correct this line:
"%ProgramFiles(x86)%\Arduino-1.5.4 nightly\hardware\tools\avr\bin\avr-size.exe"
and run DO.BAT

mrburnette

@K5CZ:
Cool.  It has been years since I played with PowerShell on Windows.  Thanks for the snipplet... I forget about that utility! 

Ray

polypagan

Here's my Linux (tested on openSUSE 12.3) version:

Code: [Select]

#!/bin/bash
# avr-size.sh
# DdelV 10131031
#
# show size of all builds in tmp
#
EXEDIR=/usr/share/arduino-1.0.5/hardware/tools/avr/bin
DATDIR=/tmp
for h in ${DATDIR}/build*/*.hex
do
  ${EXEDIR}/avr-size ${h}
done


have lots of fun!
There are 10 kinds of people in the world, those who understand binary, and those who don't.

mrburnette

@polypagan,
Thanks!  Looks like Linux and Windows are now covered.

Ray

polypagan

Not tested, but my bash script should also work just fine on MacOS (in terminal, of course).
There are 10 kinds of people in the world, those who understand binary, and those who don't.

Go Up