Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SourceKitService消耗CPU并使Xcode停止运行_Ios_Iphone_Swift_Xcode_Sourcekit - Fatal编程技术网

Ios SourceKitService消耗CPU并使Xcode停止运行

Ios SourceKitService消耗CPU并使Xcode停止运行,ios,iphone,swift,xcode,sourcekit,Ios,Iphone,Swift,Xcode,Sourcekit,这不是测试版的问题。我在Xcode 6.0.1的生产版上。我遇到的问题是,当我尝试构建或运行我正在处理的代码时,Xcode会在很长一段时间内没有响应,SourceKitService消耗了超过400%的CPU(根据Activity Monitor)。这个版本在最近几天还是新的,不过奇怪的是,自从9月17日Xcode 6.0正式发布以来,我一直在使用它。我升级到6.0.1,希望它能包含此问题的修复程序 知道问题出在哪里吗?今天下午早些时候,Xcode 6.1.1遇到了这个问题(不是beta版,官方

这不是测试版的问题。我在Xcode 6.0.1的生产版上。我遇到的问题是,当我尝试构建或运行我正在处理的代码时,Xcode会在很长一段时间内没有响应,SourceKitService消耗了超过400%的CPU(根据Activity Monitor)。这个版本在最近几天还是新的,不过奇怪的是,自从9月17日Xcode 6.0正式发布以来,我一直在使用它。我升级到6.0.1,希望它能包含此问题的修复程序


知道问题出在哪里吗?

今天下午早些时候,Xcode 6.1.1遇到了这个问题(不是beta版,官方发布的版本)。我一直在操场上运行一些代码,并怀疑这就是原因。CPU占用率接近100%,Xcode无法完成构建。

下面是我所做的: 1.打开“活动监视器”,其中显示SourceKitService作为主CPU占用器。 2.在“活动监视器”中,双击SourceKitService并单击“打开文件和端口”部分,这表明它正在处理特定文件夹的/Users/myname/Library/Developer/Xcode/DerivedData/ModuleCache/目录下的文件 3.已删除指定的文件夹(从命令行,使用rm-rf)。缓存将根据重新生成 4.再次使用活动监视器,强制退出SourceKitServer。在Xcode中看到现在非常熟悉的标志,表示SourceKitService已崩溃(这就是SourceKitService听起来很熟悉的原因!)。 5.重复步骤3。

Mac还是和平的。没有数据丢失,Xcode甚至不需要重新启动(我尝试过,但没有成功)。底线是ModuleCache似乎在循环中获取SourceKitService,删除文件夹似乎可以解决这个问题。希望这对你也有用


Bootnote:顺便说一句,SourceKitService问题的原因是我的Swift类中的数组声明太长。我在一个数组中有200多个条目。将其减少到30,错误就消失了。因此,这个问题可能是由于apple代码中的某种堆栈溢出(双关语)引起的。

我看到了这个问题,因为我声明了一个包含大约60个元素的数组,如下所示:

let byteMap = [

["ECG" : (0,12)],
["PPG" : (12,3)],
["ECG" : (15,12)],
["PPG" : (27,3)],
["ECG" : (30,12)]
let byteMap : [String: (Int, Int)] = [

["ECG" : (0,12)],
["PPG" : (12,3)],
["ECG" : (15,12)],
["PPG" : (27,3)],
["ECG" : (30,12)],
let firstLevel = [
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0],
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0],
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0]
        ]
        let secondLevel = [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 0, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ]
        let thirdLevel =     [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ]
        let map = [firstLevel, secondLevel, thirdLevel]
var myArray: [(String, Bool?)]?
myArray = [("someString", someBool),
("someString", someBool),
("someString", someBool),
("someString", someBool),
("someString", someBool)
.
.
("someString", someBool)]
通过如下显式注释类型:

