简体   繁体   English

PowerShell - 如何从 PowerShell 获得我的 exe 程序的内存消耗峰值

[英]PowerShell - how can I get memory consumption peak for my exe program from PowerShell

I have a program which allocates memory.我有一个分配内存的程序。 I am running it from Windows PowerShell command line.我从 Windows PowerShell 命令行运行它。 It can run for 1-2 hours allocating and releasing memory blocks.它可以运行 1-2 个小时来分配和释放内存块。

What I am looking for is a way to get at the end (when the program finishes) some memory consumption statistics.我正在寻找的是一种在最后(程序完成时)获得一些内存消耗统计信息的方法。 More specifically, what was the peak usage of the memory (max memory allocated).更具体地说,内存的峰值使用量是多少(分配的最大内存)。

Get-Process -Id xxx gives you the Process object instance of the process with ID xxx. Get-Process -Id xxx为您提供 ID 为 xxx 的进程的Process对象实例。 There are all kinds of memory-related properties in there, including things like PeakVirtualMemorySize64 and PeakWorkingSet64 .那里有各种与内存相关的属性,包括PeakVirtualMemorySize64PeakWorkingSet64类的东西。 Pick the ones you find useful.选择你觉得有用的那些。

You can even set up a background job to get a data series, something like您甚至可以设置后台作业来获取数据系列,例如

$proc = Start-Process "your_long_running.exe" -PassThru

$memoryWatcher = Start-Job -ScriptBlock {
    while ($true) {
        Get-Process -Id $args[0] | Select VirtualMemorySize64,PeakVirtualMemorySize64
        Start-Sleep -Seconds 1
    }
} -ArgumentList $proc.Id

# now wait for the process to end
Wait-Process -Id $proc.Id
    
$memoryWatcher.StopJob()
$results = Receive-Job $memoryWatcher

$results | Format-Table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM