Skip to content

Commit c79222a

Browse files
committed
* Added ability to clear individual process working set
1 parent 8c3de38 commit c79222a

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

MemPlus/Business/PROCESS/ProcessDetail.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MemPlus.Business.PROCESS
1+
using System;
2+
3+
namespace MemPlus.Business.PROCESS
24
{
35
/// <summary>
46
/// Internal class that represents the presentable details of a Process object
@@ -21,5 +23,9 @@ internal class ProcessDetail
2123
/// The current memory usage of the Process in MB
2224
/// </summary>
2325
public string MemoryUsage { get; set; }
26+
/// <summary>
27+
/// The Handle of the process
28+
/// </summary>
29+
internal IntPtr Handle { get; set; }
2430
}
2531
}

MemPlus/Business/UTILS/Utils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ internal static List<ProcessDetail> GetProcessDetails(LogController logControlle
160160
ProcessId = p.Id,
161161
ProcessName = p.ProcessName,
162162
ProcessLocation = p.MainModule.FileName,
163-
MemoryUsage = (p.WorkingSet64 / (1024 * 1024)).ToString("F2") + " MB"
163+
MemoryUsage = (p.WorkingSet64 / (1024 * 1024)).ToString("F2") + " MB",
164+
Handle = p.Handle
164165
};
165166
processDetailsList.Add(pd);
166167
}

MemPlus/Views/Windows/ProcessAnalyzerWindow.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
<ListView x:Name="LsvProcessList" SelectionMode="Single">
2020
<ListView.ContextMenu>
2121
<ContextMenu>
22+
<MenuItem Header="Empty working set" Click="EmptyWorkingSetMenuItem_OnClick">
23+
<MenuItem.Icon>
24+
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/process.png"></Image>
25+
</MenuItem.Icon>
26+
</MenuItem>
27+
<Separator />
2228
<MenuItem Header="Copy" Click="CopyMenuItem_OnClick">
2329
<MenuItem.Icon>
2430
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/log.png" />
2531
</MenuItem.Icon>
2632
</MenuItem>
27-
<Separator />
2833
<MenuItem Header="Clear" Click="BtnClear_OnClick">
2934
<MenuItem.Icon>
3035
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/exit.png" />

MemPlus/Views/Windows/ProcessAnalyzerWindow.xaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,23 @@ private void CopyMenuItem_OnClick(object sender, RoutedEventArgs e)
151151
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
152152
}
153153
}
154+
155+
private void EmptyWorkingSetMenuItem_OnClick(object sender, RoutedEventArgs e)
156+
{
157+
if (LsvProcessList.SelectedItems.Count == 0) return;
158+
if (!(LsvProcessList.SelectedItem is ProcessDetail detail)) return;
159+
try
160+
{
161+
_logController.AddLog(new RamLog("Emptying working set for process: " + detail.ProcessName));
162+
// Empty the working set of the process
163+
NativeMethods.EmptyWorkingSet(detail.Handle);
164+
_logController.AddLog(new RamLog("Successfully emptied working set for process " + detail.ProcessName));
165+
}
166+
catch (Exception ex)
167+
{
168+
_logController.AddLog(new ApplicationLog(ex.Message));
169+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
170+
}
171+
}
154172
}
155173
}

0 commit comments

Comments
 (0)