Go to Post Without programmers there would only be a robotic beauty contest. - mallot1243 [more]
Home
Go Back   Chief Delphi > CD-Media > White Papers
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

photos

papers

everything



Handy script to examine the size of your code

kc8nod

By: kc8nod
New: 14-12-2005 16:13
Updated: 14-12-2005 16:13
Total downloads: 234 times


Hi There!

I've written a little perl script to extract some useful information from the .map file. The script tells you how much space in flash is used by each function in your code. The size is in bytes followed by the percentage of the total 32k available. The list is ordered with the biggest ...

Hi There!

I've written a little perl script to extract some useful information from the .map file. The script tells you how much space in flash is used by each function in your code. The size is in bytes followed by the percentage of the total 32k available. The list is ordered with the biggest functions first.

Instructions:

1. Get perl. If you're using Windows, you can download perl from:
http://www.activestate.com/Products/ActivePerl/

2. Make a .map file. From MPLAB select Project->Build Options->Project.
Under the "MPLINK Linker" tab, check the box labled "Generate map file"
This will create a new .map file every time you compile your code.

3. Compile your code. Sorry the script won't work unless you can compile and link successfully.

4. Copy the script file "codesize.pl" to your FrcCode directory and run it like so:
perl codesize.pl

5. Enjoy!


If you've renamed your project for some reason, the .map file can also be specified as a parameter like so:
perl codesize.pl AwsomeCodeProject.map


BONUS!!!!!!!!

You can also import your results into Microsoft Excel with the bonus -csv switch. Use it like so:

perl codesize.pl -csv > NiftySpreadsheet.csv


Questions, comments or compliments? Let me know:
tedhansen@team1216.com

Attached Files

  • zip Handy script to examine the size of your code

    1134594805codesize.zip

    downloaddownload file

    uploaded: 14-12-2005 16:13
    filetype: zip
    filesize: 1.71kb
    downloads: 232



Recent Downloaders

Discussion

view entire thread

Reply

23-12-2005 00:05

prograid


Unread Re: White Paper Discuss: Handy script to examine the size of your code

Hi, I'm having a few problems with this script.
When I tried using the script the first two lines were as follows.

Code:
Unused Memory             28651 bytes 93.3%
vfprintf()                 3062 bytes 10.0%  vfprintf.c
Is this a bug in the script, or is it something I'm doing?
I have a feeling that my code is actually larger than the maximum possible size and somehow this is affecting the result.

Thanks.



25-12-2005 23:19

kc8nod


Unread Re: White Paper Discuss: Handy script to examine the size of your code

Quote:
Originally Posted by prograid
I have a feeling that my code is actually larger than the maximum possible size and somehow this is affecting the result.
Quite possibly. The size of the flash is hard coded in the script as 0x7FFF. If your code exceeds that size bad things might happen. If you could post or email your .map file I could probably figure out what's going on.



27-12-2005 19:52

prograid


Unread Re: White Paper Discuss: Handy script to examine the size of your code

Thanks for replying.
By the way, I don't think this should make a difference but the script is being run as a post-build command from within eclipse.
The mapfile is in the attachment in the FRCMapfile.zip archive because the forum does not allow text file attachments of greater than 100kb.

Thanks.



03-01-2006 11:03

kc8nod


Unread Re: White Paper Discuss: Handy script to examine the size of your code

Quote:
Originally Posted by prograid
...the script is being run as a post-build command from within eclipse.
Sorry for the slow response, I've been offline last week.

I'm guessing that you are doing something clever with your linker script and that is confusing the codsize script. Are you even using the linker script? I can only imagine what hacks you have had to perpetrate to make mcc18 work under Eclipse. Anyway, from your mapfile:
Code:
                              Program Memory Usage 
                               Start         End      
                           ---------   ---------      
                            0x000800    0x000814      
                            0x000818    0x0063a0      
                            0x300000    0x30000d      
            23468 out of 33816 program addresses used, program memory utilization is 69%
My codesize script is improperly concluding that your program ends at address 0x000814 rather than 0x0063a0. My unfounded guess is that you have an extra CODEPAGE entry in your .lkr file.
At any rate, the bug is indeed in my script. I'll think about this a bit more and post a fix in a day or two.



03-01-2006 11:20

kc8nod


Unread Re: White Paper Discuss: Handy script to examine the size of your code

BTW, here's the proper output from the .map file you posted.



06-01-2006 19:50

prograid


Unread Re: White Paper Discuss: Handy script to examine the size of your code

Quote:
Originally Posted by kc8nod
Sorry for the slow response, I've been offline last week.
I'm guessing that you are doing something clever with your linker script and that is confusing the codsize script. Are you even using the linker script? I can only imagine what hacks you have had to perpetrate to make mcc18 work under Eclipse.
Does your script use the linker script (I'm assuming you mean the 18f8520user.lkr file.) in calculating the usage of code? B/c in eclispe the linker script is a directory level up from the mapfile, but in the same level as your perl script.
This is the command I run in order to run your script:
Code:
perl "..codesize.pl" "FRCMapfile.map"
Thanks, for your help.

EDIT:

I tried running your script from within the plain old windows command line after copying the mapfile into the same directory as your script and the .lkr file (and run this command: perl codesize.pl FRCMapfile.map), but still get the same output. I'm using ActivePerl 5.87 Build 815 on Windows XP just for your info.



view entire thread

Reply

Tags

loading ...



All times are GMT -5. The time now is 04:34.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi