Skip to content

Commit 84199b6

Browse files
author
rhamlett_microsoft
committed
Update memory metrics snapshot with total available memory
1 parent b316322 commit 84199b6

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

src/PerfProblemSimulator/Services/CrashService.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,27 @@ private void ExecuteOutOfMemory()
257257
{
258258
while (true)
259259
{
260-
// Allocate pinned memory to prevent GC from moving or reclaiming it
261-
var block = GC.AllocateArray<byte>(allocationSize, pinned: true);
262-
263-
// Touch the memory to ensure it's committed
264-
for (int i = 0; i < block.Length; i += 4096)
260+
try
265261
{
266-
block[i] = 0xFF;
262+
// Allocate pinned memory to prevent GC from moving or reclaiming it
263+
var block = GC.AllocateArray<byte>(allocationSize, pinned: true);
264+
265+
// Touch the memory to ensure it's committed
266+
for (int i = 0; i < block.Length; i += 4096)
267+
{
268+
block[i] = 0xFF;
269+
}
270+
271+
allocations.Add(block);
272+
totalAllocated += allocationSize;
273+
274+
_logger.LogWarning("Allocated {TotalMB} MB (pinned)...", totalAllocated / (1024 * 1024));
275+
}
276+
catch (OutOfMemoryException)
277+
{
278+
// Re-throw to be caught by outer handler
279+
throw;
267280
}
268-
269-
allocations.Add(block);
270-
totalAllocated += allocationSize;
271-
272-
_logger.LogWarning("Allocated {TotalMB} MB (pinned)...", totalAllocated / (1024 * 1024));
273-
274-
// Prevent GC from running during allocation loop
275-
GC.TryStartNoGCRegion(allocationSize, disallowFullBlockingGC: false);
276281
}
277282
}
278283
catch (OutOfMemoryException)
@@ -290,10 +295,6 @@ private void ExecuteOutOfMemory()
290295
"This crash was triggered by the Performance Problem Simulator to demonstrate OOM conditions.",
291296
new OutOfMemoryException($"Process exhausted memory after allocating {totalAllocated / (1024 * 1024)} MB"));
292297
}
293-
catch (InvalidOperationException)
294-
{
295-
// TryStartNoGCRegion can throw if already in a no-GC region - ignore and continue
296-
}
297298
}
298299

299300
/// <inheritdoc />

src/PerfProblemSimulator/wwwroot/css/dashboard.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ body {
178178
color: var(--color-text-muted);
179179
}
180180

181+
.metric-total {
182+
font-size: 0.7rem;
183+
color: var(--color-text-muted);
184+
margin-left: 0.25rem;
185+
}
186+
181187
.metric-bar {
182188
height: 4px;
183189
background: #e1dfdd;

src/PerfProblemSimulator/wwwroot/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ <h1>🔥 Performance Problem Simulator - .NET 10 on Windows</h1>
5050
<div class="metric-info">
5151
<div class="metric-value" id="memoryValue">--</div>
5252
<div class="metric-unit">MB</div>
53+
<div class="metric-total" id="memoryTotal"></div>
5354
</div>
5455
<div class="metric-bar">
5556
<div class="metric-bar-fill" id="memoryBar" style="width: 0%"></div>

src/PerfProblemSimulator/wwwroot/js/dashboard.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ function handleMetricsUpdate(snapshot) {
156156
updateMetricCard('threads', snapshot.threadPoolThreads, 'threads', 100);
157157
updateMetricCard('queue', snapshot.threadPoolQueueLength, 'pending', 100);
158158

159+
// Update total memory display
160+
const totalMemoryEl = document.getElementById('memoryTotal');
161+
if (totalMemoryEl && snapshot.totalAvailableMemoryMb) {
162+
const totalFormatted = snapshot.totalAvailableMemoryMb >= 1024
163+
? (snapshot.totalAvailableMemoryMb / 1024).toFixed(1) + ' GB'
164+
: Math.round(snapshot.totalAvailableMemoryMb) + ' MB';
165+
totalMemoryEl.textContent = `of ${totalFormatted}`;
166+
}
167+
159168
// Update history for charts
160169
const timestamp = new Date(snapshot.timestamp);
161170
addToHistory(timestamp, snapshot);

0 commit comments

Comments
 (0)