let byteMap = [

["ECG" : (0,12)],
["PPG" : (12,3)],
["ECG" : (15,12)],
["PPG" : (27,3)],
["ECG" : (30,12)]
let byteMap : [String: (Int, Int)] = [

["ECG" : (0,12)],
["PPG" : (12,3)],
["ECG" : (15,12)],
["PPG" : (27,3)],
["ECG" : (30,12)],
let firstLevel = [
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0],
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0],
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0]
        ]
        let secondLevel = [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 0, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ]
        let thirdLevel =     [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ]
        let map = [firstLevel, secondLevel, thirdLevel]
var myArray: [(String, Bool?)]?
myArray = [("someString", someBool),
("someString", someBool),
("someString", someBool),
("someString", someBool),
("someString", someBool)
.
.
("someString", someBool)]
我能让它停下来。我认为这一定与Swift的类型推断和类型检查有关,当它遇到长数组时,它会进入一个循环


这是在Xcode 6.2中。我还删除了如上所述的ModuleCache,现在一切正常。

我解决了另一个导致SourceKitService使用高达13GB内存的问题

我有一个字符串(格式行,有很多参数:

return String(format: "%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", samples.count,sum1.x,sum1.y,sum1.z,sum1.rx,sum1.ry,sum1.rz,sum2.x,sum2.y,sum2.z,sum2.rx,sum2.ry,sum2.rz,sum3.x,sum3.y,sum3.z,sum3.rx,sum3.ry,sum3.rz)
当用它替换时,它工作得很好(没有内存积累和正常的CPU消耗)


对我来说,删除派生数据是有效的。从菜单中选择“Product”,按住Alt键并选择“Clean Build Folder”。快捷键:Alt+Shift+Command+K

Xcode 7.2(7C68)


解决方案是实现一个协议的方法,我的类在定义中有这个方法。

这个问题发生了10次,8次是在我连接一个实际的设备而没有运行模拟器时发生的

我不太确定我的解决方案是否好,但对我来说,我相信问题是由于在模拟器和实际设备之间切换。这听起来可能很奇怪,但它似乎在缓存文件之间产生了干扰

是什么解决了我的问题:

  • 清理构建文件夹:(在Xcode上)
    Alt+Shift+Command+K
  • 重置内容和设置:(打开 模拟器)
    命令+Shift+K
  • 等待的时间比正常情况稍长,并通过不断的点击重载Xcode
因此,基本上,在您尝试在任何新设备上运行之前,只需删除任何缓存即可

编辑
我只是在没有任何设备连接的情况下遇到了问题。我刚退出Xcode并再次打开它,问题就消失了。我不确定在获取/拉合并新代码后可能会出现一些重新编制索引的问题。

这在Xcode 7.3.1版(7D1014)中仍然是一个问题 就像LNI指出的那样,我的原因是数组太长,实际上不是太长。 我修复了我的问题,将数组分解为如下各种数组:

let byteMap = [

["ECG" : (0,12)],
["PPG" : (12,3)],
["ECG" : (15,12)],
["PPG" : (27,3)],
["ECG" : (30,12)]
let byteMap : [String: (Int, Int)] = [

["ECG" : (0,12)],
["PPG" : (12,3)],
["ECG" : (15,12)],
["PPG" : (27,3)],
["ECG" : (30,12)],
let firstLevel = [
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0],
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0],
            [1, 0, 1, 0, 1],
            [0, 0, 0, 0, 0]
        ]
        let secondLevel = [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 0, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ]
        let thirdLevel =     [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ]
        let map = [firstLevel, secondLevel, thirdLevel]
var myArray: [(String, Bool?)]?
myArray = [("someString", someBool),
("someString", someBool),
("someString", someBool),
("someString", someBool),
("someString", someBool)
.
.
("someString", someBool)]
  • 退出Xcode
  • 运行终端:
  • rm-rf~/Library/Developer/Xcode/DerivedData/ModuleCache/*


    请注意LNI接受的答案与此答案之间的差异:

  • 不崩溃总比崩溃好,尤其是涉及到Xcode进程/组件时
  • 我不是苹果的开发者,但是部分删除缓存会破坏它的完整性。在清理所有缓存之后,我没有注意到任何明显的延迟

  • 我花了4个小时来解决我的项目的长期汇编中的问题。 第一次尝试需要42分钟来编译

    重新启动
    SourceKitService
    后,按照@LNI的建议,我清除
    /Users/myname/Library/Developer/Xcode/DerivedData/ModuleCache/
    中的所有缓存,并对代码进行少量更改:

    (一) 到

    2) 到

    (三)

    结果编译时间为3分钟,速度不太快,但最好为42分钟

    因此,在
    SourceKitService
    之前-占用约5,2Gb内存,在约0.37Gb之后


    我对XCode 8.2.1(8C1002)和以下代码有同样的问题:

    import UIKit
    import AVFoundation
    import Photos
    import CoreMotion
    import Foundation
    
    
    class TestViewController: UIViewController
    {
        let movieFileOutput = AVCaptureMovieFileOutput()
    
    
    var anz_total_frames = 0, anz_total_miss = 0
    
    @IBOutlet weak var tfStatistics: UITextView!
    
    
    func showVideoStatistics()
    {
        let statisticText:String =             "frames: \(self.anz_total_frames)" + String.newLine +
    
            "frames/s: \(self.anz_total_frames / self.movieFileOutput.recordedDuration.seconds)" + String.newLine +
    
            "miss: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
        "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine +
            "nicht erkannt: " + formatText4FramesPercent(self.anz_total_miss) + String.newLine
    
    
        self.tfStatistics.text = statisticText
    }
    
    func formatText4FramesPercent(_ anz:Int) -> String
        {
            let perc = Double(anz)*100.0/Double(anz_total_frames)
            return String(perc.format(".1") + "%")
        }
    }
    
    这些扩展:

    extension String {
        var localized: String {
            return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
        }
    
        static var newLine: String {
            return "\r\n"
        }
    }
    
    extension Int {
        func format(_ f: String) -> String {
            return String(format: "%\(f)d", self)
        }
    }
    
    extension Double {
        func format(_ f: String) -> String {
            return String(format: "%\(f)f", self)
        }
    }
    
    我通过在TestViewController中注释这一行解决了这个问题:

            "frames/s: \(self.anz_total_frames / self.movieFileOutput.recordedDuration.seconds)" + String.newLine +
    
    我花了一个多小时才找到它,我希望a能为别人节省一些时间。
    对于Objective-C项目,我向苹果提交了一份编号为30103533的错误报告:

    我也有同样的问题,我们的项目中没有Swift代码,所以它不是ch类型
    // one term is not an issue
    let debugString1 = (placeMark.locality ?? "")
    
    // two terms pushes SourceKitService CPU use to 107% for about 60 seconds then settles to 0%
    let debugString1 = (placeMark.locality ?? "")  + ", " +  (placeMark.administrativeArea ?? "") 
    
    // three terms pushes SourceKitService CPU use to 187% indefinitely 
    let debugString1 = (placeMark.locality ?? "")  + ", " +  (placeMark.administrativeArea ?? "")  + (placeMark.postalCode ?? "")
    
    // ugly but it's safe to use
    var debugString1 = placeMark.locality ?? ""
    debugString1 = debugString1 + ", " +  (placeMark.administrativeArea ?? "")
    debugString1 = debugString1 + " " + (placeMark.postalCode ?? "")
    
    var color: [UIColor] {
        return [
            UIColor(...),
            UIColor(...),
            ...
        ]
    }
    
    func color() -> [UIColor] {
        return [
            UIColor(...),
            UIColor(...),
            ...
        ]
    }
    
    killall Xcode
    rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache
    open /Applications/Xcode.app
    
    echo alias xcodeFix='killall Xcode;rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache;open /Applications/Xcode.app' >> ~/.profile
    source ~/.profile
    
    xcodeFix
    
    private lazy var emojiFace = ["?", "?", "?", "?"]
    
    private lazy var emojiFace:[String] = ["?", "?", "?", "?"]