Skip to content

Commit c2c02b4

Browse files
committed
feat: add memory usage and cache metrics display in bottom-left corner
- Create MemoryMetrics view model with auto-updating stats - Display working set and managed memory in MB - Show user cache and performance metrics counts - Updates every 5 seconds automatically - Positioned at bottom of left sidebar with subtle styling
1 parent 3f7d3d8 commit c2c02b4

File tree

4 files changed

+154
-5
lines changed

4 files changed

+154
-5
lines changed

src/ViewModels/MemoryMetrics.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Threading;
3+
using CommunityToolkit.Mvvm.ComponentModel;
4+
5+
namespace SourceGit.ViewModels
6+
{
7+
public class MemoryMetrics : ObservableObject, IDisposable
8+
{
9+
public long WorkingSetMB
10+
{
11+
get => _workingSetMB;
12+
private set => SetProperty(ref _workingSetMB, value);
13+
}
14+
15+
public long ManagedMemoryMB
16+
{
17+
get => _managedMemoryMB;
18+
private set => SetProperty(ref _managedMemoryMB, value);
19+
}
20+
21+
public int UserCacheCount
22+
{
23+
get => _userCacheCount;
24+
private set => SetProperty(ref _userCacheCount, value);
25+
}
26+
27+
public int PerformanceMetricsCount
28+
{
29+
get => _performanceMetricsCount;
30+
private set => SetProperty(ref _performanceMetricsCount, value);
31+
}
32+
33+
public string MemoryDisplay
34+
{
35+
get => _memoryDisplay;
36+
private set => SetProperty(ref _memoryDisplay, value);
37+
}
38+
39+
public string CacheDisplay
40+
{
41+
get => _cacheDisplay;
42+
private set => SetProperty(ref _cacheDisplay, value);
43+
}
44+
45+
public MemoryMetrics()
46+
{
47+
// Initial update
48+
UpdateMetrics();
49+
50+
// Set up timer for periodic updates (every 5 seconds)
51+
_updateTimer = new Timer(OnTimerCallback, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
52+
}
53+
54+
private void OnTimerCallback(object state)
55+
{
56+
UpdateMetrics();
57+
}
58+
59+
private void UpdateMetrics()
60+
{
61+
try
62+
{
63+
// Get memory statistics
64+
var stats = Models.MemoryManager.GetStatistics();
65+
WorkingSetMB = stats.WorkingSetMB;
66+
ManagedMemoryMB = stats.ManagedMemoryMB;
67+
68+
// Get cache counts
69+
UserCacheCount = Models.User.GetCacheSize();
70+
PerformanceMetricsCount = Models.PerformanceMonitor.GetMeasurementCount();
71+
72+
// Update display strings
73+
MemoryDisplay = $"{WorkingSetMB}/{ManagedMemoryMB} MB";
74+
CacheDisplay = $"U:{UserCacheCount} P:{PerformanceMetricsCount}";
75+
}
76+
catch
77+
{
78+
// Silently ignore errors in metrics collection
79+
MemoryDisplay = "-- MB";
80+
CacheDisplay = "--";
81+
}
82+
}
83+
84+
public void Dispose()
85+
{
86+
_updateTimer?.Dispose();
87+
_updateTimer = null;
88+
}
89+
90+
private Timer _updateTimer;
91+
private long _workingSetMB;
92+
private long _managedMemoryMB;
93+
private int _userCacheCount;
94+
private int _performanceMetricsCount;
95+
private string _memoryDisplay = "-- MB";
96+
private string _cacheDisplay = "--";
97+
}
98+
}

src/ViewModels/Repository.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ public bool IncludeUntracked
272272
}
273273
}
274274

