Xcode 4.3.2 和 100% CPU 在空闲时间不断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10522936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:15:14  来源:igfitidea点击:

Xcode 4.3.2 and 100% CPU constantly in the idle time

xcodeperformancecpuxcode4.3

提问by Lukasz

My Xcode started to behave very heavily from yesterday when working on medium size project (around 200 source files). Project compiles correctly and runs in both simulator and device. I do not use any 3rd party libraries, except few widely used includes (like JSON or facebook ios sdk).

从昨天开始,我的 Xcode 在处理中等大小的项目(大约 200 个源文件)时开始表现得很严重。项目正确编译并在模拟器和设备中运行。我不使用任何 3rd 方库,除了少数广泛使用的包含(如 JSON 或 facebook ios sdk)。

It constantly uses CPU(s) at full speed, even if it is in idle state (no indexing, no compiling, no editing). The usage of RAM is relatively normal (300-50MB).

它始终以全速使用 CPU,即使它处于空闲状态(无索引、无编译、无编辑)。RAM的使用比较正常(300-50MB)。

My machine uses: Core 2 Duo 3.04Ghz CPU, 8GB of RAM and Vertex OCZ 3 SSD drive.

我的机器使用:Core 2 Duo 3.04Ghz CPU、8GB 内存和 Vertex OCZ 3 SSD 驱动器。

I have tried every suggested solution found at stackoverflow:

我已经尝试了在 stackoverflow 上找到的所有建议的解决方案:

  1. Cleaned project
  2. Cleaned Derived Data in Organizer
  3. Cleaned repositories in Organizer
  4. Cleaned xcodeproject bundle from workspace and userdata files as suggested here: https://stackoverflow.com/a/8165886/229229(it is helping just for a moment and starts again after minute or so).
  5. Restarted Xcode many times (with the same effect as in 4).
  6. Disabled "Live issues"
  7. even Reinstalled Xcode
  1. 清理项目
  2. 清理管理器中的派生数据
  3. 清理管理器中的存储库
  4. 按照此处的建议从工作区和用户数据文件中清除 xcodeproject 包:https: //stackoverflow.com/a/8165886/229229(它只是暂时帮助并在大约一分钟后重新开始)。
  5. 多次重启Xcode(效果同4)。
  6. 禁用“实时问题”
  7. 甚至重新安装了Xcode

Nothing helps. In most cases, Xcode indexes the project for a moment, then comes back to the normal performance, but after a while becomes unusable again. CPU jumps back to 95-100% for both cores, intelligence hangs, etc...

没有任何帮助。在大多数情况下,Xcode 会暂时为项目建立索引,然后恢复正常性能,但一段时间后又无法使用。两个内核的 CPU 都跳回到 95-100%,智能挂起等......

I am attaching screenshots of how the Xcode processes are seen by the Instruments:

我附上了仪器如何看待 Xcode 进程的屏幕截图:

enter image description hereenter image description hereenter image description hereenter image description hereenter image description here

在此处输入图片说明在此处输入图片说明在此处输入图片说明在此处输入图片说明在此处输入图片说明

UPDATE:After a moment of hope that I solved the problem by moving around few

更新:经过一段时间的希望后,我通过移动几个来解决问题

#import "header.h"

#import "header.h"

statements from headers to the implementation files and exchanging them with forward declarations ... the problem came back again after a while. I am adding the console log. The strange thing is that the logs related to Xcode show up after I quit it, not during the run itsef.

从头文件到实现文件的语句,并用前向声明交换它们……一段时间后问题又回来了。我正在添加控制台日志。奇怪的是,Xcode 相关的日志在我退出后才出现,而不是在运行期间。

Console logs:

控制台日志:

5/11/12 9:27:03.777 AM [0x0-0x45045].com.apple.dt.Xcode: com.apple.dt.instruments.backgroundinstruments: Already loaded
5/11/12 9:27:05.571 AM Xcode: Performance: Please update this scripting addition to supply a value for ThreadSafe for each event handler: "/Library/ScriptingAdditions/SIMBL.osax"
5/11/12 9:27:58.168 AM Xcode: ERROR: Failed to create an alert for ID "enabled" based on defaults: 1

采纳答案by Lukasz

What stopped my nightmare was:

