Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » SDCC
  • » [Sdcc-user] individual object file stats [RSS Feed]

#1 Dec. 7, 2010 16:31:42

Paul F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] individual object file stats


perhaps i'm missing the obvious, but:

is there a way in sdcc to see the memory requirements of individual
object files? i'm thinking of the moral equivalent of "size *.o",
something i often use to get a sense of who's using what. i can't
seem to find that kind of summary information anywhere.

(the target is the 8051.)

paul
=---------------------
paul fox, p***@*aptop.org


Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

#2 Dec. 10, 2010 16:04:19

Paul F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] individual object file stats


i wrote:
> is there a way in sdcc to see the memory requirements of individual
> object files? i'm thinking of the moral equivalent of "size *.o",


there was no response to the above, so i've put together a script that
attempts to extract this information from the .rel files for our 8051
project.

the output of my script looks like this:
$ tools/sdcc_sizes
/home/pgf/work/ec-1.75
Fri Dec 10 10:55:57 EST 2010
code const xdata data bit
obj/ac.rel: 240 25 4 0 5
obj/adc.rel: 172 0 1 0 0
obj/battery.rel: 1048 75 16 0 0
obj/build.rel: 206 46 5 0 0
obj/event.rel: 20 0 1 0 0
obj/io.rel: 2289 69 14 0 0
obj/keyboard.rel: 532 162 34 0 0
obj/lifebatt.rel: 3862 547 46 14 0
obj/main.rel: 321 32 0 0 1
obj/monitor.rel: 1165 54 24 4 1
obj/mppt.rel: 3925 235 70 8 0
obj/onewirebatt.rel: 6460 876 300 6 0
obj/power.rel: 4102 818 22 0 0
obj/ps2.rel: 764 9 75 1 0
obj/ps2_private.rel: 493 0 1 1 0
obj/sdi.rel: 1959 291 77 6 0
obj/sdicmd.rel: 588 30 2 1 0
obj/timer.rel: 564 5 22 6 0
obj/touchpad.rel: 118 9 1 0 0
obj/uart.rel: 503 17 80 5 1
obj/updater.rel: 191 1379 3 0 1

-- totals (no libraries) --------
code: 29522
const: 4679
xdata: 798
data: 52
bits: 9


the .mem file for this build says:
Other memory:
Name Start End Size Max
---------------- -------- -------- -------- --------
PAGED EXT. RAM 0 256
EXTERNAL RAM 0xf400 0xf773 884 2048
ROM/EPROM/FLASH 0x0000 0x9454 37973 62464

the difference between the ROM/EPROM/FLASH value of 37973 and
my code+const value of 29522+4679 ( == 34201) is 3772. does
that seem like a reasonable size for the library code? i think
printf_large is roughly 1K, so maybe it's about right.

the script i'm using is attached. comments/corrections welcome, of course.

paul
=---------------------
paul fox, p***@*aptop.orgsdcc_sizesDescription:
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Attachments:
attachment sdcc_sizes (2.7 KB)

Offline

#3 Dec. 10, 2010 16:23:41

Paul F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] individual object file stats


i wrote:
> the script i'm using is attached. comments/corrections welcome, of course.

the list apparently didn't like the script as an attachment. here:

#!/bin/sh

# Copyright 2010 One Laptop per Child
# License information below.

# produce a listing of the code and initialized constant sizes
# for the all the obj/*.rel files produced by sdcc.
# requires dc, xargs, cut, sed.

me=${0##*/}

tmpfile="/tmp/$me.$$"
trap "rm -f $tmpfile" 0

main()
{
pwd
date

printf " %27s %7s %7s %7s %7s\n" code const xdata data bit
listsizes | tee $tmpfile

echo
echo "-- totals (no libraries) --------"

echo -n "code:\t"
sumcol 2 < $tmpfile

echo -n "const:\t"
sumcol 3 < $tmpfile

echo -n "xdata:\t"
sumcol 4 < $tmpfile

echo -n "data:\t"
sumcol 5 < $tmpfile

echo -n "bits:\t"
sumcol 6 < $tmpfile

}


listsizes()
{
for x in obj/*.rel
do
(
echo $x:
(
egrep 'CSEG' $x;
egrep 'CONST' $x;
egrep 'XSEG' $x;
egrep 'DSEG' $x;
egrep 'BSEG' $x;
)|
sed -e 's/A //' \
-e 's/size //' \
-e 's/ flags.*//' \
-e 's/SEG\|CONST//' \
-e 's/\+/0x&/g'
) |
xargs -n 6 printf "%-20s %7d %7d %7d %7d %7d\n"
done
}

# tally the Nth field of the input
sumcol()
{
awk '
BEGIN { total = 0; }
{ total += $'$1'}
END { print total; }
'
}

main

exit

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding!

As a special exception, you may use this file as part of a free software
library for the XO of the One Laptop per Child project without restriction.
Specifically, if other files instantiate
templates or use macros or inline functions from this file, or you compile
this file and link it with other files to produce an executable, this
file does not by itself cause the resulting executable to be covered by
the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.


=---------------------
paul fox, p***@*aptop.org


Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

#4 Jan. 23, 2011 20:12:27

George O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] individual object file stats


Hello all,

