Skip to content

Commit 67dcf37

Browse files
committed
Report deltas in relative form in addition to absolute
Additional columns are added to the report to provide the data relative to the maximum available memory in addition to the previous absolute values.
1 parent e258984 commit 67dcf37

File tree

4 files changed

+254
-93
lines changed

4 files changed

+254
-93
lines changed

reportsizedeltas.py

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ReportKeys:
6464
sizes = "sizes"
6565
name = "name"
6666
absolute = "absolute"
67+
relative = "relative"
6768
current = "current"
6869
previous = "previous"
6970
delta = "delta"
@@ -255,8 +256,12 @@ def get_sketches_reports(self, artifact_folder_object):
255256
# Combine sketches reports into an array
256257
with open(file=artifact_folder + "/" + report_filename) as report_file:
257258
report_data = json.load(report_file)
258-
if self.ReportKeys.boards not in report_data:
259-
# Sketches reports use the old format, skip
259+
if (
260+
(self.ReportKeys.boards not in report_data)
261+
or (self.ReportKeys.maximum
262+
not in report_data[self.ReportKeys.boards][0][self.ReportKeys.sizes][0])
263+
):
264+
# Sketches reports use an old format, skip
260265
print("Old format sketches report found, skipping")
261266
continue
262267

@@ -294,14 +299,27 @@ def generate_report(self, sketches_reports):
294299
# Populate the row with data
295300
for size_data in fqbn_data[self.ReportKeys.sizes]:
296301
# Determine column number for this memory type
297-
column_number = get_report_column_number(report=summary_report_data,
298-
column_heading=size_data[self.ReportKeys.name])
302+
column_number = get_report_column_number(
303+
report=summary_report_data,
304+
column_heading=size_data[self.ReportKeys.name]
305+
)
299306

300-
# Add the memory data to the cell
307+
# Add the absolute memory data to the cell
301308
summary_report_data[row_number][column_number] = (
302309
get_summary_value(
310+
show_emoji=True,
303311
minimum=size_data[self.ReportKeys.delta][self.ReportKeys.absolute][self.ReportKeys.minimum],
304-
maximum=size_data[self.ReportKeys.delta][self.ReportKeys.absolute][self.ReportKeys.maximum])
312+
maximum=size_data[self.ReportKeys.delta][self.ReportKeys.absolute][self.ReportKeys.maximum]
313+
)
314+
)
315+
316+
# Add the relative memory data to the cell
317+
summary_report_data[row_number][column_number + 1] = (
318+
get_summary_value(
319+
show_emoji=False,
320+
minimum=size_data[self.ReportKeys.delta][self.ReportKeys.relative][self.ReportKeys.minimum],
321+
maximum=size_data[self.ReportKeys.delta][self.ReportKeys.relative][self.ReportKeys.maximum]
322+
)
305323
)
306324

307325
# Generate detailed report data
@@ -321,13 +339,22 @@ def generate_report(self, sketches_reports):
321339
# Determine column number for this memory type
322340
column_number = get_report_column_number(
323341
report=full_report_data,
324-
column_heading=sketch[self.ReportKeys.name] + "<br>" + size_data[self.ReportKeys.name])
342+
column_heading=(
343+
sketch[self.ReportKeys.name] + "<br>"
344+
+ size_data[self.ReportKeys.name]
345+
)
346+
)
325347

326-
# Add the memory data to the cell
348+
# Add the absolute memory data to the cell
327349
full_report_data[row_number][column_number] = (
328350
size_data[self.ReportKeys.delta][self.ReportKeys.absolute]
329351
)
330352

353+
# Add the relative memory data to the cell
354+
full_report_data[row_number][column_number + 1] = (
355+
size_data[self.ReportKeys.delta][self.ReportKeys.relative]
356+
)
357+
331358
# Add comment heading
332359
report_markdown = self.report_key_beginning + sketches_reports[0][self.ReportKeys.commit_hash] + "**\n\n"
333360

@@ -566,23 +593,34 @@ def get_report_column_number(report, column_heading):
566593
Keyword arguments:
567594
column_heading -- the text of the column heading. If it doesn't exist, a column will be created with this heading.
568595
"""
596+
relative_column_heading = "%"
597+
569598
try:
570599
column_number = report[0].index(column_heading, 1)
571600
except ValueError:
572-
# There is no existing column, so create one
601+
# There is no existing column, so create columns for relative and absolute
573602
column_number = len(report[0])
603+
604+
# Absolute column
574605
# Add the heading
575606
report[0].append(column_heading)
576607
# Expand the size of the last (current) row to match the new number of columns
577608
report[len(report) - 1].append("")
578609

610+
# Relative column
611+
# Add the heading
612+
report[0].append(relative_column_heading)
613+
# Expand the size of the last (current) row to match the new number of columns
614+
report[len(report) - 1].append("")
615+
579616
return column_number
580617

581618

582-
def get_summary_value(minimum, maximum):
619+
def get_summary_value(show_emoji, minimum, maximum):
583620
"""Return the Markdown formatted text for a memory change data cell in the report table.
584621
585622
Keyword arguments:
623+
show_emoji -- whether to add the emoji change indicator
586624
minimum -- minimum amount of change for this memory type
587625
minimum -- maximum amount of change for this memory type
588626
"""
@@ -613,7 +651,7 @@ def get_summary_value(minimum, maximum):
613651

614652
value = str(minimum) + " - " + str(maximum)
615653

616-
if emoji is not None:
654+
if show_emoji and (emoji is not None):
617655
value = emoji + " " + value
618656

619657
return value

tests/data/size-deltas-reports-new/arduino-avr-leonardo.json

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,34 @@
1111
"sizes": [
1212
{
1313
"name": "flash",
14+
"maximum": 28672,
1415
"current": {
15-
"absolute": 3494
16+
"absolute": 3494,
17+
"relative": 12.19
1618
},
1719
"previous": {
18-
"absolute": "N/A"
20+
"absolute": "N/A",
21+
"relative": "N/A"
1922
},
2023
"delta": {
21-
"absolute": "N/A"
24+
"absolute": "N/A",
25+
"relative": "N/A"
2226
}
2327
},
2428
{
2529
"name": "RAM for global variables",
30+
"maximum": 2560,
2631
"current": {
27-
"absolute": 153
32+
"absolute": 153,
33+
"relative": 5.97
2834
},
2935
"previous": {
30-
"absolute": "N/A"
36+
"absolute": "N/A",
37+
"relative": "N/A"
3138
},
3239
"delta": {
33-
"absolute": "N/A"
40+
"absolute": "N/A",
41+
"relative": "N/A"
3442
}
3543
}
3644
]
@@ -41,26 +49,34 @@
4149
"sizes": [
4250
{
4351
"name": "flash",
52+
"maximum": 28672,
4453
"current": {
45-
"absolute": 3462
54+
"absolute": 3462,
55+
"relative": 12.07
4656
},
4757
"previous": {
48-
"absolute": 3474
58+
"absolute": 3474,
59+
"relative": 12.12
4960
},
5061
"delta": {
51-
"absolute": -12
62+
"absolute": -12,
63+
"relative": -0.05
5264
}
5365
},
5466
{
5567
"name": "RAM for global variables",
68+
"maximum": 2560,
5669
"current": {
57-
"absolute": 149
70+
"absolute": 149,
71+
"relative": 5.82
5872
},
5973
"previous": {
60-
"absolute": 149
74+
"absolute": 149,
75+
"relative": 5.82
6176
},
6277
"delta": {
63-
"absolute": 0
78+
"absolute": 0,
79+
"relative": 0.0
6480
}
6581
}
6682
]
@@ -69,19 +85,29 @@
6985
"sizes": [
7086
{
7187
"name": "flash",
88+
"maximum": 28672,
7289
"delta": {
7390
"absolute": {
7491
"minimum": -12,
7592
"maximum": -12
93+
},
94+
"relative": {
95+
"minimum": -0.05,
96+
"maximum": -0.05
7697
}
7798
}
7899
},
79100
{
80101
"name": "RAM for global variables",
102+
"maximum": 2560,
81103
"delta": {
82104
"absolute": {
83105
"minimum": 0,
84106
"maximum": 0
107+
},
108+
"relative": {
109+
"minimum": 0.0,
110+
"maximum": 0.0
85111
}
86112
}
87113
}

tests/data/size-deltas-reports-new/arduino-avr-uno.json

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,34 @@
1111
"sizes": [
1212
{
1313
"name": "flash",
14+
"maximum": 32256,
1415
"current": {
15-
"absolute": 1460
16+
"absolute": 1460,
17+
"relative": 4.53
1618
},
1719
"previous": {
18-
"absolute": "N/A"
20+
"absolute": "N/A",
21+
"relative": "N/A"
1922
},
2023
"delta": {
21-
"absolute": "N/A"
24+
"absolute": "N/A",
25+
"relative": "N/A"
2226
}
2327
},
2428
{
2529
"name": "RAM for global variables",
30+
"maximum": 2048,
2631
"current": {
27-
"absolute": 190
32+
"absolute": 190,
33+
"relative": 9.28
2834
},
2935
"previous": {
30-
"absolute": "N/A"
36+
"absolute": "N/A",
37+
"relative": "N/A"
3138
},
3239
"delta": {
33-
"absolute": "N/A"
40+
"absolute": "N/A",
41+
"relative": "N/A"
3442
}
3543
}
3644
]
@@ -41,26 +49,34 @@
4149
"sizes": [
4250
{
4351
"name": "flash",
52+
"maximum": 32256,
4453
"current": {
45-
"absolute": 444
54+
"absolute": 444,
55+
"relative": 1.38
4656
},
4757
"previous": {
48-
"absolute": 1438
58+
"absolute": 1438,
59+
"relative": 4.46
4960
},
5061
"delta": {
51-
"absolute": -994
62+
"absolute": -994,
63+
"relative": -3.08
5264
}
5365
},
5466
{
5567
"name": "RAM for global variables",
68+
"maximum": 2048,
5669
"current": {
57-
"absolute": 9
70+
"absolute": 9,
71+
"relative": 0.44
5872
},
5973
"previous": {
60-
"absolute": 184
74+
"absolute": 184,
75+
"relative": 8.98
6176
},
6277
"delta": {
63-
"absolute": -175
78+
"absolute": -175,
79+
"relative": -8.54
6480
}
6581
}
6682
]
@@ -69,19 +85,29 @@
6985
"sizes": [
7086
{
7187
"name": "flash",
88+
"maximum": 32256,
7289
"delta": {
7390
"absolute": {
7491
"minimum": -994,
7592
"maximum": -994
93+
},
94+
"relative": {
95+
"minimum": -3.08,
96+
"maximum": -3.08
7697
}
7798
}
7899
},
79100
{
80101
"name": "RAM for global variables",
102+
"maximum": 2048,
81103
"delta": {
82104
"absolute": {
83105
"minimum": -175,
84106
"maximum": -175
107+
},
108+
"relative": {
109+
"minimum": -8.54,
110+
"maximum": -8.54
85111
}
86112
}
87113
}

0 commit comments

Comments
 (0)