Skip to content

Commit

Permalink
Working disk usage monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
HO-COOH committed Feb 18, 2021
1 parent 6cefa58 commit 58a3933
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
46 changes: 34 additions & 12 deletions Command1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Diagnostics;
using Microsoft.VisualBasic.Devices;
using Microsoft.VisualStudio.Debugger.Interop;
using EnvDTE;
using System.IO;

namespace ResourceMonitor
{
Expand Down Expand Up @@ -97,26 +99,44 @@ public static async Task InitializeAsync(AsyncPackage package)
Instance = new Command1(package, commandService);
}

/// <summary>
/// This function is the callback used to execute the command when the menu item is clicked.
/// See the constructor to see how the menu item is associated with this function using
/// OleMenuCommandService service and MenuCommand class.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event args.</param>

private async void DoUpdate()
private long GetSolutionSize(string path)
{
if (Directory.Exists(path))
{
var info = new DirectoryInfo(path);
long size = 0;
foreach (var fileInfo in info.EnumerateFiles("*", SearchOption.AllDirectories))
{
Console.WriteLine($"{fileInfo.FullName} -> {fileInfo.Length}");
size += fileInfo.Length;
}
return size;
}
else
return 0;
}

private async Task DoUpdate()
{
while (true)
{
//await JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken);
var statusBar = await ServiceProvider.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar;
int frozen;

statusBar.IsFrozen(out frozen);
if (frozen != 0)
statusBar.FreezeOutput(0);
var mem = GetRamUsage();
statusBar.SetText($"CPU: {GetCpuUsage()} % RAM: {mem} MB / {(float)memtotal/1024.0:0.#} GB ({(float)mem/memtotal *100 :##} %)");

var env = await ServiceProvider.GetServiceAsync(typeof(SDTE)) as DTE;
var solution = env.Solution;
var solutionFile = solution.FullName;
var solutionDir = new FileInfo(solutionFile).Directory;
var size = GetSolutionSize(solutionDir.FullName) / 1024 / 1024;


statusBar.SetText($"CPU: {GetCpuUsage()} % RAM: {mem} MB / {(float)memtotal/1024.0:0.#} GB ({(float)mem/memtotal *100 :##} %) Disk: {size} MB");
System.Threading.Thread.Sleep(1000);
}
}
Expand All @@ -125,8 +145,10 @@ private async void Execute(object sender, EventArgs e)
var info = new Microsoft.VisualBasic.Devices.ComputerInfo();
memtotal = (int)(info.TotalPhysicalMemory / 1024 / 1024);

Thread update = new Thread(DoUpdate);
update.Start();


await Task.Run(() => DoUpdate());

}
}
}
3 changes: 3 additions & 0 deletions ResourceMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.205" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.6.2051" />
<PackageReference Include="OpenHardwareMonitor">
<Version>0.7.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<VSCTCompile Include="ResourceMonitorPackage.vsct">
Expand Down

0 comments on commit 58a3933

Please sign in to comment.