Skip to content

Commit 5c4370c

Browse files
Fix duplication of embedded matlab functions in lobster trace
By default, all embedded functions are named fcn; now that name is replaced with the full name of the block.
1 parent f6f59c3 commit 5c4370c

12 files changed

Lines changed: 221 additions & 104 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ Not quite compatible with Octave yet. See #43 [octave support](https://github.co
2020

2121
### 0.9.42-dev
2222

23-
23+
* Fix issue with MATLAB functions embedded in Simulink. Usually people
24+
left the default name (i.e. `fcn`) which caused many duplicate items
25+
to appear in the `mh_trace` output. Now embedded functions use the
26+
name of the subsystem (i.e. what you'd see in Simulink as the name).
2427

2528
### 0.9.41
2629

miss_hit/mh_trace.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ def __init__(self, wp, imp_items=None, act_items=None):
5454

5555

5656
class Function_Visitor(AST_Visitor):
57-
def __init__(self, in_test_dir, mh, cu, ep):
57+
def __init__(self, in_test_dir, mh, cu, ep, blockname):
5858
assert isinstance(in_test_dir, bool)
5959
assert isinstance(mh, Message_Handler)
6060
assert isinstance(cu, Compilation_Unit)
6161
assert ep is None or isinstance(ep, Project_Directive)
62+
assert isinstance(blockname, str) or blockname is None
6263

6364
self.in_test_dir = in_test_dir
6465
self.tag_stack = []
@@ -68,6 +69,7 @@ def __init__(self, in_test_dir, mh, cu, ep):
6869
self.act_items = []
6970
self.name_prefix = cu.get_name_prefix()
7071
self.in_test_block = False
72+
self.blockname = blockname
7173
if ep is None:
7274
self.is_shared = False
7375
else:
@@ -135,7 +137,10 @@ def visit_end(self, node, n_parent, relation):
135137
# Create entry for tracing
136138
if isinstance(node, Function_Definition) and \
137139
not any(self.no_tracing_stack):
138-
name = self.name_prefix + node.get_local_name()
140+
if self.blockname:
141+
name = self.blockname
142+
else:
143+
name = self.name_prefix + node.get_local_name()
139144
tag = "matlab %s" % name
140145
location = node.loc()
141146
lobster_loc = {"kind" : "file",
@@ -314,7 +319,11 @@ def process_wp(cls, wp):
314319
except Error:
315320
return MH_Trace_Result(wp)
316321

317-
visitor = Function_Visitor(wp.in_test_dir, wp.mh, n_cu, n_ep)
322+
visitor = Function_Visitor(wp.in_test_dir,
323+
wp.mh,
324+
n_cu,
325+
n_ep,
326+
wp.blockname)
318327
n_cu.visit(None, visitor, "Root")
319328

320329
# Return results

miss_hit_core/work_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(self, simulink_wp, simulink_block):
157157

158158
super().__init__(simulink_wp.in_test_dir,
159159
n_container.filename,
160-
simulink_block.local_name(),
160+
simulink_block.full_name(),
161161
simulink_block.get_encoding(),
162162
simulink_wp.mh.fork(),
163163
simulink_wp.options,

tests/metrics/simulink/expected_out.txt

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== PLAIN MODE ===
22
=== Code metric by file:
33

4-
* Code metrics for file test1.slx/Add One:
4+
* Code metrics for file test1.slx/test1/Add One:
55
File lines: 3
66

77
Code metrics for function add_one:
@@ -13,7 +13,7 @@
1313
Parameters : 2
1414
Persistents : 0
1515

16-
* Code metrics for file test1.slx/Multiply:
16+
* Code metrics for file test1.slx/test1/Multiply:
1717
File lines: 3
1818

1919
Code metrics for function my_multiply:
@@ -25,7 +25,7 @@
2525
Parameters : 3
2626
Persistents : 0
2727

28-
* Code metrics for file test1.slx/Sub One:
28+
* Code metrics for file test1.slx/test1/Sub One:
2929
File lines: 3
3030

3131
Code metrics for function sub_one:
@@ -37,7 +37,7 @@
3737
Parameters : 2
3838
Persistents : 0
3939

40-
* Code metrics for file test2.slx/My_Sub_System/Potato:
40+
* Code metrics for file test2.slx/test2/My_Sub_System/Potato:
4141
File lines: 3
4242

4343
Code metrics for function fcn:
@@ -49,7 +49,7 @@
4949
Parameters : 2
5050
Persistents : 0
5151

52-
* Code metrics for file test2.slx/Potato:
52+
* Code metrics for file test2.slx/test2/Potato:
5353
File lines: 3
5454

5555
Code metrics for function fcn:
@@ -64,39 +64,39 @@
6464
=== Global summary of worst offenders by metric:
6565

6666
* File metric 'File lines':
67-
1. 3 (test2.slx/Potato)
68-
2. 3 (test2.slx/My_Sub_System/Potato)
69-
3. 3 (test1.slx/Sub One)
70-
4. 3 (test1.slx/Multiply)
71-
5. 3 (test1.slx/Add One)
67+
1. 3 (test2.slx/test2/Potato)
68+
2. 3 (test2.slx/test2/My_Sub_System/Potato)
69+
3. 3 (test1.slx/test1/Sub One)
70+
4. 3 (test1.slx/test1/Multiply)
71+
5. 3 (test1.slx/test1/Add One)
7272

7373
* Function metric 'Cyclomatic complexity':
74-
1. 1 (test2.slx/Potato, function fcn)
75-
2. 1 (test2.slx/My_Sub_System/Potato, function fcn)
76-
3. 1 (test1.slx/Sub One, function sub_one)
77-
4. 1 (test1.slx/Multiply, function my_multiply)
78-
5. 1 (test1.slx/Add One, function add_one)
74+
1. 1 (test2.slx/test2/Potato, function fcn)
75+
2. 1 (test2.slx/test2/My_Sub_System/Potato, function fcn)
76+
3. 1 (test1.slx/test1/Sub One, function sub_one)
77+
4. 1 (test1.slx/test1/Multiply, function my_multiply)
78+
5. 1 (test1.slx/test1/Add One, function add_one)
7979

8080
* Function metric 'Function lines':
81-
1. 3 (test2.slx/Potato, function fcn)
82-
2. 3 (test2.slx/My_Sub_System/Potato, function fcn)
83-
3. 3 (test1.slx/Sub One, function sub_one)
84-
4. 3 (test1.slx/Multiply, function my_multiply)
85-
5. 3 (test1.slx/Add One, function add_one)
81+
1. 3 (test2.slx/test2/Potato, function fcn)
82+
2. 3 (test2.slx/test2/My_Sub_System/Potato, function fcn)
83+
3. 3 (test1.slx/test1/Sub One, function sub_one)
84+
4. 3 (test1.slx/test1/Multiply, function my_multiply)
85+
5. 3 (test1.slx/test1/Add One, function add_one)
8686

8787
* Function metric 'Number of paths':
88-
1. 1 (test2.slx/Potato, function fcn)
89-
2. 1 (test2.slx/My_Sub_System/Potato, function fcn)
90-
3. 1 (test1.slx/Sub One, function sub_one)
91-
4. 1 (test1.slx/Multiply, function my_multiply)
92-
5. 1 (test1.slx/Add One, function add_one)
88+
1. 1 (test2.slx/test2/Potato, function fcn)
89+
2. 1 (test2.slx/test2/My_Sub_System/Potato, function fcn)
90+
3. 1 (test1.slx/test1/Sub One, function sub_one)
91+
4. 1 (test1.slx/test1/Multiply, function my_multiply)
92+
5. 1 (test1.slx/test1/Add One, function add_one)
9393

9494
* Function metric 'Parameters':
95-
1. 3 (test1.slx/Multiply, function my_multiply)
96-
2. 2 (test2.slx/Potato, function fcn)
97-
3. 2 (test2.slx/My_Sub_System/Potato, function fcn)
98-
4. 2 (test1.slx/Sub One, function sub_one)
99-
5. 2 (test1.slx/Add One, function add_one)
95+
1. 3 (test1.slx/test1/Multiply, function my_multiply)
96+
2. 2 (test2.slx/test2/Potato, function fcn)
97+
3. 2 (test2.slx/test2/My_Sub_System/Potato, function fcn)
98+
4. 2 (test1.slx/test1/Sub One, function sub_one)
99+
5. 2 (test1.slx/test1/Add One, function add_one)
100100

101101
MISS_HIT Metric Summary: 2 file(s) analysed, everything seems fine
102102

tests/metrics/simulink/metrics.html

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,43 @@ <h1>Worst offenders</h1>
2929
<tbody>
3030
<tr>
3131
<td>1</td>
32-
<td class='tip' tip='Potato'><a href='#test2.slx/Potato'>3</a></td>
33-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/Potato'>1</a></td>
34-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/Potato'>3</a></td>
35-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/Potato'>1</a></td>
36-
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/Multiply'>3</a></td>
32+
<td class='tip' tip='Potato'><a href='#test2.slx/test2/Potato'>3</a></td>
33+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/Potato'>1</a></td>
34+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/Potato'>3</a></td>
35+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/Potato'>1</a></td>
36+
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/test1/Multiply'>3</a></td>
3737
</tr>
3838
<tr>
3939
<td>2</td>
40-
<td class='tip' tip='Potato'><a href='#test2.slx/My_Sub_System/Potato'>3</a></td>
41-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/My_Sub_System/Potato'>1</a></td>
42-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/My_Sub_System/Potato'>3</a></td>
43-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/My_Sub_System/Potato'>1</a></td>
44-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/Potato'>2</a></td>
40+
<td class='tip' tip='Potato'><a href='#test2.slx/test2/My_Sub_System/Potato'>3</a></td>
41+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/My_Sub_System/Potato'>1</a></td>
42+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/My_Sub_System/Potato'>3</a></td>
43+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/My_Sub_System/Potato'>1</a></td>
44+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/Potato'>2</a></td>
4545
</tr>
4646
<tr>
4747
<td>3</td>
48-
<td class='tip' tip='Sub One'><a href='#test1.slx/Sub One'>3</a></td>
49-
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/Sub One'>1</a></td>
50-
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/Sub One'>3</a></td>
51-
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/Sub One'>1</a></td>
52-
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/My_Sub_System/Potato'>2</a></td>
48+
<td class='tip' tip='Sub One'><a href='#test1.slx/test1/Sub One'>3</a></td>
49+
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/test1/Sub One'>1</a></td>
50+
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/test1/Sub One'>3</a></td>
51+
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/test1/Sub One'>1</a></td>
52+
<td class='tip' tip='fcn in file Potato'><a href='#test2.slx/test2/My_Sub_System/Potato'>2</a></td>
5353
</tr>
5454
<tr>
5555
<td>4</td>
56-
<td class='tip' tip='Multiply'><a href='#test1.slx/Multiply'>3</a></td>
57-
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/Multiply'>1</a></td>
58-
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/Multiply'>3</a></td>
59-
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/Multiply'>1</a></td>
60-
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/Sub One'>2</a></td>
56+
<td class='tip' tip='Multiply'><a href='#test1.slx/test1/Multiply'>3</a></td>
57+
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/test1/Multiply'>1</a></td>
58+
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/test1/Multiply'>3</a></td>
59+
<td class='tip' tip='my_multiply in file Multiply'><a href='#test1.slx/test1/Multiply'>1</a></td>
60+
<td class='tip' tip='sub_one in file Sub One'><a href='#test1.slx/test1/Sub One'>2</a></td>
6161
</tr>
6262
<tr>
6363
<td>5</td>
64-
<td class='tip' tip='Add One'><a href='#test1.slx/Add One'>3</a></td>
65-
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/Add One'>1</a></td>
66-
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/Add One'>3</a></td>
67-
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/Add One'>1</a></td>
68-
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/Add One'>2</a></td>
64+
<td class='tip' tip='Add One'><a href='#test1.slx/test1/Add One'>3</a></td>
65+
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/test1/Add One'>1</a></td>
66+
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/test1/Add One'>3</a></td>
67+
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/test1/Add One'>1</a></td>
68+
<td class='tip' tip='add_one in file Add One'><a href='#test1.slx/test1/Add One'>2</a></td>
6969
</tr>
7070
<tr>
7171
<td>6</td>
@@ -117,7 +117,7 @@ <h1>Code metrics by file</h1>
117117
</div>
118118
<section>
119119
<div class='metrics'>
120-
<h2><a name='test1.slx/Add One'>test1.slx/Add One</a></h2>
120+
<h2><a name='test1.slx/test1/Add One'>test1.slx/test1/Add One</a></h2>
121121
<table>
122122
<thead>
123123
<tr>
@@ -158,7 +158,7 @@ <h2><a name='test1.slx/Add One'>test1.slx/Add One</a></h2>
158158
</table>
159159
</div>
160160
<div class='metrics'>
161-
<h2><a name='test1.slx/Multiply'>test1.slx/Multiply</a></h2>
161+
<h2><a name='test1.slx/test1/Multiply'>test1.slx/test1/Multiply</a></h2>
162162
<table>
163163
<thead>
164164
<tr>
@@ -199,7 +199,7 @@ <h2><a name='test1.slx/Multiply'>test1.slx/Multiply</a></h2>
199199
</table>
200200
</div>
201201
<div class='metrics'>
202-
<h2><a name='test1.slx/Sub One'>test1.slx/Sub One</a></h2>
202+
<h2><a name='test1.slx/test1/Sub One'>test1.slx/test1/Sub One</a></h2>
203203
<table>
204204
<thead>
205205
<tr>
@@ -240,7 +240,7 @@ <h2><a name='test1.slx/Sub One'>test1.slx/Sub One</a></h2>
240240
</table>
241241
</div>
242242
<div class='metrics'>
243-
<h2><a name='test2.slx/My_Sub_System/Potato'>test2.slx/My_Sub_System/Potato</a></h2>
243+
<h2><a name='test2.slx/test2/My_Sub_System/Potato'>test2.slx/test2/My_Sub_System/Potato</a></h2>
244244
<table>
245245
<thead>
246246
<tr>
@@ -281,7 +281,7 @@ <h2><a name='test2.slx/My_Sub_System/Potato'>test2.slx/My_Sub_System/Potato</a><
281281
</table>
282282
</div>
283283
<div class='metrics'>
284-
<h2><a name='test2.slx/Potato'>test2.slx/Potato</a></h2>
284+
<h2><a name='test2.slx/test2/Potato'>test2.slx/test2/Potato</a></h2>
285285
<table>
286286
<thead>
287287
<tr>

0 commit comments

Comments
 (0)