mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
tool/metric: show metrics in table
This commit is contained in:
parent
4c65e7e535
commit
d7e6933a33
@ -18,12 +18,15 @@ targets = {}
|
|||||||
|
|
||||||
targets['PATH'] = 1000
|
targets['PATH'] = 1000
|
||||||
targets['GOTO'] = 0
|
targets['GOTO'] = 0
|
||||||
targets['CCN'] = 10
|
targets['CCN'] = 20
|
||||||
targets['CALLS'] = 12
|
targets['CALLS'] = 12
|
||||||
targets['PARAM'] = 7
|
targets['PARAM'] = 7
|
||||||
targets['STMT'] = 100
|
targets['STMT'] = 100
|
||||||
targets['LEVEL'] = 6
|
targets['LEVEL'] = 6
|
||||||
targets['RETURN'] = 6
|
targets['RETURN'] = 1
|
||||||
|
|
||||||
|
excluded_functions = [
|
||||||
|
]
|
||||||
|
|
||||||
def metric_sum(name, value):
|
def metric_sum(name, value):
|
||||||
global metrics
|
global metrics
|
||||||
@ -54,10 +57,13 @@ def metric_measure(metric_name, function_name, actual):
|
|||||||
metric_sum(metric_name + '_SUM', actual)
|
metric_sum(metric_name + '_SUM', actual)
|
||||||
if actual > targets[metric_name]:
|
if actual > targets[metric_name]:
|
||||||
metric_sum(metric_name + '_DEVIATIONS', 1)
|
metric_sum(metric_name + '_DEVIATIONS', 1)
|
||||||
metric_list(metric_name + '_LIST', function_name + '(%u)' % actual)
|
# metric_list(metric_name + '_LIST', function_name + '(%u)' % actual)
|
||||||
|
metric_list(metric_name + '_LIST', function_name)
|
||||||
|
|
||||||
|
|
||||||
def analyze_folders(btstack_root, folders):
|
def analyze_folders(btstack_root, folders):
|
||||||
|
global excluded_functions
|
||||||
|
|
||||||
# File,Name,"'goto' keyword count (raw source)","Return points","Statement count (raw source)(local)",
|
# File,Name,"'goto' keyword count (raw source)","Return points","Statement count (raw source)(local)",
|
||||||
# "Statement count (raw source)(cumulative)","Comment density","McCabe complexity (raw source)",
|
# "Statement count (raw source)(cumulative)","Comment density","McCabe complexity (raw source)",
|
||||||
# "Number of paths through the function","No. different functions called","Function Parameters",
|
# "Number of paths through the function","No. different functions called","Function Parameters",
|
||||||
@ -65,7 +71,7 @@ def analyze_folders(btstack_root, folders):
|
|||||||
fields = [ 'file','function','GOTO','RETURN','_','STMT' ,'_','CCN','PATH','CALLS','PARAM','LEVEL','_','_','_']
|
fields = [ 'file','function','GOTO','RETURN','_','STMT' ,'_','CCN','PATH','CALLS','PARAM','LEVEL','_','_','_']
|
||||||
|
|
||||||
# for now, just read the file
|
# for now, just read the file
|
||||||
with open("btstack.tsv") as fd:
|
with open("metrics.tsv") as fd:
|
||||||
rd = csv.reader(fd, delimiter="\t")
|
rd = csv.reader(fd, delimiter="\t")
|
||||||
last_function_name = ''
|
last_function_name = ''
|
||||||
for row in rd:
|
for row in rd:
|
||||||
@ -73,7 +79,7 @@ def analyze_folders(btstack_root, folders):
|
|||||||
function_metrics = {}
|
function_metrics = {}
|
||||||
for key, value in zip(fields, row):
|
for key, value in zip(fields, row):
|
||||||
if key == 'file':
|
if key == 'file':
|
||||||
file = value
|
file = value.replace('../../','')
|
||||||
continue
|
continue
|
||||||
if key == 'function':
|
if key == 'function':
|
||||||
function_name = value
|
function_name = value
|
||||||
@ -83,11 +89,15 @@ def analyze_folders(btstack_root, folders):
|
|||||||
function_metrics[key] = value
|
function_metrics[key] = value
|
||||||
if file.endswith('.h'):
|
if file.endswith('.h'):
|
||||||
continue
|
continue
|
||||||
if function_name != last_function_name:
|
qualified_function_name = file+':'+function_name
|
||||||
last_function_name = function_name
|
if qualified_function_name != last_function_name:
|
||||||
|
last_function_name = qualified_function_name
|
||||||
metric_sum('FUNC', 1)
|
metric_sum('FUNC', 1)
|
||||||
|
# exclude functions
|
||||||
|
if qualified_function_name in excluded_functions:
|
||||||
|
continue
|
||||||
for key,value in function_metrics.items():
|
for key,value in function_metrics.items():
|
||||||
metric_measure(key, function_name, int(function_metrics[key]))
|
metric_measure(key, qualified_function_name, int(function_metrics[key]))
|
||||||
|
|
||||||
def analyze(folders):
|
def analyze(folders):
|
||||||
# print ("\nAnalyzing:")
|
# print ("\nAnalyzing:")
|
||||||
@ -115,6 +125,22 @@ def list_metrics():
|
|||||||
else:
|
else:
|
||||||
print ('- %-20s: %5u' % (key, value))
|
print ('- %-20s: %5u' % (key, value))
|
||||||
|
|
||||||
|
def list_metrics_table():
|
||||||
|
row = "%-11s |%11s |%11s |%11s"
|
||||||
|
|
||||||
|
print( row % ('Name', 'Target', 'Deviations', 'Max value'))
|
||||||
|
print("------------|------------|------------|------------")
|
||||||
|
|
||||||
|
ordered_metrics = [ 'PATH', 'GOTO', 'CCN', 'CALLS', 'PARAM', 'STMT', 'LEVEL', 'RETURN', 'FUNC'];
|
||||||
|
for metric_name in ordered_metrics:
|
||||||
|
if metric_name in targets:
|
||||||
|
target = targets[metric_name]
|
||||||
|
deviations = metrics[metric_name + '_DEVIATIONS']
|
||||||
|
max = metrics[metric_name + '_MAX']
|
||||||
|
print ( row % ( metric_name, target, deviations, max))
|
||||||
|
else:
|
||||||
|
print ( row % ( metric_name, '', '', ''))
|
||||||
|
|
||||||
def list_deviations():
|
def list_deviations():
|
||||||
global metrics
|
global metrics
|
||||||
for key,value in sorted(metrics.items()):
|
for key,value in sorted(metrics.items()):
|
||||||
@ -124,6 +150,7 @@ def list_deviations():
|
|||||||
print ('\n'.join(value))
|
print ('\n'.join(value))
|
||||||
|
|
||||||
analyze(folders)
|
analyze(folders)
|
||||||
list_targets()
|
list_metrics_table()
|
||||||
list_metrics()
|
# list_targets()
|
||||||
list_deviations()
|
# list_metrics()
|
||||||
|
# list_deviations()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user