275+
public MemoryMetrics MemoryMetrics
276+
{
277+
get => _memoryMetrics;
278+
private set => SetProperty(ref _memoryMetrics, value);
279+
}
280+
275281
public bool IsSearching
276282
{
277283
get => _isSearching;
@@ -547,6 +553,7 @@ public Repository(bool isBare, string path, string gitDir)
547553
IsBare = isBare;
548554
FullPath = path;
549555
GitDir = gitDir;
556+
MemoryMetrics = new MemoryMetrics();
550557

551558
var commonDirFile = Path.Combine(_gitDir, "commondir");
552559
_isWorktree = _gitDir.Replace('\\', '/').IndexOf("/worktrees/", StringComparison.Ordinal) > 0 &&
@@ -616,6 +623,10 @@ public void Close()
616623
{
617624
SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect
618625

626+
// Dispose of MemoryMetrics
627+
_memoryMetrics?.Dispose();
628+
_memoryMetrics = null;
629+
619630
// Clear all observable collections first to release references
620631
Logs.Clear();
621632
_branches?.Clear();
@@ -2376,6 +2387,7 @@ private void AutoFetchInBackground(object sender)
23762387
private int _localChangesCount = 0;
23772388
private int _stashesCount = 0;
23782389

2390+
private MemoryMetrics _memoryMetrics = null;
23792391
private bool _isSearching = false;
23802392
private bool _isSearchLoadingVisible = false;
23812393
private int _searchCommitFilterType = (int)Models.CommitSearchMethod.ByMessage;

src/Views/Histories.axaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
<DataGrid.Columns>
7777
<!-- Column 1: Branch/Tag -->
78-
<DataGridTemplateColumn Width="120" MinWidth="50" MaxWidth="400" IsReadOnly="True" CanUserResize="True">
78+
<DataGridTemplateColumn Width="200" MinWidth="50" MaxWidth="400" IsReadOnly="True" CanUserResize="True">
7979
<DataGridTemplateColumn.Header>
8080
<TextBlock Classes="table_header" Text="Branch/Tag" HorizontalAlignment="Center"/>
8181
</DataGridTemplateColumn.Header>
@@ -102,7 +102,7 @@
102102
</DataGridTemplateColumn>
103103

104104
<!-- Column 2: Graph -->
105-
<DataGridTemplateColumn Width="100" MinWidth="60" MaxWidth="300" IsReadOnly="True" CanUserResize="True">
105+
<DataGridTemplateColumn Width="120" MinWidth="60" MaxWidth="300" IsReadOnly="True" CanUserResize="True">
106106
<DataGridTemplateColumn.Header>
107107
<Grid ColumnDefinitions="Auto,*">
108108
<Button Grid.Column="0"
@@ -163,7 +163,7 @@
163163
</DataGridTemplateColumn.CellTemplate>
164164
</DataGridTemplateColumn>
165165

166-
<DataGridTemplateColumn MinWidth="160" CanUserResize="True" IsReadOnly="True">
166+
<DataGridTemplateColumn MinWidth="170" CanUserResize="True" IsReadOnly="True">
167167
<DataGridTemplateColumn.Width>
168168
<Binding Source="{x:Static vm:Preferences.Instance}"
169169
Path="Layout.AuthorColumnWidth"
@@ -214,7 +214,7 @@
214214
</DataGridTemplateColumn.CellTemplate>
215215
</DataGridTemplateColumn>
216216

217-
<DataGridTemplateColumn MinWidth="140" MaxWidth="300" CanUserResize="True" IsReadOnly="True">
217+
<DataGridTemplateColumn MinWidth="150" MaxWidth="300" CanUserResize="True" IsReadOnly="True">
218218
<DataGridTemplateColumn.Header>
219219
<Grid HorizontalAlignment="Center">
220220
<TextBlock Classes="table_header"

src/Views/Repository.axaml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</Grid.ColumnDefinitions>
1818

1919
<!-- Left Panel -->
20-
<Grid Grid.Column="0" RowDefinitions="Auto,*">
20+
<Grid Grid.Column="0" RowDefinitions="Auto,*,Auto">
2121
<!-- Page Switcher for Left Contents (Dashboard or CommitSearch) -->
2222
<StackPanel Grid.Row="0" Margin="0,6" Height="24" HorizontalAlignment="Center" Orientation="Horizontal">
2323
<RadioButton Classes="switch_button"
@@ -671,6 +671,45 @@
671671
HorizontalAlignment="Center" VerticalAlignment="Center"
672672
IsVisible="{Binding IsSearchLoadingVisible}"/>
673673
</Grid>
674+
675+
<!-- Memory & Cache Metrics Panel -->
676+
<Border Grid.Row="2"
677+
Background="{DynamicResource Brush.Contents}"
678+
BorderThickness="0,1,0,0"
679+
BorderBrush="{DynamicResource Brush.Border0}"
680+
Height="28">
681+
<Grid Margin="8,0" ColumnDefinitions="Auto,*,Auto">
682+
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
683+
<Path Width="10" Height="10"
684+
Data="{StaticResource Icons.Info}"
685+
Fill="{DynamicResource Brush.FG2}"
686+
Margin="0,0,4,0"/>
687+
<TextBlock Text="Memory:"
688+
FontSize="11"
689+
Foreground="{DynamicResource Brush.FG2}"
690+
VerticalAlignment="Center"/>
691+
<TextBlock Text="{Binding MemoryMetrics.MemoryDisplay}"
692+
FontSize="11"
693+
FontFamily="{DynamicResource Fonts.Monospace}"
694+
Foreground="{DynamicResource Brush.FG1}"
695+
Margin="4,0,0,0"
696+
VerticalAlignment="Center"/>
697+
</StackPanel>
698+
699+
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
700+
<TextBlock Text="Cache:"
701+
FontSize="11"
702+
Foreground="{DynamicResource Brush.FG2}"
703+
VerticalAlignment="Center"/>
704+
<TextBlock Text="{Binding MemoryMetrics.CacheDisplay}"
705+
FontSize="11"
706+
FontFamily="{DynamicResource Fonts.Monospace}"
707+
Foreground="{DynamicResource Brush.FG1}"
708+
Margin="4,0,0,0"
709+
VerticalAlignment="Center"/>
710+
</StackPanel>
711+
</Grid>
712+
</Border>
674713
</Grid>
675714

676715
<!-- Splitter -->

0 commit comments

Comments
 (0)