Android studio在任何时候都使用> 100%的CPU——没有后台进程正在运行。

时间:2022-11-06 20:51:52

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). I might suspect this were something specific to my box, but some fellow developers are encountering this as well.

我注意到Android Studio(在运行时)一直使用超过100%的CPU,即使它出现时没有IDE正在运行的后台进程(索引等)。我可能会怀疑这是我的工具箱中特定的东西,但是一些开发人员也遇到了这个问题。

Often times the CPU usage is in the high 100s or mid 200s (see screenshots below). 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?

通常情况下,CPU的使用率是在高100s或mid - 200s(见下面的屏幕截图)。有人也遇到过这种情况吗?如果是的话,IDE中有什么策略或选项来纠正系统资源的密集使用吗?

Android studio在任何时候都使用> 100%的CPU——没有后台进程正在运行。

Android studio在任何时候都使用> 100%的CPU——没有后台进程正在运行。

11 个解决方案

#1


36  

You can try the following options in the File Menu:

您可以在文件菜单中尝试以下选项:

  1. Enable "Power Save Mode"
  2. 启用“省电模式”
  3. File Menu -> Invalidate Caches / Restart... -> Invalidate and Restart
  4. 文件菜单->无效缓存/重新启动…- >无效并重启

#2


26  

You might consider going to File > Invalidate Caches / Restart Your cache might be kicking off something funky in the background

您可以考虑将>无效缓存文件/重新启动缓存可能会在后台启动一些奇怪的东西

Android studio在任何时候都使用> 100%的CPU——没有后台进程正在运行。

#3


8  

I encountered a constant high cpu usage with no apparent reason. Invalidating cache did not work nor did the power save mode.

我遇到了持续的高cpu使用率,没有明显的原因。无效缓存不起作用,电源保存模式也不起作用。

In my case there was a something wrong in the '.git' directory which was causing android studio to fail in an endless loop. Checking out the repo again fixed the problem.

在我的情况下,有什么问题。git目录,导致android studio在循环中失败。再次检查repo解决了问题。

My advice is to check the android studio logs for any hints to what is causing it to falter. You could also start it from terminal and check the Stdout/Stderr output.

我的建议是,查看android studio日志,寻找导致它出现问题的任何线索。您还可以从终端启动它并检查Stdout/Stderr输出。

#4


7  

Thanks to Buzzrick (answered on this page, probably above my answer), he mentioned about CVS. 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.

多亏了Buzzrick(在这个页面上回答,可能在我的答案之上),他提到了CVS。关掉风投的所有后台操作似乎对高cpu使用率产生了巨大的影响——它是150%,现在是20%,或多或少。

I'm on OS X

我在OS X

Go to: Preferences > Version Control > Background. Now listed under 'Background Operations' are 6 options. I disabled the first three options which are:

转到:Preferences >版本控制>背景。现在在“后台操作”下面列出了6个选项。我取消了前三个选项:

Perform update on VCS in background, Perform commit to VCS in background, Perform checkout to VCS in background.

在后台执行对VCS的更新,在后台执行对VCS的提交,在后台执行对VCS的校验。

#5


3  

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". After that it ran smoothly without pulling CPU

我通过重新加载我的android studio项目来解决这个问题,当它询问我的CVS链接(我不记得确切的措辞)时,我只说了“忽略”。在那之后,它平稳地运行,没有拉动CPU

#6


2  

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. 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. Apparently once I increased this, I am able to switch off power save and have my Android Studio work perfectly.

我在Android Studio 1.0中打开了电源保存功能,这很有帮助,但这意味着我选择了Android Studio必须提供的很多功能。因此我寻求更好的解决方案,我碰巧总是弹出一个对话框,并要求我增加VM的大小。显然,一旦我增加了这个功能,我就可以关掉省电功能,让我的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操作系统上,转到/应用/Android\ Studio.app/内容/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上,转到环境变量并找到一个名为_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指定初始内存分配池。

