简体   繁体   English

Android工作室始终使用> 100%的CPU - 没有后台进程似乎正在运行

[英]Android studio using > 100% CPU at all times - no background processes appear to be running

I've noticed Android Studio (when running) uses greater than 100% CPU at all times, even when it appears there are no background processes that the IDE is running (indexing, etc). 我注意到Android Studio(运行时)始终使用超过100%的CPU,即使看起来没有IDE正在运行的后台进程(索引等)。 I might suspect this were something specific to my box, but some fellow developers are encountering this as well. 我可能怀疑这是我的盒子特有的东西,但是一些开发人员也遇到了这个问题。

Often times the CPU usage is in the high 100s or mid 200s (see screenshots below). 通常,CPU使用率处于高100或200年代中期(参见下面的屏幕截图)。 Has anyone encountered this as well? 有没有人遇到过这个? If so, are there any strategies or options within the IDE to correct this intensive use of system resources? 如果是这样,IDE中是否有任何策略或选项来纠正系统资源的这种密集使用?

在此输入图像描述

在此输入图像描述

You can try the following options in the File Menu: 您可以在“文件”菜单中尝试以下选项:

  1. File Menu -> Invalidate Caches / Restart... -> Invalidate and Restart 文件菜单 - >使高速缓存/重新启动无效... - >无效并重新启动
  2. Enable Power Save Mode by clicking on File -> Power Save Mode 单击文件 - >省电模式启用省电模式

Power Save mode only disable code insights and background tasks. 省电模式仅禁用代码洞察和后台任务。

You might consider going to File > Invalidate Caches / Restart Your cache might be kicking off something funky in the background 您可以考虑转到文件>无效缓存/重新启动您的缓存可能会在后台启动一些时髦的东西

在此输入图像描述

Thanks to Buzzrick (answered on this page, probably above my answer), he mentioned about VCS. 感谢Buzzrick (在本页回答,可能在我的回答之上),他提到了VCS。 Turning off all of the background operations of VCS seemed to have a HUGE impact toward the high cpu usage - it was 150% and now it's 20%, more or less. 关闭VCS的所有后台操作似乎对高CPU使用率产生巨大影响 - 它是150%,现在是20%,或多或少。

I'm on OS X 我在OS X上

Go to: Preferences > Version Control > Background. 转至:首选项>版本控制>背景。 Now listed under 'Background Operations' are 6 options. 现在列在“后台操作”下的是6个选项。 I disabled the first three options which are: 我禁用了前三个选项:

Perform update on VCS in background, Perform commit to VCS in background, Perform checkout to VCS in background. 在后台执行VCS更新,在后台执行提交到VCS,在后台执行到VCS的签出。

I encountered a constant high cpu usage with no apparent reason. 我没有明显的理由遇到了持续的高CPU使用率。 Invalidating cache did not work nor did the power save mode. 无效缓存不起作用,也没有省电模式。

In my case there was a something wrong in the '.git' directory which was causing android studio to fail in an endless loop. 在我的情况下,'。git'目录中有一个错误导致android studio在无限循环中失败。 Checking out the repo again fixed the problem. 再次签出回购修复了问题。

My advice is to check the android studio logs for any hints to what is causing it to falter. 我的建议是检查android studio日志中是否有任何提示导致它失败的原因。 You could also start it from terminal and check the Stdout/Stderr output. 您也可以从终端启动它并检查Stdout / Stderr输出。

I switched on power save in Android Studio 1.0 it helped but this meant I opted out on so many features that Android Studio has to offer. 我在Android Studio 1.0中启用了省电,但这意味着我选择了Android Studio提供的众多功能。 Thus I sought to find a better solution, I happened to always have a dialog box pop up and ask me to increase my VM size. 因此,我试图找到一个更好的解决方案,我碰巧弹出一个对话框,并要求我增加我的VM大小。 Apparently once I increased this, I am able to switch off power save and have my Android Studio work perfectly. 显然,一旦我增加了这个,我就可以关闭省电并让我的Android Studio完美运行。

This is how to do so: On Mac OS go to /Applications/Android\\ Studio.app/Contents/bin/studio.vmoptions (To open contents right click on Android Studio app > View contents) You will find the following variables 这是如何做到的:在Mac OS上转至/Applications/Android\\ Studio.app/Contents/bin/studio.vmoptions (打开内容右键单击Android Studio app>查看内容)您将找到以下变量

-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops

On Windows go to Environment Variables and find a System Variable called _JAVA_OPTIONS 在Windows上转到Environment Variables并找到名为_JAVA_OPTIONS的系统变量

Increase these figures accordingly. 相应地增加这些数字。

  • Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM). Xmx指定Java虚拟机(JVM)的最大内存分配池。
  • Xms specifies the initial memory allocation pool. Xms指定初始内存分配池。

ie Your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. 即你的JVM将以Xms的内存量启动,并且能够使用最大的Xmx内存量。

I had exact same problem on Linux. 我在Linux上遇到了同样的问题。 Solved by increasing the memory size. 通过增加内存大小解决。