Paul Fox wrote:
> > is there a way in sdcc to see the memory requirements of individual
> > object files? i'm thinking of the moral equivalent of "size *.o",
>
> there was no response to the above, so i've put together a script that
> attempts to extract this information from the .rel files for our 8051
> project.

Slightly old thread now but I found it useful (many thanks again, Paul) and
I've made some modifications. The modified script, tested on unbuntu 10.10 and
MAC OS X 10.6.6, is inline after the change list:

- The script now takes the project's map file as the 1st argument in the
command line. It parses it and extracts the paths/names of modules which are
being linked in (instead of brute force parsing obj/*.rel). This is important
in cases when we have files which are being compiled but not linked.

- It now supports named code segments when building with banking support. The
total code size reported is the sum of code found in any of the segments listed
in the code_segs variable, rather than only in CSEG. To add/rename code
segments, just change the values inside $code_segs

- Similar for XRAM segments, it sums up variables assigned to XISEG in addition
to XSEG (listed in $mem_segs)

- If we have built sdcc from sources, we have standard library rel files in the
build dir (one directory with rel files for each memory model / stack-auto /
xstack combo). The script will optionally parse those and include them in the
calculation. In order to turn this on, simply set $sdcc_src to the location of
your SDCC sources. Then change $libdir to correspond to the memory model used
for your builds

- Slightly better portability (mainly related to different versions of sed and
awk - see inline)

========
#!/bin/bash

# Copyright 2010 One Laptop per Child
# License information below.

# produce a listing of the code and initialized constant sizes
# for the all the obj/*.rel files produced by sdcc.
# requires xargs, cut, sed, awk

me=${0##*/}

tmpfile="/tmp/$me.$$"
code_segs=( CSEG HOME BANK1 BANK2 BANK3 XINIT )
mem_segs=( XSEG XISEG )

# gawk refuses to sum up hex values unless we pass --posix
# Try 'awk' first. If that doesn't work, experiment.
AWK=awk
#AWK="gawk --posix"
#AWK=mawk

# If we want to parse SDCC's library rel files, make sure to set SDCC_SRC below
# correctly. Also, we need to change huge-stack-auto to correspond to the memory
# model used for our particular build.
# If we don't care about libraries, just ignore both steps above
sdcc_src=$HOME/svn-working-copies/sdcc
libdir=${sdcc_src}/device/lib/huge-stack-auto

trap "rm -f $tmpfile" 0

main()
{
# make sure sort puts files starting with _ at the start
export LC_COLLATE=C
pwd
date
echo $tmpfile

build_dir=$(dirname $1)
files=( $( grep .rel $1 | $AWK '{print $(NF-1)}' | sort ) )

printf " %50s %7s %7s %7s %7s\n" CODE XRAM CONST DATA BITS
listsizes | tee $tmpfile

echo
echo "-- Totals (see .mem for more accurate info) --"

echo -en " CODE:\t"
sumcol 2 < $tmpfile

echo -en " XRAM:\t"
sumcol 3 < $tmpfile

echo -en "CONST:\t"
sumcol 4 < $tmpfile

echo -en " DATA:\t"
sumcol 5 < $tmpfile

echo -en " BITS:\t"
sumcol 6 < $tmpfile
echo " (Each file with an ISR increments the reported BITS value by 1)"
}

listsizes()
{
for rel_file in ${files}
do
x="$build_dir/$rel_file"
if ; then x="$libdir/$rel_file"; fi
if
then
(
# Output our filename
echo ${x##*/}:

# Sum up all the CODE segments
reg=""
for seg in ${code_segs}
do reg="$reg|$seg"
done
egrep -w ${reg:1} $x |
sed -E -e 's/A //' \
-e 's/size //' \
-e 's/ flags.*//' \
-e "s/${reg:1}//" \
-e 's/+/0x&/' |
$AWK '{ SUM += $1 } END { print SUM }'

# Do the same for mem segments
reg=""
for seg in ${mem_segs}
do reg="$reg|$seg"
done
egrep -w ${reg:1} $x |
sed -E -e 's/A //' \
-e 's/size //' \
-e 's/ flags.*//' \
-e "s/${reg:1}//" \
-e 's/+/0x&/' |
$AWK '{ SUM += $1 } END { print SUM }'

# CONST, DATA, BITS
(
egrep -w 'CONST' $x
egrep -w 'DSEG' $x
egrep -w 'BIT_BANK' $x
) |
sed -E -e 's/A //' \
-e 's/size //' \
-e 's/ flags.*//' \
-e "s/CONST|DSEG|BIT_BANK//" \
-e 's/+/0x&/'
) |
xargs -n 6 printf "%-43s %7d %7d %7d %7d %7d\n"
fi
done
}

# tally the Nth field of the input
sumcol()
{
$AWK '
BEGIN { total = 0; }
{ total += $'$1'}
END { print total; }
'
}

if ; then echo "Please supply a .map filename as argument."; exit ;
fi

main $1

exit

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding!

As a special exception, you may use this file as part of a free software
library for the XO of the One Laptop per Child project without restriction.
Specifically, if other files instantiate
templates or use macros or inline functions from this file, or you compile
this file and link it with other files to produce an executable, this
file does not by itself cause the resulting executable to be covered by
the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.




Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

  • Root
  • » SDCC
  • » [Sdcc-user] individual object file stats [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support