i.e 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数量的内存。

#7


2  

On Windows I reduced the studio64.exe process priority and set the process' affinity to half of the cores. Open Task Manager, click on Processes tab, right click on process studio64.exe and you'll see it in the menu.

在Windows上我减少了studio64。exe进程优先级,并将进程的关联性设置为一半核心。打开任务管理器,单击process选项卡,右键单击process studio64。你会在菜单上看到的。

#8


1  

I had exact same problem on Linux. Solved by increasing the memory size.

我在Linux上遇到了同样的问题。通过增加内存大小来解决。

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. 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)". All three of them. apparently JVM is too busy doing GC all the time.

首先看看顶部的-p -H,它显示了哪些线程正在使用大部分CPU,对我来说有三个线程:94232、94233、94234。然后我执行jstack 获取android studio的堆栈转储,并查找0x17018(=94232),结果是“Gang worker#0 (Parallel CMD Threads)”。所有三个。显然JVM总是忙于做GC。

Also opened jconsole against my android studio process and it shows GC time "20 minutes"!!! (at the bottom of memory tab)

也在我的android studio进程中打开jconsole,它显示GC时间“20分钟”!!!(在记忆标签的底部)

Fix is to change the studio.vmoptions (or studio64.vmoptions in my case), to increase the -Xmx value from default 750m to 1500m. It is sufficient for me. if you have too much memory, set to 2g or 4g or 16g..

Fix就是更改studio。vmoptions(或studio64。在我的例子中,将-Xmx值从默认的7.5 m增加到1500m。对我来说足够了。如果内存太多,设置为2g或4g或16g..

#9


1  

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.
  2. 减少Android虚拟设备的数量和内存。
  3. Invalidate Caches/Restart
  4. 缓存失效/重启
  5. Go to Power Save Mode
  6. 进入电源保存模式
  7. Close all unnecessary files that are opened.
  8. 关闭打开的所有不必要的文件。
  9. Reduce your VM Heap Size to around 256.
  10. 将VM堆大小减少到大约256。

#10


0  

In my case I have white-listed Android-Studio's folder in "Eset Smart Security" and the problem solved!

在我的案例中,我在“Eset智能安全”中有一个Android-Studio的白名单文件夹,问题解决了!

hope this helps!

希望这可以帮助!

#11


0  

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连接三星手机到你的电脑时,也会发生这种情况,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,这个错误不会发生。

#1


36  

You can try the following options in the File Menu:

您可以在文件菜单中尝试以下选项:

  1. Enable "Power Save Mode"
  2. 启用“省电模式”
  3. File Menu -> Invalidate Caches / Restart... -> Invalidate and Restart
  4. 文件菜单->无效缓存/重新启动…- >无效并重启

#2


26  

You might consider going to File > Invalidate Caches / Restart Your cache might be kicking off something funky in the background

您可以考虑将>无效缓存文件/重新启动缓存可能会在后台启动一些奇怪的东西

Android studio在任何时候都使用> 100%的CPU——没有后台进程正在运行。

#3


8  

I encountered a constant high cpu usage with no apparent reason. Invalidating cache did not work nor did the power save mode.

我遇到了持续的高cpu使用率,没有明显的原因。无效缓存不起作用,电源保存模式也不起作用。

In my case there was a something wrong in the '.git' directory which was causing android studio to fail in an endless loop. Checking out the repo again fixed the problem.

在我的情况下,有什么问题。git目录,导致android studio在循环中失败。再次检查repo解决了问题。

My advice is to check the android studio logs for any hints to what is causing it to falter. You could also start it from terminal and check the Stdout/Stderr output.

我的建议是,查看android studio日志,寻找导致它出现问题的任何线索。您还可以从终端启动它并检查Stdout/Stderr输出。

#4


7  

Thanks to Buzzrick (answered on this page, probably above my answer), he mentioned about CVS. 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.

多亏了Buzzrick(在这个页面上回答,可能在我的答案之上),他提到了CVS。关掉风投的所有后台操作似乎对高cpu使用率产生了巨大的影响——它是150%,现在是20%,或多或少。

I'm on OS X

我在OS X

Go to: Preferences > Version Control > Background. Now listed under 'Background Operations' are 6 options. I disabled the first three options which are:

转到:Preferences >版本控制>背景。现在在“后台操作”下面列出了6个选项。我取消了前三个选项:

Perform update on VCS in background, Perform commit to VCS in background, Perform checkout to VCS in background.

在后台执行对VCS的更新,在后台执行对VCS的提交,在后台执行对VCS的校验。

#5


3  

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". After that it ran smoothly without pulling CPU

我通过重新加载我的android studio项目来解决这个问题,当它询问我的CVS链接(我不记得确切的措辞)时,我只说了“忽略”。在那之后,它平稳地运行,没有拉动CPU

#6


2  

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. 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. Apparently once I increased this, I am able to switch off power save and have my Android Studio work perfectly.

我在Android Studio 1.0中打开了电源保存功能,这很有帮助,但这意味着我选择了Android Studio必须提供的很多功能。因此我寻求更好的解决方案,我碰巧总是弹出一个对话框,并要求我增加VM的大小。显然,一旦我增加了这个功能,我就可以关掉省电功能,让我的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操作系统上,转到/应用/Android\ Studio.app/内容/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上,转到环境变量并找到一个名为_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指定初始内存分配池。

i.e 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数量的内存。

#7


2  

On Windows I reduced the studio64.exe process priority and set the process' affinity to half of the cores. Open Task Manager, click on Processes tab, right click on process studio64.exe and you'll see it in the menu.

在Windows上我减少了studio64。exe进程优先级,并将进程的关联性设置为一半核心。打开任务管理器,单击process选项卡,右键单击process studio64。你会在菜单上看到的。

#8


1  

I had exact same problem on Linux. Solved by increasing the memory size.

我在Linux上遇到了同样的问题。通过增加内存大小来解决。

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. 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)". All three of them. apparently JVM is too busy doing GC all the time.

