Skip to content

Commit

Permalink
Merge pull request #228 from geky/add-reserved-memory-reporting
Browse files Browse the repository at this point in the history
Add reserved memory reporting
  • Loading branch information
mazimkhan authored Jun 21, 2017
2 parents 8d40798 + 1a3ad86 commit fc20216
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion mbed_greentea/mbed_report_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ def exporter_memory_metrics_csv(test_result_ext, test_suite_properties=None):
report_key = '%s_%s_max_heap_usage' % (target_name, test_suite_name)
metrics_report[report_key] = memory_metrics['max_heap']

if 'reserved_heap' in memory_metrics:
report_key = '%s_%s_reserved_heap_usage' % (target_name, test_suite_name)
metrics_report[report_key] = memory_metrics['reserved_heap']

if 'thread_stack_summary' in memory_metrics:
thread_stack_summary = memory_metrics['thread_stack_summary']

Expand All @@ -790,7 +794,11 @@ def exporter_memory_metrics_csv(test_result_ext, test_suite_properties=None):
report_key = '%s_%s_max_stack_usage_total' % (target_name, test_suite_name)
metrics_report[report_key] = thread_stack_summary['max_stack_usage_total']

if 'reserved_stack_total' in thread_stack_summary:
report_key = '%s_%s_reserved_stack_total' % (target_name, test_suite_name)
metrics_report[report_key] = thread_stack_summary['reserved_stack_total']

column_names = sorted(metrics_report.keys())
column_values = [str(metrics_report[x]) for x in column_names]

return "%s\n%s" % (','.join(column_names), ','.join(column_values))
return "%s\n%s" % (','.join(column_names), ','.join(column_values))
18 changes: 15 additions & 3 deletions mbed_greentea/mbed_test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_binary_host_tests_dir(binary_path, level=2):
result = get_test_result(htrun_output)
result_test_cases = get_testcase_result(htrun_output)
test_cases_summary = get_testcase_summary(htrun_output)
max_heap, thread_stack_info = get_memory_metrics(htrun_output)
max_heap, reserved_heap, thread_stack_info = get_memory_metrics(htrun_output)

thread_stack_summary = []

Expand All @@ -310,6 +310,7 @@ def get_binary_host_tests_dir(binary_path, level=2):

memory_metrics = {
"max_heap": max_heap,
"reserved_heap": reserved_heap,
"thread_stack_info": thread_stack_info,
"thread_stack_summary": thread_stack_summary
}
Expand Down Expand Up @@ -523,15 +524,22 @@ def get_memory_metrics(output):
is a list of dictionaries with format {entry, arg, max_stack, stack_size}
"""
max_heap_usage = None
reserved_heap = None
thread_info = {}
re_tc_max_heap_usage = re.compile(r"^\[(\d+\.\d+)\][^\{]+\{\{(max_heap_usage);(\d+)\}\}")
re_tc_reserved_heap = re.compile(r"^\[(\d+\.\d+)\][^\{]+\{\{(reserved_heap);(\d+)\}\}")
re_tc_thread_info = re.compile(r"^\[(\d+\.\d+)\][^\{]+\{\{(__thread_info);\"([A-Fa-f0-9\-xX]+)\",(\d+),(\d+)\}\}")
for line in output.splitlines():
m = re_tc_max_heap_usage.search(line)
if m:
_, _, max_heap_usage = m.groups()
max_heap_usage = int(max_heap_usage)

m = re_tc_reserved_heap.search(line)
if m:
_, _, reserved_heap = m.groups()
reserved_heap = int(reserved_heap)

m = re_tc_thread_info.search(line)
if m:
_, _, thread_entry_arg, thread_max_stack, thread_stack_size = m.groups()
Expand All @@ -552,18 +560,21 @@ def get_memory_metrics(output):

thread_info_list = thread_info.values()

return max_heap_usage, thread_info_list
return max_heap_usage, reserved_heap, thread_info_list

def get_thread_with_max_stack_size(thread_stack_info):
max_thread_stack_size = 0
max_thread = None
max_stack_usage_total = 0
reserved_stack_total = 0
for cur_thread_stack_info in thread_stack_info:
if cur_thread_stack_info['stack_size'] > max_thread_stack_size:
max_thread_stack_size = cur_thread_stack_info['stack_size']
max_thread = cur_thread_stack_info
max_stack_usage_total += cur_thread_stack_info['max_stack']
reserved_stack_total += cur_thread_stack_info['stack_size']
max_thread['max_stack_usage_total'] = max_stack_usage_total
max_thread['reserved_stack_total'] = reserved_stack_total
return max_thread

def get_thread_stack_info_summary(thread_stack_info):
Expand All @@ -572,7 +583,8 @@ def get_thread_stack_info_summary(thread_stack_info):
summary = {
'max_stack_size': max_thread_info['stack_size'],
'max_stack_usage': max_thread_info['max_stack'],
'max_stack_usage_total': max_thread_info['max_stack_usage_total']
'max_stack_usage_total': max_thread_info['max_stack_usage_total'],
'reserved_stack_total': max_thread_info['reserved_stack_total']
}
return summary

Expand Down

0 comments on commit fc20216

Please sign in to comment.