Skip to content

Commit

Permalink
Collapsed vector regions and sections in the output.
Browse files Browse the repository at this point in the history
  • Loading branch information
chintal committed Mar 21, 2018
1 parent af9da02 commit 077b0c2
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 15 deletions.
33 changes: 21 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,27 @@ assembly listings.
dynamic memory allocation is anyway avoided when possible.


.. note::
This script was first written based on the format of mapfiles
generated by ``msp430-elf-gcc, v4.9.1``. Over time, it was modifed to
accept elements found in mapfiles generated by later versions and gcc-based
toolchains for other platforms.

Still, remember that the file parsing was implemented by observing the
content of real mapfiles, and not based on a file format specification.
Even with toolchains it was written to support, there are large sections
of the file that are not actually used. Due to this, the outputs generated
are not always accurate. Various boundary conditions result in minor errors
in size reporting.
Known Issues
------------

This script was first written based on the format of mapfiles
generated by ``msp430-elf-gcc, v4.9.1``. Over time, it was modifed to
accept elements found in mapfiles generated by later versions and gcc-based
toolchains for other platforms.

Still, remember that the file parsing was implemented by observing the
content of real mapfiles, and not based on a file format specification.
Even with toolchains it was written to support, there are large sections
of the file that are not actually used. Due to this, the outputs generated
are not always accurate. Various boundary conditions result in minor errors
in size reporting.

The following more serious issues are known. They should be fixed at some
point, but for the moment I've chosen to work around them :

- Having two C filenames with the same name (or generating the same
obj name) in your tree will cause parsing to break on some
platforms / toolchains.


Links
Expand Down
3 changes: 3 additions & 0 deletions fpvgcc/fpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def linkermap_get_newnode(name, sm, allow_disambig=True,
except TypeError:
print("Error getting new node : {0}".format(name))
raise
except RuntimeError:
print("Runtime Error getting new node : {0}".format(name))
exit(0)
newnode = linkermap_get_newnode(
'{0}.{1}'.format(name, objfile.replace('.', '_')), sm,
allow_disambig=False, objfile=objfile, at_fill=True)
Expand Down
74 changes: 73 additions & 1 deletion fpvgcc/gccMemoryMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,33 @@ def __repr__(self):


class GCCMemoryMap(SizeNTree):
# This really needs to be cleaned up. Most of the code here is pretty much an
# example of what NOT to do.
node_t = GCCMemoryMapNode
collapse_vectors = True

def __init__(self):
self.memory_regions = []
self._vector_regions = []
self._vector_sections = []
self.aliases = LinkAliases()
super(GCCMemoryMap, self).__init__()

@property
def used_regions(self):
ur = ['UNDEF']
if self.collapse_vectors:
self._vector_regions = []
ur.append('VEC')
for node in self.root.all_nodes():
if node.region not in ur:
ur.append(node.region)
if self.collapse_vectors:
if 'VEC' not in node.region:
ur.append(node.region)
elif node.region not in self._vector_regions:
self._vector_regions.append(node.region)
else:
ur.append(node.region)
ur.remove('UNDEF')
ur.remove('DISCARDED')
return ur
Expand Down Expand Up @@ -314,6 +328,9 @@ def used_sections(self):
sum([n.children for n in self.top_level_nodes
if n.region == 'UNDEF'], [])
if node.region != 'DISCARDED' and node.size > 0]
if self.collapse_vectors:
self._vector_sections = [x for x in sections if 'vec' in x]
sections = ['.*vec*'] + [x for x in sections if 'vec' not in x]
return sections

@property
Expand All @@ -338,6 +355,8 @@ def get_symbol_fp(self, symbol):
return r

def get_symbol_fp_rgn(self, symbol, region):
if self.collapse_vectors and region == "VEC":
return self.get_symbol_fp_rgnvec(symbol)
rv = 0
for node in self.root.all_nodes():
if node.name == symbol:
Expand All @@ -346,13 +365,24 @@ def get_symbol_fp_rgn(self, symbol, region):
rv += node.leafsize
return rv

def get_symbol_fp_rgnvec(self, symbol):
rv = 0
for node in self.root.all_nodes():
if node.name == symbol:
if 'VEC' in node.region:
if node.leafsize is not None:
rv += node.leafsize
return rv

