Skip to content

Commit

Permalink
chore: Add powershell process (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia authored Oct 9, 2024
1 parent a83d74e commit cef2e0c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
39 changes: 37 additions & 2 deletions DCL_PiXYZ/PXZEntryPoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using CommandLine;
using DCL_PiXYZ.Utils;
Expand All @@ -17,9 +18,43 @@ private static async Task RunLODGeneration(PXZEntryArgs obj)
{
PXZClient pxzClient = new PXZClient();
FileWriter.currentScene = obj.SceneToConvert;
FileWriter.PrintDriveSize("ON START PROCESS");
FileWriter.WriteToConsole("PROCESS START");
FileWriter.PrintDriveSize();
RunTopCPUProcessesScript();
await pxzClient.RunLODBuilder(obj);
FileWriter.PrintDriveSize("ON END PROCESS");
FileWriter.WriteToConsole("PROCESS END");
FileWriter.PrintDriveSize();
RunTopCPUProcessesScript();
}

private static void RunTopCPUProcessesScript()
{
// Define the PowerShell script to run
string script = @"
$topCount = 10;
Get-Process | Sort-Object CPU -Descending | Select-Object -First $topCount -Property Id, ProcessName, CPU, StartTime | Format-Table -AutoSize
";

// Start the PowerShell process
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "powershell",
Arguments = $"-Command \"{script}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};

using (Process process = Process.Start(psi))
{
// Read and display the output
using (System.IO.StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
FileWriter.WriteToConsole("Top 10 CPU-consuming processes:");
FileWriter.WriteToConsole(result);
}
}
}

public static void CloseApplication(string errorMessage)
Expand Down
4 changes: 2 additions & 2 deletions DCL_PiXYZ/Utils/FileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public static void WriteToConsole(string message)
}


public static void PrintDriveSize(string message)
public static void PrintDriveSize()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if(d.IsReady)
WriteToConsole($"{message} Drive {d.Name} - Total: {ConvertToGB(d.TotalSize)} GB, Available: {ConvertToGB(d.AvailableFreeSpace)} GB, Free: {ConvertToGB(d.TotalFreeSpace)} GB");
WriteToConsole($"Drive {d.Name} - Total: {ConvertToGB(d.TotalSize)} GB, Available: {ConvertToGB(d.AvailableFreeSpace)} GB, Free: {ConvertToGB(d.TotalFreeSpace)} GB");
}
}

Expand Down

0 comments on commit cef2e0c

Please sign in to comment.