首先看看顶部的-p -H,它显示了哪些线程正在使用大部分CPU,对我来说有三个线程:94232、94233、94234。然后我执行jstack 获取android studio的堆栈转储,并查找0x17018(=94232),结果是“Gang worker#0 (Parallel CMD Threads)”。所有三个。显然JVM总是忙于做GC。

Also opened jconsole against my android studio process and it shows GC time "20 minutes"!!! (at the bottom of memory tab)

也在我的android studio进程中打开jconsole,它显示GC时间“20分钟”!!!(在记忆标签的底部)

Fix is to change the studio.vmoptions (or studio64.vmoptions in my case), to increase the -Xmx value from default 750m to 1500m. It is sufficient for me. if you have too much memory, set to 2g or 4g or 16g..

Fix就是更改studio。vmoptions(或studio64。在我的例子中,将-Xmx值从默认的7.5 m增加到1500m。对我来说足够了。如果内存太多,设置为2g或4g或16g..

#9


1  

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.
  2. 减少Android虚拟设备的数量和内存。
  3. Invalidate Caches/Restart
  4. 缓存失效/重启
  5. Go to Power Save Mode
  6. 进入电源保存模式
  7. Close all unnecessary files that are opened.
  8. 关闭打开的所有不必要的文件。
  9. Reduce your VM Heap Size to around 256.
  10. 将VM堆大小减少到大约256。

#10


0  

In my case I have white-listed Android-Studio's folder in "Eset Smart Security" and the problem solved!

在我的案例中,我在“Eset智能安全”中有一个Android-Studio的白名单文件夹,问题解决了!

hope this helps!

希望这可以帮助!

#11


0  

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连接三星手机到你的电脑时,也会发生这种情况,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,这个错误不会发生。