Started by looking at the top -p <android studio pid> -H which shows which threads are using most of CPU, to me there are three threads: 94232,94233,94234. 通过查看top -p <android studio pid> -H显示哪些线程正在使用大部分CPU,对我来说有三个线程:94232,94233,94234。 Then I do a jstack <pid> to get the stack dump of android studio, and look for 0x17018 (=94232), it turns out to be "Gang worker#0 (Parallel CMD Threads)" . 然后我做一个jstack <pid>来获取android studio的堆栈转储,并寻找0x17018(= 94232),结果是"Gang worker#0 (Parallel CMD Threads)" All three of them. 他们三个。 apparently JVM is too busy doing GC all the time. 显然JVM一直忙着做GC。

Also opened jconsole against my android studio process and it shows GC time " 20 minutes "!!! 还打开jconsole对我的android工作室进程,它显示GC时间“ 20 minutes ”! (at the bottom of memory tab) (在内存标签的底部)

Fix is to change the studio.vmoptions (or studio64.vmoptions in my case), to increase the -Xmx value from default 750m to 1500m. 修复是更改studio.vmoptions(或我的情况下为studio64.vmoptions),将-Xmx值从默认值750m增加到1500m。 It is sufficient for me. 这对我来说已经足够了。 if you have too much memory, set to 2g or 4g or 16g.. 如果你有太多的记忆,设置为2克或4克或16克..

Interestingly, for me this seemed to be something to do with the version control integration. 有趣的是,对我而言,这似乎与版本控制集成有关。

I fixed this by re-loading my android studio project and when it asked about wiring up my CVS links (I don't recall the exact wording), I just said "Ignore". 我通过重新加载我的android工作室项目来解决这个问题,当它询问有关连接我的CVS链接时(我不记得确切的措辞),我只是说“忽略”。 After that it ran smoothly without pulling CPU 之后它运行顺利而不会拉CPU

I tried the following procedure and Android Studio on my Surface Pro 3 sped up by an insane amount: 我尝试了以下程序,我的Surface Pro 3上的Android Studio增加了疯狂的数量:

  1. Reduce the amount and memory of the Android Virtual Devices you have. 减少您拥有的Android Virtual Devicesamountmemory
  2. Invalidate Caches/Restart
  3. Go to Power Save Mode 进入Power Save模式
  4. Close all unnecessary files that are opened . 关闭所有unnecessary files that are opened
  5. Reduce your VM Heap Size to around 256 . VM Heap Size减少到256左右。

On Windows I reduced the studio64.exe process priority and set the process' affinity to half of the cores. 在Windows上,我减少了studio64.exe进程优先级,并将进程的亲和性设置为一半的核心。 Open Task Manager, click on Processes tab, right click on process studio64.exe and you'll see it in the menu. 打开任务管理器,单击进程选项卡,右键单击process studio64.exe,您将在菜单中看到它。

In my case I have white-listed Android-Studio's folder in "Eset Smart Security" and the problem solved! 在我的情况下,我在"Eset Smart Security" white-listed Android-Studio文件夹,问题解决了!

hope this helps! 希望这可以帮助!

Edit: 编辑:

Disabling HIPS in Eset settings was also helpful in my situation! Eset settings禁用HIPS也有助于我的情况!

On Android Studio 2.3, this happens when the "Android Monitor" window is open (the window shows Logcat messages from devices and emulators), and then you press Ctrl+F ( Cmd+F on the Mac) to reveal the 'Find' search bar inside this window . 在Android Studio 2.3上,当“Android Monitor”窗口打开时(窗口显示来自设备和模拟器的Logcat消息),然后按Ctrl + F (Mac上的Cmd + F显示“查找”搜索这个窗口里面的吧

It can also happen when you connect a Samsung phone to your computer via USB, which has Developer Mode enabled, because Samsung phones usually send out large amounts of debug text to Logcat every second, even if the Logcat window is closed. 当您通过启用了开发者模式的USB将三星手机连接到计算机时也会发生这种情况,因为三星手机通常会每秒向Logcat发送大量调试文本,即使Logcat窗口已关闭。

So the solutions to prevent the 100% CPU usage are: 因此,防止100%CPU使用的解决方案是:

Turn off the Find search bar, or hide the window completely. 关闭“查找”搜索栏,或完全隐藏窗口。

or 要么

Disconnect a Samsung phone which is sending out lots of debug messages. 断开发送大量调试信息的三星手机。

or 要么

Upgrade to Android Studio 3, where this bug doesn't happen. 升级到Android Studio 3,不会发生此错误。

I've left this question open for awhile as coworkers and posters here have found value in various solutions over time. 我已经暂时搁置了这个问题,因为随着时间的推移,这里的同事和海报已经在各种解决方案中找到了价值。 For myself, simply updating Android Studio solved the issue (after a number of months where none of the solutions herein worked for me). 对我自己来说,简单地更新Android Studio就解决了这个问题(经过几个月的努力,这里没有任何解决方案适用于我)。

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

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