diff --git a/BuildTimeAnalyzer.xcodeproj/project.pbxproj b/BuildTimeAnalyzer.xcodeproj/project.pbxproj index 21c8586..87d8af8 100644 --- a/BuildTimeAnalyzer.xcodeproj/project.pbxproj +++ b/BuildTimeAnalyzer.xcodeproj/project.pbxproj @@ -252,7 +252,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Cane Media Ltd"; TargetAttributes = { 2AF8213F1D21D6B900D65186 = { @@ -353,6 +353,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -408,6 +409,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; diff --git a/BuildTimeAnalyzer.xcodeproj/xcshareddata/xcschemes/BuildTimeAnalyzer.xcscheme b/BuildTimeAnalyzer.xcodeproj/xcshareddata/xcschemes/BuildTimeAnalyzer.xcscheme index f8d451d..7a47967 100644 --- a/BuildTimeAnalyzer.xcodeproj/xcshareddata/xcschemes/BuildTimeAnalyzer.xcscheme +++ b/BuildTimeAnalyzer.xcodeproj/xcshareddata/xcschemes/BuildTimeAnalyzer.xcscheme @@ -1,6 +1,6 @@ () +fileprivate let regex = try! NSRegularExpression(pattern: "^\\d*\\.?\\d*ms\\t/", options: []) + protocol LogProcessorProtocol: class { var rawMeasures: [String: RawMeasure] { get set } var updateHandler: CMUpdateClosure? { get set } @@ -16,86 +18,117 @@ protocol LogProcessorProtocol: class { func processingDidFinish() } -extension LogProcessorProtocol { +class LogProcessor: NSObject, LogProcessorProtocol { + + var rawMeasures: [String: RawMeasure] = [:] + var updateHandler: CMUpdateClosure? + var shouldCancel = false + var timer: Timer? + + func processingDidStart() { + DispatchQueue.main.async { + self.timer = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(self.timerCallback(_:)), userInfo: nil, repeats: true) + } + } + + func processingDidFinish() { + DispatchQueue.main.async { + self.timer?.invalidate() + self.timer = nil + let didCancel = self.shouldCancel + self.shouldCancel = false + self.updateResults(didComplete: true, didCancel: didCancel) + } + } + + @objc func timerCallback(_ timer: Timer) { + updateResults(didComplete: false, didCancel: false) + } + func processDatabase(database: XcodeDatabase, updateHandler: CMUpdateClosure?) { guard let text = database.processLog() else { updateHandler?([], true, false) return } - + self.updateHandler = updateHandler - DispatchQueue.global().async { + DispatchQueue.global(qos: .background).async { self.process(text: text) } } - + // MARK: Private methods - + private func process(text: String) { - let characterSet = CharacterSet(charactersIn:"\r\"") + let characterSet = CharacterSet(charactersIn:"\r") var remainingRange = text.startIndex...init(match.range, in: text)! + let timeString = text[remainingRange.lowerBound.. 10 } - if filteredResults.count < 20 { - filteredResults = rawMeasures.values.filter{ $0.time > 0.1 } - } - - let sortedResults = filteredResults.sorted(by: { $0.time > $1.time }) - updateHandler?(processResult(sortedResults), completed, didCancel) - - if completed { - rawMeasures.removeAll() + DispatchQueue.global(qos: .userInteractive).async { + let measures = self.rawMeasures.values + var filteredResults = measures.filter{ $0.time > 10 } + if filteredResults.count < 20 { + filteredResults = measures.filter{ $0.time > 0.1 } + } + + let sortedResults = filteredResults.sorted(by: { $0.time > $1.time }) + let result = self.processResult(sortedResults) + + if completed { + self.rawMeasures.removeAll() + } + + DispatchQueue.main.async { + self.updateHandler?(result, completed, didCancel) + } } } - + private func processResult(_ unprocessedResult: [RawMeasure]) -> [CompileMeasure] { let characterSet = CharacterSet(charactersIn:"\r\"") - + var result: [CompileMeasure] = [] for entry in unprocessedResult { let code = entry.text.split(separator: "\t").map(String.init) let method = code.count >= 2 ? trimPrefixes(code[1]) : "-" - + if let path = code.first?.trimmingCharacters(in: characterSet), let measure = CompileMeasure(time: entry.time, rawPath: path, code: method, references: entry.references) { result.append(measure) } } return result } - + private func trimPrefixes(_ code: String) -> String { var code = code ["@objc ", "final ", "@IBAction "].forEach { (prefix) in @@ -106,31 +139,3 @@ extension LogProcessorProtocol { return code } } - -class LogProcessor: NSObject, LogProcessorProtocol { - - var rawMeasures: [String: RawMeasure] = [:] - var updateHandler: CMUpdateClosure? - var shouldCancel = false - var timer: Timer? - - func processingDidStart() { - DispatchQueue.main.async { - self.timer = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(self.timerCallback(_:)), userInfo: nil, repeats: true) - } - } - - func processingDidFinish() { - DispatchQueue.main.async { - self.timer?.invalidate() - self.timer = nil - let didCancel = self.shouldCancel - self.shouldCancel = false - self.updateResults(didComplete: true, didCancel: didCancel) - } - } - - @objc func timerCallback(_ timer: Timer) { - updateResults(didComplete: false, didCancel: false) - } -} diff --git a/BuildTimeAnalyzer/ProjectSelection.swift b/BuildTimeAnalyzer/ProjectSelection.swift old mode 100644 new mode 100755 diff --git a/BuildTimeAnalyzer/RawMeasure.swift b/BuildTimeAnalyzer/RawMeasure.swift old mode 100644 new mode 100755 index ef8fe35..c0aead0 --- a/BuildTimeAnalyzer/RawMeasure.swift +++ b/BuildTimeAnalyzer/RawMeasure.swift @@ -5,7 +5,7 @@ import Foundation -struct RawMeasure { +class RawMeasure { var time: Double var text: String var references: Int @@ -28,7 +28,9 @@ func ==(lhs: RawMeasure, rhs: RawMeasure) -> Bool { // MARK: Hashable extension RawMeasure: Hashable { + func hash(into hasher: inout Hasher) { - hasher.combine(time.hashValue ^ text.hashValue) + hasher.combine(time) + hasher.combine(text) } } diff --git a/BuildTimeAnalyzer/ViewController.swift b/BuildTimeAnalyzer/ViewController.swift old mode 100644 new mode 100755