You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cobalt/tools: Improved smaps analysis and visualization (#7829)
This commit introduces improvements to the smaps memory analysis
toolchain:
- Structured JSON Output: analyze_smaps_logs.py now supports an
--json_output argument to generate a machine-readable JSON file
containing time-series memory data. This enables external tools to
consume and visualize the analysis results.
- Memory Visualization Script: A new script,
visualize_smaps_analysis.py, has been added. It consumes the JSON output
and generates a comprehensive PNG dashboard with three key charts:
- Total PSS and RSS over time.
- Stacked area chart of the top 10 memory consumers. - Line chart of the
top 10 memory regions with the most growth (potential leaks).
- Top 10 Reporting: The analysis and visualization now consistently
report the top 10 memory consumers and growers, providing a more
detailed view.
- Shared Memory Aggregation: All memory regions starting with
"mem/shared_memory" are now aggregated into a single
`[mem/shared_memory]` category for clearer analysis of shared memory
impact.
- Swap Memory Parsing: The toolchain now correctly parses and includes
Swap and SwapPss memory fields in the analysis.
- Updated Documentation and Tests: The README.md has been updated to
reflect the new usage and functionality. Corresponding unit tests have
been added or updated to ensure the correctness of these new features.
#vibe-coded
Bug: 456178181
After processing a batch of smaps files, you can use this script to analyze the entire run. It reads a directory of processed smaps files, tracks memory usage over time, and generates a summary report.
132
132
133
133
The report includes:
134
-
* The top 5 largest memory consumers by PSS and RSS at the end of the run.
135
-
* The top 5 memory regions that have grown the most in PSS and RSS over the duration of the run.
134
+
* The top 10 largest memory consumers by PSS and RSS at the end of the run.
135
+
* The top 10 memory regions that have grown the most in PSS and RSS over the duration of the run.
136
136
* The overall change in total PSS and RSS.
137
137
138
+
The script can also output a structured JSON file containing the time-series data for further analysis or visualization.
The toolchain is designed to be extensible, allowing you to add new fields from the raw smaps files to the analysis and visualization. The key is to follow the data pipeline from the processor (`read_smaps.py`) to the analyzer (`analyze_smaps_logs.py`) and visualizer (`visualize_smaps_analysis.py`).
203
+
204
+
Here is a step-by-step guide using the `Locked` field as an example.
205
+
206
+
### Step 1: Update the Processor (`read_smaps.py`)
207
+
208
+
This is the most critical step to get the new data into the processed files.
209
+
210
+
1. **Add the new field to the `fields` tuple:**
211
+
In `cobalt/tools/performance/smaps/read_smaps.py`, add your new field (in lowercase) to the `fields` string.
The `parse_smaps_entry`functionautomatically parses all fields into a dictionary. You just need to use the new field when creating the `MemDetail` object.
225
+
226
+
```python
227
+
# --- BEFORE ---
228
+
# d = MemDetail(..., data['swap'], data['swappss'])
After these two changes, re-running `read_smaps_batch.py` will produce processed files that include a `locked` column.
239
+
240
+
### Step 2: (Optional) Use the Field in the Analyzer (`analyze_smaps_logs.py`)
241
+
242
+
The analyzer will now have access to the `locked` data. To display it, you can add it to the text report. For example, to show the total change in locked memory:
243
+
244
+
```python
245
+
# In analyze_logs in analyze_smaps_logs.py
246
+
247
+
# Add this block to the "Overall Total Memory Change" section
248
+
if'locked'in total_history and len(total_history['locked']) > 1:
By following this pattern, you can incorporate any field from the raw smaps files into the entire toolchain.
277
+
150
278
## Testing
151
279
152
280
Unit tests are provided to ensure the functionality of the scripts. To run the tests, navigate to the project root directory and execute the following commands. Note that `__init__.py` handles Python path setup, so tests should always be run from the project root.
0 commit comments