阻止我做噩梦的是:

  1. Change Always Search User Path to NO in Project build settings (bolded).
  2. Remove -objC flag Other Linker Flags (also bolded setting).
  1. 在项目构建设置(粗体)中将“始终搜索用户路径”更改为“否”。
  2. 删除 -objC 标志其他链接器标志(也是粗体设置)。

And then delete Derived Data and wait until Xcode reindexes.

然后删除派生数据并等待 Xcode 重新索引。

I am not sure which of them helped bacause I changed both of them at the same time and I am so behind my schedule I have no time to test it. I will improve this answer when I reproduce the bug and solution in spare time.

我不确定他们中的哪一个有帮助,因为我同时改变了他们两个,而且我太落后于我的日程安排,我没有时间测试它。当我在业余时间重现错误和解决方案时,我会改进这个答案。

However, there is a hint:*Rethink and recheck your project / targets build settings.*

但是,有一个提示:*重新考虑并重新检查您的项目/目标构建设置。*

It is highly probable that this strange behavior may be caused by some unfortunate combination of build settings.

这种奇怪的行为很可能是由一些不幸的构建设置组合引起的。

回答by N.J.

All my projects does this from time to time. I can shut down X-code and start it up again and it'll run fine for a while, then go back to using 200% CPU time (two cores fully loaded).

我所有的项目都会不时地这样做。我可以关闭 X-code 并再次启动它,它会运行一段时间,然后返回使用 200% CPU 时间(两个内核满载)。

