Commit 9505e50a authored by shrabbit's avatar shrabbit
Browse files

Add GC and memory commands for manual garbage collection and memory usage display

parent fc4bb14e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
using System.Reflection;
using Spectre.Console;
using TestV.Tools;

namespace TestV;

@@ -104,6 +105,20 @@ public class PlaygroundLauncher(Action onReload)
                    onReload();
                    return;

                case "gc":
                    AnsiConsole.WriteLine("Please wait for GC completed...");
                    GC.Collect(2, GCCollectionMode.Forced, true);
                    
                    GC.WaitForPendingFinalizers();
                    
                    GC.Collect(2, GCCollectionMode.Forced, true);
                    AnsiConsole.MarkupLine("[green]Done!\n[/]");
                    break;

                case "mem":
                    AnsiConsole.WriteLine(new Storage(GC.GetTotalMemory(false)).ToString() + '\n');
                    break;
                
                default:
                    HandleCommand(input);
                    break;
@@ -233,6 +248,8 @@ public class PlaygroundLauncher(Action onReload)
        AnsiConsole.MarkupLine("[yellow]reload [[Command]][/]: 重载 Playground 实例");
        AnsiConsole.MarkupLine("[yellow]info [[Command]][/]: 打印所选 Playground 的所有信息表格");
        AnsiConsole.MarkupLine("[yellow]ver[/]: 打印 TestV 版本");
        AnsiConsole.MarkupLine("[yellow]gc[/]: 执行一次垃圾回收");
        AnsiConsole.MarkupLine("[yellow]mem[/]: 获取当前程序的 .NET 堆内存占用(自动单位)");
        AnsiConsole.MarkupLine("[yellow]list[/]: 列举所有 Playground\n");
    }