def get_objfile_fp(self, objfile):
r = []
for rgn in self.used_regions:
r.append(self.get_objfile_fp_rgn(objfile, rgn))
return r

def get_objfile_fp_rgn(self, objfile, region):
if self.collapse_vectors and region == "VEC":
return self.get_objfile_fp_rgnvec(objfile)
rv = 0
for node in self.root.all_nodes():
if node.objfile == objfile:
Expand All @@ -361,6 +391,15 @@ def get_objfile_fp_rgn(self, objfile, region):
rv += node.leafsize
return rv

def get_objfile_fp_rgnvec(self, objfile):
rv = 0
for node in self.root.all_nodes():
if node.objfile == objfile:
if 'VEC' in node.region:
if node.leafsize is not None:
rv += node.leafsize
return rv

def get_objfile_fp_secs(self, objfile):
r = []
for section in self.used_sections:
Expand All @@ -374,28 +413,52 @@ def get_arfile_fp_secs(self, arfile):
return r

def get_objfile_fp_sec(self, objfile, section):
if section == '.*vec*':
return self.get_objfile_fp_secvec(objfile)
rv = 0
for node in self.get_node(section).all_nodes():
if node.objfile == objfile:
if node.leafsize is not None:
rv += node.leafsize
return rv

def get_objfile_fp_secvec(self, objfile):
rv = 0
for section in self._vector_sections:
for node in self.get_node(section).all_nodes():
if node.objfile == objfile:
if node.leafsize is not None:
rv += node.leafsize
return rv

def get_arfile_fp_sec(self, arfile, section):
if section == '.*vec*':
return self.get_objfile_fp_secvec(arfile)
rv = 0
for node in self.get_node(section).all_nodes():
if node.arfile == arfile:
if node.leafsize is not None:
rv += node.leafsize
return rv

def get_arfile_fp_secvec(self, arfile):
rv = 0
for section in self._vector_sections:
for node in self.get_node(section).all_nodes():
if node.arfile == arfile:
if node.leafsize is not None:
rv += node.leafsize
return rv

def get_arfile_fp(self, arfile):
r = []
for rgn in self.used_regions:
r.append(self.get_arfile_fp_rgn(arfile, rgn))
return r

def get_arfile_fp_rgn(self, arfile, region):
if self.collapse_vectors and region == "VEC":
return self.get_arfile_fp_rgnvec(arfile)
rv = 0
for node in self.root.all_nodes():
if node.arfile == arfile:
Expand All @@ -404,6 +467,15 @@ def get_arfile_fp_rgn(self, arfile, region):
rv += node.leafsize
return rv

def get_arfile_fp_rgnvec(self, arfile):
rv = 0
for node in self.root.all_nodes():
if node.arfile == arfile:
if 'VEC' in node.region:
if node.leafsize is not None:
rv += node.leafsize
return rv


class MemoryRegion(object):
def __init__(self, name, origin, size, attribs):
Expand Down
30 changes: 30 additions & 0 deletions fpvgcc/wui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,33 @@
"""
Docstring for __init__.py
"""

from bokeh.plotting import figure, output_file, show
from bokeh.models import Range1d

# prepare some data
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y0 = [i**2 for i in x]
y1 = [10**i for i in x]
y2 = [10**(i**2) for i in x]

# output to static HTML file
output_file("log_lines.html")

# create a new plot
p = figure(
tools="pan,box_zoom,reset,save", y_axis_type="log",
y_range=Range1d(0.001, 10**11, bounds='auto'), title="log axis example",
x_axis_label='sections', y_axis_label='particles'
)

# add some renderers
p.line(x, x, legend="y=x")
p.circle(x, x, legend="y=x", fill_color="white", size=8)
p.line(x, y0, legend="y=x^2", line_width=3)
p.line(x, y1, legend="y=10^x", line_color="red")
p.circle(x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6)
p.line(x, y2, legend="y=10^x^2", line_color="orange", line_dash="4 4")

# show the results
show(p)
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bokeh
six
prettytable
sphinx
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def read(fname):

setup(
name="fpvgcc",
version="0.8.0",
version="0.8.1",
author="Chintalagiri Shashank",
author_email="shashank@chintal.in",
description="Analysing code footprint on embedded microcontrollers "
Expand Down

0 comments on commit 077b0c2

Please sign in to comment.