My solution is to use AppCode as my primary IDE (has the added benefit of being a much better IDE, but that's another story). I only start XCode when I need to edit storyboards and shut it down when I'm done - usually that keeps the problem at bay.

我的解决方案是使用 AppCode 作为我的主要 IDE(具有成为更好的 IDE 的额外好处,但这是另一回事)。我只在需要编辑情节提要时才启动 XCode,并在完成后关闭它 - 通常这样可以避免问题。

AppCode runs off the same project files/structure has better and faster indexing and never runs into this issue, so I can't see how this can be a settings/configuration problem - it must be a bug in XCode. Hence, I would not waste time changing your code structure as it will most likely only delay the problem, not fix it.

AppCode 运行相同的项目文件/结构具有更好更快的索引并且永远不会遇到这个问题,所以我看不出这是一个设置/配置问题 - 它一定是 XCode 中的错误。因此,我不会浪费时间更改您的代码结构,因为它很可能只会延迟问题,而不是修复它。

回答by n8tr

No way to know if the OP actually had a different root cause, but for me it appears to have been an Xcode glitch with git. Adding / committing my current changes solved my problem. Here is the complete scenario and what I did to get it fixed:

无法知道 OP 是否真的有不同的根本原因,但对我来说,这似乎是 Xcode 的 git 故障。 添加/提交我当前的更改解决了我的问题。这是完整的场景以及我为修复它所做的工作:

  • Environment:
    • Xcode Version 5.1.1 (5B1008)
    • Macbook Pro OS X 10.9.2
    • 2 GHz Intel Core i7, 8GB RAM
  • I noticed Xcode was starting to eat 200% of my CPU constantly.
  • Not sure exactly when it started, but Xcode did freeze up on trying to make a snapshot (400% CPU usage for several minutes until I force-quitted Xcode)
  • After reopening, I noticed Xcode was still stuck indefinitely at 200% CPU usage.
  • Closing all projects did not work.
  • Deleting all derived data and restarting did not work.
  • Uninstalling Xcode and reinstalling at first held promise, but once I re-opened my main project, the CPU returned to a constant 200% CPU usage. (after indexing finished)
  • Closing the troubled project did not help. Xcode was now stuck again in forever-kill-200%-of-CPU land.
  • 环境:
    • Xcode 版本 5.1.1 (5B1008)
    • Macbook Pro OS X 10.9.2
    • 2 GHz 英特尔酷睿 i7,8GB 内存
  • 我注意到 Xcode 开始不断地消耗我200% 的 CPU。
  • 不确定它何时开始,但 Xcode 在尝试制作快照时确实冻结了(CPU 使用率为 400%,持续几分钟,直到我强制退出 Xcode)
  • 重新打开后,我注意到 Xcode 仍然无限期地停留在200% CPU 使用率。
  • 关闭所有项目不起作用。
  • 删除所有派生数据并重新启动不起作用。
  • 卸载 Xcode 并重新安装一开始是有希望的,但是一旦我重新打开我的主项目,CPU 就会恢复到200% 的 CPU 使用率。(索引完成后)
  • 关闭陷入困境的项目并没有帮助。Xcode 现在再次陷入永远杀死 200% CPU 的土地。

After looking around Stack Overflow, multiple people alluded to git being an issue.

在环顾 Stack Overflow 之后,很多人都提到 git 是一个问题。

  • I have a slightly complicated git repo (has a submodule repo and a subproject within the main Xcode project).
  • I had pending changes in both the main repo and submodule portion of the repo.
  • I closed Xcode and git added & committed all my current changes.
  • Reopen Xcode and VIOLA!No more CPU being killed. Back down to 0.0% idle usage.
  • 我有一个稍微复杂的 git repo(在主 Xcode 项目中有一个子模块 repo 和一个子项目)。
  • 我在 repo 的主 repo 和 submodule 部分都有待处理的更改。
  • 我关闭了 Xcode,然后 git 添加并提交了我当前的所有更改。
  • 重新打开 Xcode 和VIOLA!不再有 CPU 被杀死。回到0.0% 空闲使用率。

Xcode 5.1.x seems to struggle with git in other ways for me too (sometimes does not pick up changes in the GUI, etc.) so perhaps there are Xcode git integration bugs.

Xcode 5.1.x 对我来说似乎也在其他方面与 git 斗争(有时不会在 GUI 中进行更改等),所以也许存在 Xcode git 集成错误。

回答by justin

It looks like it's spending its time parsing ObjC included in the PCH.

看起来它正在花时间解析包含在 PCH 中的 ObjC。

  • How many PCHs must clang generate? In your project, that would be one for C, one for ObjC, one for C++, one for ObjC++ for each dialect/lang used in your project and any dependent targets. That is -- if you have a dependent library included in your app's PCH and you are hacking on that library, all code sense in the app target must be invalidated and parsed again each time you alter a header included by your pch. And if your target compiles a C file, it will need a PCH for C. If it needs one for ObjC, it will need to generate one for ObjC.
  • How often do you alter the PCH (or anything included by it)?
  • Remove includes from the PCH. It's not unusual to see every linked framework included in a PCH (avoid doing this!).
  • If you change your build or preprocessor settings, it may need to rebuild the code sense index for the target(s) entirelyeach time.
  • Have you tried disabling live issues?
  • clang 必须生成多少个 PCH?在您的项目中,对于您的项目中使用的每种方言/语言以及任何相关目标,这将是 C 的一个,ObjC 的一个,C++ 的一个,ObjC++ 的一个。也就是说——如果您的应用程序的 PCH 中包含一个依赖库并且您正在对该库进行黑客攻击,则每次更改包含在您的 pch 中的标头时,应用程序目标中的所有代码意义都必须无效并再次解析。如果你的目标编译一个 C 文件,它需要一个 C 的 PCH。如果它需要一个用于 ObjC 的 PCH,它需要为 ObjC 生成一个。
  • 您多久更改一次 PCH(或其中包含的任何内容)?
  • 从 PCH 中删除包含。在 PCH 中看到每个链接框架并不罕见(避免这样做!)。
  • 如果您更改构建或预处理器设置,则可能需要每次完全为目标重新构建代码感知索引。
  • 您是否尝试过禁用实时问题?

回答by scippie

On my projects (all of them) it was the autocompletion/intellisense. When I changed one line of code in my .h files, it went haywire, +100% CPU usage (more than one core). I just disabled it, now I have to think a bit more for myself (like I used to do on windows) and it works great at low CPU usage.

在我的项目(所有项目)中,它是自动完成/智能感知。当我在我的 .h 文件中更改一行代码时,它出问题了,CPU 使用率 +100%(多于一个内核)。我只是禁用了它,现在我必须为自己考虑更多(就像我以前在 Windows 上所做的那样)并且它在 CPU 使用率低的情况下效果很好。

回答by rookie

i used to encounter this problem.it is caused by git.Although i don't know the git very well.i removed the file named .git in the project directory and it turned to normal.by the way,the .git is hidden.

以前也遇到过这个问题,是git引起的。虽然我不太了解git,我把项目目录下的.git文件去掉,就正常了。顺便说一下,.git是隐藏的.