Skip to content

Commit ec1ec7c

Browse files
authored
Merge pull request #2015 from mlnx/memap_improvements
[memap] Improve wording on stack/heap and minor improvements
2 parents 5ea1953 + d50139c commit ec1ec7c

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

tools/memap.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long, too-many-nested-blocks, too-many-public-methods, too-many-instance-attributes
33
# pylint: disable=invalid-name, missing-docstring
44

5-
# Memory Map File Analyser for ARM mbed OS
5+
# Memory Map File Analyser for ARM mbed
66

77
import sys
88
import os
@@ -317,7 +317,7 @@ def search_objects(self, path, toolchain):
317317
if test_rex:
318318
search_path = test_rex.group(1) + toolchain + '/mbed-os/'
319319
else:
320-
# It looks this is not an mbed OS project
320+
# It looks this is not an mbed project
321321
# object-to-module mapping cannot be generated
322322
print "Warning: specified toolchain doesn't match with path to the memory map file."
323323
return
@@ -369,6 +369,9 @@ def generate_output(self, export_format, file_output=None):
369369
table = PrettyTable(columns)
370370
table.align["Module"] = "l"
371371

372+
for i in list(self.print_sections):
373+
table.align[i] = 'r'
374+
372375
subtotal = dict()
373376
for k in self.sections:
374377
subtotal[k] = 0
@@ -399,9 +402,9 @@ def generate_output(self, export_format, file_output=None):
399402
if export_format == 'json':
400403
json_obj.append({\
401404
'summary':{\
402-
'static_ram':(subtotal['.data']+subtotal['.bss']),\
403-
'heap':(subtotal['.heap']),\
404-
'stack':(subtotal['.stack']),\
405+
'total_static_ram':(subtotal['.data']+subtotal['.bss']),\
406+
'allocated_heap':(subtotal['.heap']),\
407+
'allocated_stack':(subtotal['.stack']),\
405408
'total_ram':(subtotal['.data']+subtotal['.bss']+subtotal['.heap']+subtotal['.stack']),\
406409
'total_flash':(subtotal['.text']+subtotal['.data']+misc_flash_mem),}})
407410

@@ -419,14 +422,20 @@ def generate_output(self, export_format, file_output=None):
419422
csv_module_section += [i+k]
420423
csv_sizes += [self.modules[i][k]]
421424

422-
csv_module_section += ['static_ram']
425+
csv_module_section += ['total_static_ram']
423426
csv_sizes += [subtotal['.data']+subtotal['.bss']]
424427

425-
csv_module_section += ['heap']
426-
csv_sizes += [subtotal['.heap']]
428+
csv_module_section += ['allocated_heap']
429+
if subtotal['.heap'] == 0:
430+
csv_sizes += ['unknown']
431+
else:
432+
csv_sizes += [subtotal['.heap']]
427433

428-
csv_module_section += ['stack']
429-
csv_sizes += [subtotal['.stack']]
434+
csv_module_section += ['allocated_stack']
435+
if subtotal['.stack'] == 0:
436+
csv_sizes += ['unknown']
437+
else:
438+
csv_sizes += [subtotal['.stack']]
430439

431440
csv_module_section += ['total_ram']
432441
csv_sizes += [subtotal['.data']+subtotal['.bss']+subtotal['.heap']+subtotal['.stack']]
@@ -440,11 +449,20 @@ def generate_output(self, export_format, file_output=None):
440449
else: # default format is 'table'
441450
file_desc.write(table.get_string())
442451
file_desc.write('\n')
443-
file_desc.write("Static RAM memory (data + bss): %s\n" % (str(subtotal['.data']+subtotal['.bss'])))
444-
file_desc.write("Heap: %s\n" % str(subtotal['.heap']))
445-
file_desc.write("Stack: %s\n" % str(subtotal['.stack']))
446-
file_desc.write("Total RAM memory (data + bss + heap + stack): %s\n" % (str(subtotal['.data']+subtotal['.bss']+subtotal['.heap']+subtotal['.stack'])))
447-
file_desc.write("Total Flash memory (text + data + misc): %s\n" % (str(subtotal['.text']+subtotal['.data']+misc_flash_mem)))
452+
453+
if subtotal['.heap'] == 0:
454+
file_desc.write("Allocated Heap: unknown\n")
455+
else:
456+
file_desc.write("Allocated Heap: %s bytes\n" % str(subtotal['.heap']))
457+
458+
if subtotal['.stack'] == 0:
459+
file_desc.write("Allocated Stack: unknown\n")
460+
else:
461+
file_desc.write("Allocated Stack: %s bytes\n" % str(subtotal['.stack']))
462+
463+
file_desc.write("Total Static RAM memory (data + bss): %s bytes\n" % (str(subtotal['.data']+subtotal['.bss'])))
464+
file_desc.write("Total RAM memory (data + bss + heap + stack): %s bytes\n" % (str(subtotal['.data']+subtotal['.bss']+subtotal['.heap']+subtotal['.stack'])))
465+
file_desc.write("Total Flash memory (text + data + misc): %s bytes\n" % (str(subtotal['.text']+subtotal['.data']+misc_flash_mem)))
448466

449467
if file_desc is not sys.stdout:
450468
file_desc.close()
@@ -479,10 +497,10 @@ def parse(self, mapfile, toolchain):
479497

480498
def main():
481499

482-
version = '0.3.10'
500+
version = '0.3.11'
483501

484502
# Parser handling
485-
parser = argparse.ArgumentParser(description="Memory Map File Analyser for ARM mbed OS\nversion %s" % version)
503+
parser = argparse.ArgumentParser(description="Memory Map File Analyser for ARM mbed\nversion %s" % version)
486504

487505
parser.add_argument('file', help='memory map file')
488506

0 commit comments

Comments
 (0)