From ef51eab07661fb6900d7a586b048bc85eec4836f Mon Sep 17 00:00:00 2001 From: georgeivannikov <41365858+georgeivannikov@users.noreply.github.com> Date: Thu, 15 Apr 2021 13:53:24 +0200 Subject: [PATCH 1/3] FEAT: HIPMC-1914, cpu info added to metadatalogger --- QuantiLogger.xcodeproj/project.pbxproj | 6 ++ .../common/MetaInformationLogger.swift | 17 ++-- QuantiLogger/common/UIDevice+.swift | 79 +++++++++++++++++++ 3 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 QuantiLogger/common/UIDevice+.swift diff --git a/QuantiLogger.xcodeproj/project.pbxproj b/QuantiLogger.xcodeproj/project.pbxproj index a8bda69d..c35635c4 100644 --- a/QuantiLogger.xcodeproj/project.pbxproj +++ b/QuantiLogger.xcodeproj/project.pbxproj @@ -99,6 +99,8 @@ 9C6F8ED023A0EE240098FA4C /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C6F8ECF23A0EE240098FA4C /* RxSwift.framework */; platformFilter = ios; }; 9C6F8ED523A0F0210098FA4C /* RxTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C6F8ED123A0EE2B0098FA4C /* RxTest.framework */; }; 9C6F8ED723A0F02B0098FA4C /* RxRelay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C6F8ECD23A0EE1E0098FA4C /* RxRelay.framework */; }; + 9C74063226284F6C005B2E69 /* UIDevice+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C74063126284F6C005B2E69 /* UIDevice+.swift */; }; + 9C74064326285BC0005B2E69 /* UIDevice+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C74063126284F6C005B2E69 /* UIDevice+.swift */; }; D32E659320D15A5C00698F3E /* WebLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E659220D15A5C00698F3E /* WebLogger.swift */; }; D32E659E20D15A7100698F3E /* JSONParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E659420D15A6900698F3E /* JSONParser.swift */; }; D32E659F20D15A7100698F3E /* ApiFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E659520D15A6A00698F3E /* ApiFactory.swift */; }; @@ -185,6 +187,7 @@ 9C6F8ECF23A0EE240098FA4C /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = SOURCE_ROOT; }; 9C6F8ED123A0EE2B0098FA4C /* RxTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxTest.framework; path = Carthage/Build/iOS/RxTest.framework; sourceTree = SOURCE_ROOT; }; 9C6F8ED323A0EE300098FA4C /* RxAtomic.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxAtomic.framework; path = Carthage/Build/iOS/RxAtomic.framework; sourceTree = SOURCE_ROOT; }; + 9C74063126284F6C005B2E69 /* UIDevice+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+.swift"; sourceTree = ""; }; D32E659220D15A5C00698F3E /* WebLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebLogger.swift; sourceTree = ""; }; D32E659420D15A6900698F3E /* JSONParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParser.swift; sourceTree = ""; }; D32E659520D15A6A00698F3E /* ApiFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiFactory.swift; sourceTree = ""; }; @@ -315,6 +318,7 @@ FFF2456E24472F5B0028F625 /* Substring+.swift */, 5B164FBE23BDF65700A5F4E6 /* Date+.swift */, 5B164FC123BDF67800A5F4E6 /* Observable+.swift */, + 9C74063126284F6C005B2E69 /* UIDevice+.swift */, ); name = Extensions; sourceTree = ""; @@ -791,6 +795,7 @@ 6C07CA8522CA6C740009203A /* LogFilesViaMailViewController.swift in Sources */, D32E65A320D15A7100698F3E /* HttpMethod.swift in Sources */, 5BA3645D1DD0EDD10017F9EB /* LogFileRecord.swift in Sources */, + 9C74063226284F6C005B2E69 /* UIDevice+.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -835,6 +840,7 @@ 5BA6AB03226F42BA00FBB047 /* Data+Serialization.swift in Sources */, 5BF957471F5ED3A700F88F9B /* LogFileRecord.swift in Sources */, FF2C2F0624640A7500399D9D /* Substring+.swift in Sources */, + 9C74064326285BC0005B2E69 /* UIDevice+.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/QuantiLogger/common/MetaInformationLogger.swift b/QuantiLogger/common/MetaInformationLogger.swift index 3afca41e..4bf09074 100644 --- a/QuantiLogger/common/MetaInformationLogger.swift +++ b/QuantiLogger/common/MetaInformationLogger.swift @@ -11,7 +11,7 @@ import Foundation import UIKit #endif -public enum MetaInformationType: String { +public enum MetaInformationType: String, CaseIterable { case identifier = "CFBundleIdentifier" case compiler = "DTCompiler" case version = "CFBundleShortVersionString" @@ -20,9 +20,8 @@ public enum MetaInformationType: String { case currentOSVersion = "CurrentOSVersion" case upTime = "UpTime" case language = "Language" - - static let allValues: [MetaInformationType] = [.identifier, .compiler, .version, .buildNumber, - .modelType, .currentOSVersion, .upTime, .language] + case cpuName = "CPUName" + case cpuSpeed = "CPUSpeed" } protocol MetaInformationLoggerDelegate: class { @@ -100,11 +99,19 @@ class MetaInformationLogger { data[MetaInformationType.language.rawValue] = _value } + if dataToLog.contains(.cpuName) { + data[MetaInformationType.language.rawValue] = UIDevice.current.cpuName + } + + if dataToLog.contains(.cpuSpeed) { + data[MetaInformationType.language.rawValue] = UIDevice.current.cpuSpeed + } + return data } func log(_ dataToLog: [MetaInformationType], onLevel level: Level) { - let _dataToLog = dataToLog.count == 0 ? MetaInformationType.allValues : dataToLog + let _dataToLog = dataToLog.count == 0 ? MetaInformationType.allCases : dataToLog delegate?.logMetaInformation("Meta information: \(values(for: _dataToLog))", onLevel: level) } diff --git a/QuantiLogger/common/UIDevice+.swift b/QuantiLogger/common/UIDevice+.swift new file mode 100644 index 00000000..e0982087 --- /dev/null +++ b/QuantiLogger/common/UIDevice+.swift @@ -0,0 +1,79 @@ +// +// UIDevice+.swift +// QuantiLogger +// +// Created by George Ivannikov on 4/15/21. +// Copyright © 2021 quanti. All rights reserved. +// + +import Foundation +import UIKit + +extension UIDevice { + //Original Author: HAS + // https://stackoverflow.com/questions/33855998/how-to-get-hardware-details-in-swift + var cpuName: String { + Array(CPUinfo().keys)[0] + } + + var cpuSpeed: String { + Array(CPUinfo().values)[0] + } + + private func CPUinfo() -> [String: String] { + #if targetEnvironment(simulator) + let identifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"]! + #else + + var systemInfo = utsname() + uname(&systemInfo) + let machineMirror = Mirror(reflecting: systemInfo.machine) + let identifier = machineMirror.children.reduce("") { identifier, element in + guard let value = element.value as? Int8, value != 0 else { return identifier } + return identifier + String(UnicodeScalar(UInt8(value))) + } + #endif + + switch identifier { + case "iPod5,1": return ["A5": "800 MHz"] + case "iPod7,1": return ["A8": "1.4 GHz"] + case "iPhone3,1", "iPhone3,2", "iPhone3,3": return ["A4": "800 MHz"] + case "iPhone4,1": return ["A5": "800 MHz"] + case "iPhone5,1", "iPhone5,2": return ["A6": "1.3 GHz"] + case "iPhone5,3", "iPhone5,4": return ["A6": "1.3 GHz"] + case "iPhone6,1", "iPhone6,2": return ["A7": "1.3 GHz"] + case "iPhone7,2": return ["A8": "1.4 GHz"] + case "iPhone7,1": return ["A8": "1.4 GHz"] + case "iPhone8,1": return ["A9": "1.85 GHz"] + case "iPhone8,2": return ["A9": "1.85 GHz"] + case "iPhone9,1", "iPhone9,3": return ["A10 Fusion": "2.34 GHz"] + case "iPhone9,2", "iPhone9,4": return ["A10 Fusion": "2.34 GHz"] + case "iPhone8,4": return ["A9": "1.85 GHz"] + case "iPhone10,1", "iPhone10,4": return ["A11 Bionic": "2.39 GHz"] + case "iPhone10,2", "iPhone10,5": return ["A11 Bionic": "2.39 GHz"] + case "iPhone10,3", "iPhone10,6": return ["A11 Bionic": "2.39 GHz"] + case "iPhone11,2", "iPhone11,4", + "iPhone11,6", "iPhone11,8": return ["A12": "2.5 GHz"] + case "iPhone12,1", "iPhone12,3", "iPhone12,5": return ["A13": "2650 GHz"] + case "iPhone12,8": return ["A13": "2.65 GHz"] + case "iPhone13,2", "iPhone13,1", "iPhone13,3": return ["A14": "2.99 GHz"] + case "iPhone13,4": return ["A14": "3.1 GHz"] + case "iPad2,1", "iPad2,2", + "iPad2,3", "iPad2,4": return ["A5": "1.0 GHz"] + case "iPad3,1", "iPad3,2", "iPad3,3": return ["A5X": "1.0 GHz"] + case "iPad3,4", "iPad3,5", "iPad3,6": return ["A6X": "1.4 GHz"] + case "iPad4,1", "iPad4,2", "iPad4,3": return ["A7": "1.4 GHz"] + case "iPad5,3", "iPad5,4": return ["A8X": "1.5 GHz"] + case "iPad6,11", "iPad6,12": return ["A9": "1.85 GHz"] + case "iPad2,5", "iPad2,6", "iPad2,7": return ["A5": "1.0 GHz"] + case "iPad4,4", "iPad4,5", "iPad4,6": return ["A7": "1.3 GHz"] + case "iPad4,7", "iPad4,8", "iPad4,9": return ["A7": "1.3 GHz"] + case "iPad5,1", "iPad5,2": return ["A8": "1.5 GHz"] + case "iPad6,3", "iPad6,4": return ["A9X": "2.16 GHz"] + case "iPad6,7", "iPad6,8": return ["A9X": "2.24 GHz"] + case "iPad7,1", "iPad7,2": return ["A10X Fusion": "2.34 GHz"] + case "iPad7,3", "iPad7,4": return ["A10X Fusion": "2.34 GHz"] + default: return ["N/A": "N/A"] + } + } +} From 7ee65e829d0b8b34f1564c5281fe95abfe9a4d8f Mon Sep 17 00:00:00 2001 From: georgeivannikov <41365858+georgeivannikov@users.noreply.github.com> Date: Thu, 15 Apr 2021 14:04:00 +0200 Subject: [PATCH 2/3] FEAT: HIPMC-1914, target membership updated --- QuantiLogger.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/QuantiLogger.xcodeproj/project.pbxproj b/QuantiLogger.xcodeproj/project.pbxproj index c35635c4..1a3e03b0 100644 --- a/QuantiLogger.xcodeproj/project.pbxproj +++ b/QuantiLogger.xcodeproj/project.pbxproj @@ -101,6 +101,7 @@ 9C6F8ED723A0F02B0098FA4C /* RxRelay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C6F8ECD23A0EE1E0098FA4C /* RxRelay.framework */; }; 9C74063226284F6C005B2E69 /* UIDevice+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C74063126284F6C005B2E69 /* UIDevice+.swift */; }; 9C74064326285BC0005B2E69 /* UIDevice+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C74063126284F6C005B2E69 /* UIDevice+.swift */; }; + 9C740649262861F7005B2E69 /* UIDevice+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C74063126284F6C005B2E69 /* UIDevice+.swift */; }; D32E659320D15A5C00698F3E /* WebLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E659220D15A5C00698F3E /* WebLogger.swift */; }; D32E659E20D15A7100698F3E /* JSONParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E659420D15A6900698F3E /* JSONParser.swift */; }; D32E659F20D15A7100698F3E /* ApiFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E659520D15A6A00698F3E /* ApiFactory.swift */; }; @@ -869,6 +870,7 @@ 6C5DF0B622C0E96600271501 /* ConsoleLogger.swift in Sources */, FF2C2F0524640A4200399D9D /* Substring+.swift in Sources */, 6C5DF0B722C0E96600271501 /* ApiFactory.swift in Sources */, + 9C740649262861F7005B2E69 /* UIDevice+.swift in Sources */, 6C5DF0B822C0E96600271501 /* SystemLogger.swift in Sources */, 6C5DF0B922C0E96600271501 /* ApiError.swift in Sources */, 6C5DF0BA22C0E96600271501 /* JSONParseable.swift in Sources */, From 931d87d6f73224f507240a4a0b006aead0baaf57 Mon Sep 17 00:00:00 2001 From: georgeivannikov <41365858+georgeivannikov@users.noreply.github.com> Date: Mon, 19 Apr 2021 10:03:49 +0200 Subject: [PATCH 3/3] FEAT: HIPMC1914, meta dict. fixed --- QuantiLogger/common/MetaInformationLogger.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QuantiLogger/common/MetaInformationLogger.swift b/QuantiLogger/common/MetaInformationLogger.swift index 4bf09074..89445fe6 100644 --- a/QuantiLogger/common/MetaInformationLogger.swift +++ b/QuantiLogger/common/MetaInformationLogger.swift @@ -100,11 +100,11 @@ class MetaInformationLogger { } if dataToLog.contains(.cpuName) { - data[MetaInformationType.language.rawValue] = UIDevice.current.cpuName + data[MetaInformationType.cpuName.rawValue] = UIDevice.current.cpuName } if dataToLog.contains(.cpuSpeed) { - data[MetaInformationType.language.rawValue] = UIDevice.current.cpuSpeed + data[MetaInformationType.cpuSpeed.rawValue] = UIDevice.current.cpuSpeed } return data