如何降低Visual Studio构建过程的优先级以防止系统无响应? [英] How to reduce Visual Studio build process priority to prevent unresponsive system?

查看:219
本文介绍了如何降低Visual Studio构建过程的优先级以防止系统无响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将定期使用Visual Studio(2013)编译大型C ++项目.在开发人员机器上构建源代码最多需要45分钟. 在此期间,由于100%CPU负载,计算机通常变得无响应. 有没有办法告诉Visual Studio以较低的进程优先级运行编译/生成工具,从而不会降低Windows UI的速度? 如果我可以同时做其他事情,我很乐意让机器在构建过程上花费更多的时间.

We are compiling big C++ projects using Visual Studio (2013) on a regular basis. Building the source can take up to 45 mins on a developer machine. During this time, the machine often becomes unresponsive due to 100% CPU load. Is there any way to tell Visual Studio to run the compile/build tools with a lower process priority so that the Windows UI isn't slowed down? I'd happily have the machine spend a bit more time overall on the build process if i could do other things meanwhile.

自安装SSD以来,问题甚至变得更加令人讨厌! 尽管总体构建时间得到了显着改善,但由于现在不再存在磁盘瓶颈,因此构建过程甚至更频繁地遇到CPU最大负载,从而导致系统无响应.

The problem has even become more annoying since installing an SSD! Although the overall build time is significantly improved, now that there is no more disk bottleneck, the build process runs into CPU max load even more often, with an unresponsive system as a consequence.

如何解决此问题?

推荐答案

更新

我刚刚找到以下线程,其中一个叫Mikhail Virovets的人提供了自动解决方案:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\cl.exe\PerfOptions下的注册表中,创建一个名为CpuPriorityClassDWORD值并将其设置为5.这会将具有该名称的 all 新创建进程的基本优先级设置为below normal.您可能还应该为链接器创建一个类似的条目.

In the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\cl.exe\PerfOptions, create a DWORD value called CpuPriorityClass and set it to 5. This will set the base priority of all newly created processes with that name to below normal. You should probably also create a similar entry for the linker.

当然,这更具侵入性,因为它将影响具有这些名称的所有进程,无论在何处,何时以及如何创建它们.但是我认为这可能会很好.

Of course this is a little bit more invasive as it will affect all processes with those names, regardless of where, when and how they are created. But I think it will probably work fine.

别忘了您添加了这些值,以防将来导致某些不必要的变慢,否则您可能会长期寻找该问题.

Just don't forget you have added those values in case it causes some unwanted slowdowns in the future, otherwise you may be looking for the problem for a long time.

您可以使用以下.reg文件将编译器和链接器的CPU和IO优先级设置为低于正常"/低于":

You can use the following .reg file to set the CPU and IO priority of the compiler and linker to "below normal"/"low":

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\cl.exe]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\cl.exe\PerfOptions]
"CpuPriorityClass"=dword:00000005
"IoPriority"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\link.exe]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\link.exe\PerfOptions]
"CpuPriorityClass"=dword:00000005
"IoPriority"=dword:00000001


原始答案

我正面临着同样的问题,这确实使我很烦.作为权宜之计,我创建了一个小的批处理文件,该文件只是降低了最重要的构建工具的处理优先级:


Original Answer

I was facing the same problem and it really annoyed me. As a stop gap solution, I have created a small batch file that simply lowers the process priority of the most important build tools:

wmic process where name="msbuild.exe" CALL setpriority "idle"
wmic process where name="cl.exe" CALL setpriority "idle"
wmic process where name="link.exe" CALL setpriority "idle"

(这是用于C ++构建的,如果您构建其他内容,则可能需要将.exe名称更改为您的主要构建工具.)

(This is for C++ builds, if you build something else you may want to change the .exe names to whatever your main build tools are.)

当然,这只会影响当前正在运行的进程,因此您必须在每次开始构建时都运行它.不过,新创建的子过程(编译器,链接器等)的优先级是从MSBuild主过程继承的,因此这不仅会影响当前正在运行的编译器/链接器实例,还会影响整个构建.

Of course this only affects processes that are currently running, so you have to run it every time you start a build. The priorities of newly created sub-processes (compiler, linker, ...) are being inherited from the main MSBuild process though, so this will not only affect the currently running compiler/linker instances but the whole build.

我在Command: cmd.exeArguments: /c C:\Path\To\My\LowerBuildPriority.bat中添加了一个外部工具"条目,因此可以从Visual Studio中启动批处理文件.

I've added an "external tool" entry with Command: cmd.exe and Arguments: /c C:\Path\To\My\LowerBuildPriority.bat so I can start the batch file from within Visual Studio.

一个更方便的解决方案可能是向构建中添加自定义任务,以更改流程优先级.由于AFAIK任务是从MSBuild主过程中执行的,因此应该可以正常工作.但是我还没有尝试一下.

A more convenient solution would probably be to add a custom task to the build that alters the process priority. Since AFAIK tasks are executed from within the main MSBuild process, this should work. But I haven't gotten around to trying it yet.

这篇关于如何降低Visual Studio构建过程的优先级以防止系统无响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