Skip to content

Commit a63cf02

Browse files
authored
Streamline bloat reports, part 2 of 2 (#33716)
* Streamline bloat reports, part 2 Remove the early attempt to aggregate FLASH vs RAM based on whether ELF segments are writable or not, which turned out not to be useful because several platforms mark flash segments as writable. Now that explicit section groups are in use (#33642), there is no additional value to segment aggregation even on platforms that mark them accurately. * Streamline bloat reports, part 2 Remove the early attempt to aggregate FLASH vs RAM based on whether ELF segments are writable or not, which turned out not to be useful because several platforms mark flash segments as writable. Now that explicit section groups are in use (#33642), there is no additional value to segment aggregation even on platforms that mark them accurately. * Filter down to region reports only.
1 parent 2feb25f commit a63cf02

File tree

3 files changed

+17
-34
lines changed

3 files changed

+17
-34
lines changed

scripts/tools/memory/gh_report.py

+4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ def report_matching_commits(self) -> Dict[str, pd.DataFrame]:
276276
continue
277277

278278
df = pd.DataFrame(changes.rows, columns=changes.columns)
279+
280+
# Filter down to region reports only.
281+
df = df[df['kind'] == 'region'].drop('kind', axis=1)
282+
279283
df.attrs = {
280284
'name': f'{pr},{parent},{commit}',
281285
'title': (f'PR #{pr}: ' if pr else '') +

scripts/tools/memory/gh_sizes.py

+10-25
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
{"section": ".data", "size": 1648},
5959
{"section": ".text", "size": 740236}
6060
],
61-
"wr": [
62-
{"wr": 0, "size": 262144},
63-
{"wr": 1, "size": 74023}
61+
"region": [
62+
{"region": "FLASH", "size": 262144},
63+
{"region": "RAM", "size": 74023}
6464
]
6565
}
6666
}
@@ -77,8 +77,7 @@
7777
import memdf.report
7878
import memdf.select
7979
import memdf.util
80-
import numpy as np # type: ignore
81-
from memdf import Config, ConfigDescription, DFs, SectionDF, SegmentDF
80+
from memdf import Config, ConfigDescription, DFs, SectionDF
8281

8382
PLATFORM_CONFIG_DIR = pathlib.Path('scripts/tools/memory/platform')
8483

@@ -162,7 +161,8 @@ def main(argv):
162161
**CONFIG,
163162
}
164163
# In case there is no platform configuration file, default to using a popular set of section names.
165-
config_desc['section.select']['default'] = ['.text', '.rodata', '.data', '.bss']
164+
config_desc['section.select']['default'] = [
165+
'.text', '.rodata', '.data', '.bss']
166166

167167
config = Config().init(config_desc)
168168
config.put('output.file', output)
@@ -197,32 +197,17 @@ def main(argv):
197197

198198
collected: DFs = memdf.collect.collect_files(config, [binary])
199199

200-
# Aggregate loaded segments, by writable (RAM) or not (flash).
201-
segments = collected[SegmentDF.name]
202-
segments['segment'] = segments.index
203-
segments['wr'] = ((segments['flags'] & 2) != 0).convert_dtypes(
204-
convert_boolean=False, convert_integer=True)
205-
segment_summary = segments[segments['type'] == 'PT_LOAD'][[
206-
'wr', 'size'
207-
]].groupby('wr').aggregate(np.sum).reset_index().astype(
208-
{'size': np.int64})
209-
segment_summary.attrs['name'] = "wr"
210-
211200
sections = collected[SectionDF.name]
212-
sections = sections.join(on='segment',
213-
how='left',
214-
other=segments,
215-
rsuffix='-segment')
216-
section_summary = sections[['section', 'size',
217-
'wr']].sort_values(by='section')
201+
section_summary = sections[['section',
202+
'size']].sort_values(by='section')
218203
section_summary.attrs['name'] = "section"
219204

220-
region_summary = memdf.select.groupby(config, collected['section'], 'region')
205+
region_summary = memdf.select.groupby(
206+
config, collected['section'], 'region')
221207
region_summary.attrs['name'] = "region"
222208

223209
summaries = {
224210
'section': section_summary,
225-
'memory': segment_summary,
226211
'region': region_summary,
227212
}
228213

scripts/tools/memory/memdf/sizedb.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ def add_sizes_from_json(self, s: Union[bytes, str], origin: Dict):
109109
'size': i['size'],
110110
'kind': frame
111111
})
112-
# Add segment sizes.
113-
for i in r['frames'].get('wr', []):
114-
r['sizes'].append({
115-
'name': ('(read only)', '(read/write)')[int(i['wr'])],
116-
'size': i['size'],
117-
'kind': 'wr'
118-
})
119112
self.add_sizes(**r)
120113

121114
def add_sizes_from_zipfile(self, f: Union[IO, Path], origin: Dict):
@@ -182,6 +175,7 @@ def select_changes(self, parent: str, commit: str) -> ChangeInfo:
182175
pb.id AS parent_build,
183176
cb.id AS commit_build,
184177
t.platform, t.config, t.target,
178+
cs.kind AS kind,
185179
cs.name AS name,
186180
ps.size AS parent_size,
187181
cs.size AS commit_size,
@@ -196,7 +190,7 @@ def select_changes(self, parent: str, commit: str) -> ChangeInfo:
196190
cs.name, cb.time DESC, pb.time DESC
197191
''', (commit, parent))
198192

199-
keep = ('platform', 'target', 'config', 'name', 'parent_size',
193+
keep = ('platform', 'target', 'config', 'kind', 'name', 'parent_size',
200194
'commit_size')
201195
things: set[int] = set()
202196
artifacts: set[int] = set()
@@ -229,7 +223,7 @@ def select_changes(self, parent: str, commit: str) -> ChangeInfo:
229223
artifacts.add(row['artifact'])
230224
builds.add(row['commit_build'])
231225

232-
return ChangeInfo(('platform', 'target', 'config', 'section',
226+
return ChangeInfo(('platform', 'target', 'config', 'kind', 'section',
233227
parent[:8], commit[:8], 'change', '% change'), rows,
234228
things, builds, stale_builds, artifacts,
235229
stale_artifacts)

0 commit comments

Comments
 (0)