From 5d62029b4c64f7a8c0e5d525fbd43c01a0e48bb6 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 20 Sep 2022 18:35:42 -0800 Subject: [PATCH 01/53] DEBUG: experiment with different sysctl call values --- Sources/Sentry/SentryProfiler.mm | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index de58a0802f6..d51e8824f83 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -61,14 +61,135 @@ } namespace { +NSString * +getCPUArchitecture() +{ + size_t size; + cpu_type_t type; + cpu_subtype_t subtype; + size = sizeof(type); + const auto nameStr = [NSMutableString string]; + if (sysctlbyname("hw.cputype", &type, &size, NULL, 0) == 0) { + switch (type) { + case CPU_TYPE_I386: + [nameStr appendString:@"i386"]; + break; + case CPU_TYPE_X86_64: + [nameStr appendString:@"x86_64"]; + break; + case CPU_TYPE_ARM: + [nameStr appendString:@"arm"]; + break; + case CPU_TYPE_ARM64: + [nameStr appendString:@"arm64"]; + break; + case CPU_TYPE_ARM64_32: + [nameStr appendString:@"arm64_32"]; + break; + default: + [nameStr appendFormat:@"unknown type (%d)", type]; + break; + } + } + + size = sizeof(subtype); + if (sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0) == 0) { + switch (subtype) { + case CPU_SUBTYPE_ARM_V6: + [nameStr appendString:@"v6"]; + break; + case CPU_SUBTYPE_ARM_V7: + [nameStr appendString:@"v7"]; + break; + case CPU_SUBTYPE_ARM_V7S: + [nameStr appendString:@"v7s"]; + break; + case CPU_SUBTYPE_ARM_V7K: + [nameStr appendString:@"v7k"]; + break; + case CPU_SUBTYPE_ARM64_V8: + // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as + // ((cpu_subtype_t) 1) + [nameStr appendString:@"v8"]; + break; + case CPU_SUBTYPE_ARM64E: + [nameStr appendString:@"e"]; + break; + } + } + + return nameStr; +} + +NSString * +getOSName() +{ +# if SENTRY_HAS_UIKIT + return UIDevice.currentDevice.systemName; +# else + return @"macOS"; +# endif // SENTRY_HAS_UIKIT +} + +NSString * +getOSVersion() +{ +# if SENTRY_HAS_UIKIT + return UIDevice.currentDevice.systemVersion; +# else + // based off of + // https://github.com/lmirosevic/GBDeviceInfo/blob/98dd3c75bb0e1f87f3e0fd909e52dcf0da4aa47d/GBDeviceInfo/GBDeviceInfo_OSX.m#L107-L133 + if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { + const auto version = [[NSProcessInfo processInfo] operatingSystemVersion]; + return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion, + (long)version.minorVersion, (long)version.patchVersion]; + } else { + SInt32 major, minor, patch; + +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated-declarations" + Gestalt(gestaltSystemVersionMajor, &major); + Gestalt(gestaltSystemVersionMinor, &minor); + Gestalt(gestaltSystemVersionBugFix, &patch); +# pragma clang diagnostic pop + + return [NSString stringWithFormat:@"%d.%d.%d", major, minor, patch]; + } +# endif // SENTRY_HAS_UIKIT +} + +NSString * +getHardwareDescription(int type) +{ + int mib[2]; + char name[128]; + size_t len; + + mib[0] = CTL_HW; + mib[1] = type; + len = sizeof(name); + if (sysctl(mib, 2, &name, &len, NULL, 0) != 0) { + return @""; + } + return [NSString stringWithUTF8String:name]; +} + NSString * getDeviceModel() { + const auto machine = getHardwareDescription(HW_MACHINE); + const auto machine_arch = getHardwareDescription(HW_MACHINE_ARCH); + const auto model = getHardwareDescription(HW_MODEL); + NSLog(@"machine: %@, machine_arch: %@, model: %@", machine, machine_arch, model); +# if SENTRY_HAS_UIKIT utsname info; if (SENTRY_PROF_LOG_ERRNO(uname(&info)) == 0) { return [NSString stringWithUTF8String:info.machine]; } return @""; +# else + return model; +# endif // SENTRY_HAS_UIKIT } NSString * From d9b21cb19600b508b18326ad41a14ca7f52a07fa Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 20 Sep 2022 18:54:29 -0800 Subject: [PATCH 02/53] fix how arch/model are fetched on macos --- Sources/Sentry/SentryProfiler.mm | 73 +++++++++++++++++++------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index d51e8824f83..74fd4effd08 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -61,9 +61,41 @@ } namespace { +/** + * @brief Get the hardware description of the device. + * @discussion The values returned are different between iOS and macOS. Some examples of values returned on different devices: + * @code + * | device | machine | model | + * --------------------------------------------------------------- + * | m1 mbp | arm64 | MacBookPro18,3 | + * | iphone 13 mini | iPhone14,4 | D16AP | + * | intel imac | x86_64 | iMac20,1 | + * | iphone simulator on m1 mac | arm64 | MacBookPro18,3 | + * | iphone simulator on intel mac | x86_64 | iMac20,1 | + * @endcode + * @seealso See https://www.cocoawithlove.com/blog/2016/03/08/swift-wrapper-for-sysctl.html#looking-for-the-source for more info. + * @return @c sysctl value for the combination of @c CTL_HW and the provided other flag in the @c type parameter. + */ +NSString * +getHardwareDescription(int type) +{ + int mib[2]; + char name[128]; + size_t len; + + mib[0] = CTL_HW; + mib[1] = type; + len = sizeof(name); + if (sysctl(mib, 2, &name, &len, NULL, 0) != 0) { + return @""; + } + return [NSString stringWithUTF8String:name]; +} + NSString * getCPUArchitecture() { +#if SENTRY_HAS_UIKIT size_t size; cpu_type_t type; cpu_subtype_t subtype; @@ -119,6 +151,9 @@ } return nameStr; +#else + return getHardwareDescription(HW_MACHINE); +#endif // SENTRY_HAS_UIKIT } NSString * @@ -158,38 +193,18 @@ # endif // SENTRY_HAS_UIKIT } -NSString * -getHardwareDescription(int type) -{ - int mib[2]; - char name[128]; - size_t len; - - mib[0] = CTL_HW; - mib[1] = type; - len = sizeof(name); - if (sysctl(mib, 2, &name, &len, NULL, 0) != 0) { - return @""; - } - return [NSString stringWithUTF8String:name]; -} - NSString * getDeviceModel() { - const auto machine = getHardwareDescription(HW_MACHINE); - const auto machine_arch = getHardwareDescription(HW_MACHINE_ARCH); - const auto model = getHardwareDescription(HW_MODEL); - NSLog(@"machine: %@, machine_arch: %@, model: %@", machine, machine_arch, model); -# if SENTRY_HAS_UIKIT - utsname info; - if (SENTRY_PROF_LOG_ERRNO(uname(&info)) == 0) { - return [NSString stringWithUTF8String:info.machine]; - } - return @""; -# else - return model; -# endif // SENTRY_HAS_UIKIT +#if SENTRY_HAS_UIKIT +#if TARGET_OS_SIMULATOR + return getHardwareDescription(HW_MODEL); +#else + return getHardwareDescription(HW_MACHINE); +#endif // TARGET_OS_SIMULATOR +#else + return getHardwareDescription(HW_MODEL); +#endif // SENTRY_HAS_UIKIT } NSString * From d06b42506b4d02f8b4dc2964d67e9e8c576436af Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 20 Sep 2022 22:49:35 -0800 Subject: [PATCH 03/53] use new functions --- Sources/Sentry/SentryProfiler.mm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 74fd4effd08..945f3ebad0e 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -380,15 +380,13 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"debug_meta"] = @{ @"images" : debugImages }; } + profile[@"device_architecture"] = getCPUArchitecture(); profile[@"device_locale"] = NSLocale.currentLocale.localeIdentifier; profile[@"device_manufacturer"] = @"Apple"; - const auto model = getDeviceModel(); - profile[@"device_model"] = model; + profile[@"device_model"] = getDeviceModel(); profile[@"device_os_build_number"] = getOSBuildNumber(); -# if TARGET_OS_IOS - profile[@"device_os_name"] = UIDevice.currentDevice.systemName; - profile[@"device_os_version"] = UIDevice.currentDevice.systemVersion; -# endif + profile[@"device_os_name"] = getOSName(); + profile[@"device_os_version"] = getOSVersion(); profile[@"device_is_emulator"] = @(isSimulatorBuild()); profile[@"device_physical_memory_bytes"] = [@(NSProcessInfo.processInfo.physicalMemory) stringValue]; From c07614e700c0318d8c6c582cd427214ac887e323 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 21 Sep 2022 07:02:44 +0000 Subject: [PATCH 04/53] Format code --- Sources/Sentry/SentryProfiler.mm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 945f3ebad0e..87402a67dae 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -63,7 +63,8 @@ namespace { /** * @brief Get the hardware description of the device. - * @discussion The values returned are different between iOS and macOS. Some examples of values returned on different devices: + * @discussion The values returned are different between iOS and macOS. Some examples of values + * returned on different devices: * @code * | device | machine | model | * --------------------------------------------------------------- @@ -73,8 +74,11 @@ * | iphone simulator on m1 mac | arm64 | MacBookPro18,3 | * | iphone simulator on intel mac | x86_64 | iMac20,1 | * @endcode - * @seealso See https://www.cocoawithlove.com/blog/2016/03/08/swift-wrapper-for-sysctl.html#looking-for-the-source for more info. - * @return @c sysctl value for the combination of @c CTL_HW and the provided other flag in the @c type parameter. + * @seealso See + * https://www.cocoawithlove.com/blog/2016/03/08/swift-wrapper-for-sysctl.html#looking-for-the-source + * for more info. + * @return @c sysctl value for the combination of @c CTL_HW and the provided other flag in the @c + * type parameter. */ NSString * getHardwareDescription(int type) @@ -95,7 +99,7 @@ NSString * getCPUArchitecture() { -#if SENTRY_HAS_UIKIT +# if SENTRY_HAS_UIKIT size_t size; cpu_type_t type; cpu_subtype_t subtype; @@ -151,9 +155,9 @@ } return nameStr; -#else +# else return getHardwareDescription(HW_MACHINE); -#endif // SENTRY_HAS_UIKIT +# endif // SENTRY_HAS_UIKIT } NSString * @@ -196,15 +200,15 @@ NSString * getDeviceModel() { -#if SENTRY_HAS_UIKIT -#if TARGET_OS_SIMULATOR +# if SENTRY_HAS_UIKIT +# if TARGET_OS_SIMULATOR return getHardwareDescription(HW_MODEL); -#else +# else return getHardwareDescription(HW_MACHINE); -#endif // TARGET_OS_SIMULATOR -#else +# endif // TARGET_OS_SIMULATOR +# else return getHardwareDescription(HW_MODEL); -#endif // SENTRY_HAS_UIKIT +# endif // SENTRY_HAS_UIKIT } NSString * From 4c6ad8698b985ccc390e9a1a0c8ed59660fcd9b4 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 21 Sep 2022 14:25:55 -0800 Subject: [PATCH 05/53] distinguish x86 32 and 64 bit --- Sources/Sentry/SentryProfiler.mm | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 87402a67dae..42adeb98a1a 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -104,33 +104,34 @@ cpu_type_t type; cpu_subtype_t subtype; size = sizeof(type); - const auto nameStr = [NSMutableString string]; + NSMutableString *nameStr; if (sysctlbyname("hw.cputype", &type, &size, NULL, 0) == 0) { switch (type) { - case CPU_TYPE_I386: - [nameStr appendString:@"i386"]; - break; - case CPU_TYPE_X86_64: - [nameStr appendString:@"x86_64"]; + case CPU_TYPE_X86: + if (LIKELY((type & CPU_ARCH_ABI64) == CPU_ARCH_ABI64)) { + nameStr = [NSMutableString stringWithString:@"_64"]; + } else { + nameStr = [NSMutableString stringWithString:@"x86"]; + } break; case CPU_TYPE_ARM: - [nameStr appendString:@"arm"]; + nameStr = [NSMutableString stringWithString:@"arm"]; break; case CPU_TYPE_ARM64: - [nameStr appendString:@"arm64"]; + nameStr = [NSMutableString stringWithString:@"arm64"]; break; case CPU_TYPE_ARM64_32: - [nameStr appendString:@"arm64_32"]; + nameStr = [NSMutableString stringWithString:@"arm64_32"]; break; default: - [nameStr appendFormat:@"unknown type (%d)", type]; - break; + return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; } } size = sizeof(subtype); if (sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0) == 0) { switch (subtype) { + default: break; case CPU_SUBTYPE_ARM_V6: [nameStr appendString:@"v6"]; break; From 856c839d9bec9c1505db7909fd6ca5c8263b89e8 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 21 Sep 2022 15:40:49 -0800 Subject: [PATCH 06/53] move to separate SentryDevice file; fix errno logging and add to more syscalls --- Sentry.xcodeproj/project.pbxproj | 8 + Sources/Sentry/SentryDevice.h | 27 +++ Sources/Sentry/SentryDevice.mm | 186 ++++++++++++++++++ Sources/Sentry/SentryProfiler.mm | 179 +---------------- Sources/Sentry/include/SentryLog.h | 31 +++ .../Sentry/include/SentryProfilingLogging.hpp | 17 -- 6 files changed, 253 insertions(+), 195 deletions(-) create mode 100644 Sources/Sentry/SentryDevice.h create mode 100644 Sources/Sentry/SentryDevice.mm diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index e74dfabcf1f..489207bf7b8 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -591,6 +591,8 @@ 7DC8310C2398283C0043DD9A /* SentryCrashIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DC831092398283C0043DD9A /* SentryCrashIntegration.m */; }; 8453421228BE855D00C22EEC /* SentrySampleDecision.m in Sources */ = {isa = PBXBuildFile; fileRef = 8453421128BE855D00C22EEC /* SentrySampleDecision.m */; }; 8453421628BE8A9500C22EEC /* SentrySpanStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 8453421528BE8A9500C22EEC /* SentrySpanStatus.m */; }; + 84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; }; + 84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8891B28DBD28900C51DFD /* SentryDevice.mm */; }; 861265F92404EC1500C4AFDE /* NSArray+SentrySanitize.h in Headers */ = {isa = PBXBuildFile; fileRef = 861265F72404EC1500C4AFDE /* NSArray+SentrySanitize.h */; }; 861265FA2404EC1500C4AFDE /* NSArray+SentrySanitize.m in Sources */ = {isa = PBXBuildFile; fileRef = 861265F82404EC1500C4AFDE /* NSArray+SentrySanitize.m */; }; 8E0551E026A7A63C00400526 /* TestProtocolClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E0551DF26A7A63C00400526 /* TestProtocolClient.swift */; }; @@ -1364,6 +1366,8 @@ 844DA81F28246DE300E6B62E /* scripts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = scripts; sourceTree = ""; }; 8453421128BE855D00C22EEC /* SentrySampleDecision.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySampleDecision.m; sourceTree = ""; }; 8453421528BE8A9500C22EEC /* SentrySpanStatus.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySpanStatus.m; sourceTree = ""; }; + 84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryDevice.h; sourceTree = ""; }; + 84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = ""; }; 861265F72404EC1500C4AFDE /* NSArray+SentrySanitize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "NSArray+SentrySanitize.h"; path = "include/NSArray+SentrySanitize.h"; sourceTree = ""; }; 861265F82404EC1500C4AFDE /* NSArray+SentrySanitize.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSArray+SentrySanitize.m"; sourceTree = ""; }; 8E0551DF26A7A63C00400526 /* TestProtocolClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestProtocolClient.swift; sourceTree = ""; }; @@ -1828,6 +1832,8 @@ 7B2A70DC27D6083D008B0D15 /* SentryThreadWrapper.m */, 7B18DE3F28D9F748004845C6 /* SentryNSNotificationCenterWrapper.h */, 7B18DE4128D9F794004845C6 /* SentryNSNotificationCenterWrapper.m */, + 84A8891A28DBD28900C51DFD /* SentryDevice.h */, + 84A8891B28DBD28900C51DFD /* SentryDevice.mm */, 0A9E917028DC7E7000FB4182 /* SentryInternalDefines.h */, ); name = Helper; @@ -3010,6 +3016,7 @@ 7BA235632600B61200E12865 /* SentryInternalNotificationNames.h in Headers */, 7BAF3DB9243C9777008A5414 /* SentryTransport.h in Headers */, 6383953623ABA42C000C1594 /* SentryHttpTransport.h in Headers */, + 84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */, 8E564AEF267AF24400FE117D /* SentryNetworkTracker.h in Headers */, 63FE715120DA4C1100CDBAE8 /* SentryCrashDebug.h in Headers */, 63FE70F520DA4C1000CDBAE8 /* SentryCrashMonitor_System.h in Headers */, @@ -3347,6 +3354,7 @@ 03F84D3627DD4191008FE43F /* SentryProfilingLogging.mm in Sources */, 8EC3AE7A25CA23B600E7591A /* SentrySpan.m in Sources */, 6360850E1ED2AFE100E8599E /* SentryBreadcrumb.m in Sources */, + 84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */, 7B56D73324616D9500B842DA /* SentryConcurrentRateLimitsDictionary.m in Sources */, 8ECC674825C23A20000E2BF6 /* SentryTransaction.m in Sources */, 7BECF42826145CD900D9826E /* SentryMechanismMeta.m in Sources */, diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/SentryDevice.h new file mode 100644 index 00000000000..78ce6ff5037 --- /dev/null +++ b/Sources/Sentry/SentryDevice.h @@ -0,0 +1,27 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +NSString * +getCPUArchitecture(); + + +NSString * +getOSName(); + +NSString * +getOSVersion(); + +NSString * +getDeviceModel() +; + +NSString * +getOSBuildNumber() +; + +BOOL +isSimulatorBuild() +; + +NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm new file mode 100644 index 00000000000..6c930475620 --- /dev/null +++ b/Sources/Sentry/SentryDevice.mm @@ -0,0 +1,186 @@ +#import "SentryDevice.h" +#import "SentryLog.h" +#import +#import + +namespace { + /** + * @brief Get the hardware description of the device. + * @discussion The values returned are different between iOS and macOS. Some examples of values + * returned on different devices: + * @code + * | device | machine | model | + * --------------------------------------------------------------- + * | m1 mbp | arm64 | MacBookPro18,3 | + * | iphone 13 mini | iPhone14,4 | D16AP | + * | intel imac | x86_64 | iMac20,1 | + * | iphone simulator on m1 mac | arm64 | MacBookPro18,3 | + * | iphone simulator on intel mac | x86_64 | iMac20,1 | + * @endcode + * @seealso See + * https://www.cocoawithlove.com/blog/2016/03/08/swift-wrapper-for-sysctl.html#looking-for-the-source + * for more info. + * @return @c sysctl value for the combination of @c CTL_HW and the provided other flag in the + * type parameter. + */ + NSString * + getHardwareDescription(int type) + { + int mib[2]; + char name[128]; + size_t len; + + mib[0] = CTL_HW; + mib[1] = type; + len = sizeof(name); + if (SENTRY_LOG_ERRNO(sysctl(mib, 2, &name, &len, NULL, 0)) != 0) { + return @""; + } + return [NSString stringWithUTF8String:name]; + } +} // namespace + +NSString * +getCPUArchitecture() +{ +# if SENTRY_HAS_UIKIT + + // This is provided for apps running in simulators on macs. + + size_t size; + cpu_type_t type; + cpu_subtype_t subtype; + size = sizeof(type); + NSMutableString *nameStr; + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &size, NULL, 0)) == 0) { + switch (type) { + case CPU_TYPE_X86_64: + // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the x86 branch below is taken, and then the subtype retrieved below reports the 64-bit subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) + case CPU_TYPE_X86: + nameStr = [NSMutableString stringWithString:@"x86"]; + break; + case CPU_TYPE_ARM: + nameStr = [NSMutableString stringWithString:@"arm"]; + break; + case CPU_TYPE_ARM64: + nameStr = [NSMutableString stringWithString:@"arm64"]; + break; + case CPU_TYPE_ARM64_32: + nameStr = [NSMutableString stringWithString:@"arm64_32"]; + break; + default: + return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; + } + } + + size = sizeof(subtype); + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0)) == 0) { + switch (subtype) { + default: break; + case CPU_SUBTYPE_X86_64_H: + [nameStr appendString:@"_64H"]; + break; + case CPU_SUBTYPE_X86_64_ALL: + [nameStr appendString:@"_64"]; + break; + case CPU_SUBTYPE_ARM_V6: + [nameStr appendString:@"v6"]; + break; + case CPU_SUBTYPE_ARM_V7: + [nameStr appendString:@"v7"]; + break; + case CPU_SUBTYPE_ARM_V7S: + [nameStr appendString:@"v7s"]; + break; + case CPU_SUBTYPE_ARM_V7K: + [nameStr appendString:@"v7k"]; + break; + case CPU_SUBTYPE_ARM64_V8: + // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as + // ((cpu_subtype_t) 1) + [nameStr appendString:@"v8"]; + break; + case CPU_SUBTYPE_ARM64E: + [nameStr appendString:@"e"]; + break; + } + } + + return nameStr; +# else + return getHardwareDescription(HW_MACHINE); +# endif // SENTRY_HAS_UIKIT +} + +NSString * +getOSName() +{ +# if SENTRY_HAS_UIKIT + return UIDevice.currentDevice.systemName; +# else + return @"macOS"; +# endif // SENTRY_HAS_UIKIT +} + +NSString * +getOSVersion() +{ +# if SENTRY_HAS_UIKIT + return UIDevice.currentDevice.systemVersion; +# else + // based off of + // https://github.com/lmirosevic/GBDeviceInfo/blob/98dd3c75bb0e1f87f3e0fd909e52dcf0da4aa47d/GBDeviceInfo/GBDeviceInfo_OSX.m#L107-L133 + if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { + const auto version = [[NSProcessInfo processInfo] operatingSystemVersion]; + return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion, + (long)version.minorVersion, (long)version.patchVersion]; + } else { + SInt32 major, minor, patch; + +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated-declarations" + Gestalt(gestaltSystemVersionMajor, &major); + Gestalt(gestaltSystemVersionMinor, &minor); + Gestalt(gestaltSystemVersionBugFix, &patch); +# pragma clang diagnostic pop + + return [NSString stringWithFormat:@"%d.%d.%d", major, minor, patch]; + } +# endif // SENTRY_HAS_UIKIT +} + +NSString * +getDeviceModel() +{ +# if SENTRY_HAS_UIKIT +# if TARGET_OS_SIMULATOR + return getHardwareDescription(HW_MODEL); +# else + return getHardwareDescription(HW_MACHINE); +# endif // TARGET_OS_SIMULATOR +# else + return getHardwareDescription(HW_MODEL); +# endif // SENTRY_HAS_UIKIT +} + +NSString * +getOSBuildNumber() +{ + char str[32]; + size_t size = sizeof(str); + int cmd[2] = { CTL_KERN, KERN_OSVERSION }; + if (SENTRY_LOG_ERRNO(sysctl(cmd, sizeof(cmd) / sizeof(*cmd), str, &size, NULL, 0)) == 0) { + return [NSString stringWithUTF8String:str]; + } + return @""; +} + +bool +isSimulatorBuild() +{ +# if TARGET_OS_SIMULATOR + return true; +# else + return false; +# endif +} diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 42adeb98a1a..a00e2e28c40 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -8,6 +8,7 @@ # import "SentryDebugMeta.h" # import "SentryDefines.h" # import "SentryDependencyContainer.h" +#import "SentryDevice.h" # import "SentryEnvelope.h" # import "SentryEnvelopeItemType.h" # import "SentryFramesTracker.h" @@ -15,7 +16,6 @@ # import "SentryHub.h" # import "SentryId.h" # import "SentryLog.h" -# import "SentryProfilingLogging.hpp" # import "SentrySamplingProfiler.hpp" # import "SentryScope+Private.h" # import "SentryScreenFrames.h" @@ -30,8 +30,6 @@ # import # import -# import -# import # if TARGET_OS_IOS # import @@ -60,181 +58,6 @@ return [symbolNSStr substringWithRange:[match rangeAtIndex:1]]; } -namespace { -/** - * @brief Get the hardware description of the device. - * @discussion The values returned are different between iOS and macOS. Some examples of values - * returned on different devices: - * @code - * | device | machine | model | - * --------------------------------------------------------------- - * | m1 mbp | arm64 | MacBookPro18,3 | - * | iphone 13 mini | iPhone14,4 | D16AP | - * | intel imac | x86_64 | iMac20,1 | - * | iphone simulator on m1 mac | arm64 | MacBookPro18,3 | - * | iphone simulator on intel mac | x86_64 | iMac20,1 | - * @endcode - * @seealso See - * https://www.cocoawithlove.com/blog/2016/03/08/swift-wrapper-for-sysctl.html#looking-for-the-source - * for more info. - * @return @c sysctl value for the combination of @c CTL_HW and the provided other flag in the @c - * type parameter. - */ -NSString * -getHardwareDescription(int type) -{ - int mib[2]; - char name[128]; - size_t len; - - mib[0] = CTL_HW; - mib[1] = type; - len = sizeof(name); - if (sysctl(mib, 2, &name, &len, NULL, 0) != 0) { - return @""; - } - return [NSString stringWithUTF8String:name]; -} - -NSString * -getCPUArchitecture() -{ -# if SENTRY_HAS_UIKIT - size_t size; - cpu_type_t type; - cpu_subtype_t subtype; - size = sizeof(type); - NSMutableString *nameStr; - if (sysctlbyname("hw.cputype", &type, &size, NULL, 0) == 0) { - switch (type) { - case CPU_TYPE_X86: - if (LIKELY((type & CPU_ARCH_ABI64) == CPU_ARCH_ABI64)) { - nameStr = [NSMutableString stringWithString:@"_64"]; - } else { - nameStr = [NSMutableString stringWithString:@"x86"]; - } - break; - case CPU_TYPE_ARM: - nameStr = [NSMutableString stringWithString:@"arm"]; - break; - case CPU_TYPE_ARM64: - nameStr = [NSMutableString stringWithString:@"arm64"]; - break; - case CPU_TYPE_ARM64_32: - nameStr = [NSMutableString stringWithString:@"arm64_32"]; - break; - default: - return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; - } - } - - size = sizeof(subtype); - if (sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0) == 0) { - switch (subtype) { - default: break; - case CPU_SUBTYPE_ARM_V6: - [nameStr appendString:@"v6"]; - break; - case CPU_SUBTYPE_ARM_V7: - [nameStr appendString:@"v7"]; - break; - case CPU_SUBTYPE_ARM_V7S: - [nameStr appendString:@"v7s"]; - break; - case CPU_SUBTYPE_ARM_V7K: - [nameStr appendString:@"v7k"]; - break; - case CPU_SUBTYPE_ARM64_V8: - // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as - // ((cpu_subtype_t) 1) - [nameStr appendString:@"v8"]; - break; - case CPU_SUBTYPE_ARM64E: - [nameStr appendString:@"e"]; - break; - } - } - - return nameStr; -# else - return getHardwareDescription(HW_MACHINE); -# endif // SENTRY_HAS_UIKIT -} - -NSString * -getOSName() -{ -# if SENTRY_HAS_UIKIT - return UIDevice.currentDevice.systemName; -# else - return @"macOS"; -# endif // SENTRY_HAS_UIKIT -} - -NSString * -getOSVersion() -{ -# if SENTRY_HAS_UIKIT - return UIDevice.currentDevice.systemVersion; -# else - // based off of - // https://github.com/lmirosevic/GBDeviceInfo/blob/98dd3c75bb0e1f87f3e0fd909e52dcf0da4aa47d/GBDeviceInfo/GBDeviceInfo_OSX.m#L107-L133 - if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { - const auto version = [[NSProcessInfo processInfo] operatingSystemVersion]; - return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion, - (long)version.minorVersion, (long)version.patchVersion]; - } else { - SInt32 major, minor, patch; - -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wdeprecated-declarations" - Gestalt(gestaltSystemVersionMajor, &major); - Gestalt(gestaltSystemVersionMinor, &minor); - Gestalt(gestaltSystemVersionBugFix, &patch); -# pragma clang diagnostic pop - - return [NSString stringWithFormat:@"%d.%d.%d", major, minor, patch]; - } -# endif // SENTRY_HAS_UIKIT -} - -NSString * -getDeviceModel() -{ -# if SENTRY_HAS_UIKIT -# if TARGET_OS_SIMULATOR - return getHardwareDescription(HW_MODEL); -# else - return getHardwareDescription(HW_MACHINE); -# endif // TARGET_OS_SIMULATOR -# else - return getHardwareDescription(HW_MODEL); -# endif // SENTRY_HAS_UIKIT -} - -NSString * -getOSBuildNumber() -{ - char str[32]; - size_t size = sizeof(str); - int cmd[2] = { CTL_KERN, KERN_OSVERSION }; - if (SENTRY_PROF_LOG_ERRNO(sysctl(cmd, sizeof(cmd) / sizeof(*cmd), str, &size, NULL, 0)) == 0) { - return [NSString stringWithUTF8String:str]; - } - return @""; -} - -bool -isSimulatorBuild() -{ -# if TARGET_OS_SIMULATOR - return true; -# else - return false; -# endif -} -} // namespace - @implementation SentryProfiler { NSMutableDictionary *_profile; uint64_t _startTimestamp; diff --git a/Sources/Sentry/include/SentryLog.h b/Sources/Sentry/include/SentryLog.h index 310301c07dc..c487707d938 100644 --- a/Sources/Sentry/include/SentryLog.h +++ b/Sources/Sentry/include/SentryLog.h @@ -25,3 +25,34 @@ NS_ASSUME_NONNULL_END [SentryLog logWithMessage:[NSString stringWithFormat:__VA_ARGS__] andLevel:kSentryLevelError] #define SENTRY_LOG_CRITICAL(...) \ [SentryLog logWithMessage:[NSString stringWithFormat:__VA_ARGS__] andLevel:kSentryLevelCritical] + +/** + * Logs the error code returned by executing `statement`, and returns the + * error code (i.e. returns the return value of `statement`). + */ +#define SENTRY_LOG_ERRNO_RETURN(statement) \ + ({ \ + const int __log_errnum = statement; \ + if (__log_errnum != 0) { \ + SENTRY_LOG_ERROR(@"%s failed with code: %d, description: %s", #statement, \ + __log_errnum, strerror(__log_errnum)); \ + } \ + __log_errnum; \ + }) + +/** + * If `errno` is set to a non-zero value after `statement` finishes executing, + * the error value is logged, and the original return value of `statement` is + * returned. + */ +#define SENTRY_LOG_ERRNO(statement) \ + ({ \ + errno = 0; \ + const auto __log_rv = (statement); \ + const int __log_errnum = errno; \ + if (__log_errnum != 0) { \ + SENTRY_LOG_ERROR(@"%s failed with code: %d, description: %s", #statement, \ + __log_errnum, strerror(__log_errnum)); \ + } \ + __log_rv; \ + }) diff --git a/Sources/Sentry/include/SentryProfilingLogging.hpp b/Sources/Sentry/include/SentryProfilingLogging.hpp index 3c3c67b2f20..d86a2949fbb 100644 --- a/Sources/Sentry/include/SentryProfilingLogging.hpp +++ b/Sources/Sentry/include/SentryProfilingLogging.hpp @@ -39,20 +39,3 @@ namespace profiling { } \ __log_errnum; \ }) - -/** - * If `errno` is set to a non-zero value after `statement` finishes executing, - * the error value is logged, and the original return value of `statement` is - * returned. - */ -#define SENTRY_PROF_LOG_ERRNO(statement) \ - ({ \ - errno = 0; \ - const auto __log_rv = (statement); \ - const int __log_errnum = errno; \ - if (__log_errnum != 0) { \ - SENTRY_PROF_LOG_ERROR("%s failed with code: %s, description: %s", #statement, \ - __log_errnum, std::strerror(__log_errnum)); \ - } \ - __log_rv; \ - }) From ecdd57803f243dd158c5f214f10b7f781f69e655 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 21 Sep 2022 16:33:29 -0800 Subject: [PATCH 07/53] more updates to cpu arch and add a test --- Sentry.xcodeproj/project.pbxproj | 4 + Sources/Sentry/SentryDevice.h | 12 +- Sources/Sentry/SentryDevice.mm | 147 ++++++++++-------- Tests/SentryTests/Helper/SentryDeviceTests.mm | 33 ++++ 4 files changed, 121 insertions(+), 75 deletions(-) create mode 100644 Tests/SentryTests/Helper/SentryDeviceTests.mm diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 489207bf7b8..24f160ff10e 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -593,6 +593,7 @@ 8453421628BE8A9500C22EEC /* SentrySpanStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 8453421528BE8A9500C22EEC /* SentrySpanStatus.m */; }; 84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; }; 84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8891B28DBD28900C51DFD /* SentryDevice.mm */; }; + 84A8892128DBD8D600C51DFD /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */; }; 861265F92404EC1500C4AFDE /* NSArray+SentrySanitize.h in Headers */ = {isa = PBXBuildFile; fileRef = 861265F72404EC1500C4AFDE /* NSArray+SentrySanitize.h */; }; 861265FA2404EC1500C4AFDE /* NSArray+SentrySanitize.m in Sources */ = {isa = PBXBuildFile; fileRef = 861265F82404EC1500C4AFDE /* NSArray+SentrySanitize.m */; }; 8E0551E026A7A63C00400526 /* TestProtocolClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E0551DF26A7A63C00400526 /* TestProtocolClient.swift */; }; @@ -1368,6 +1369,7 @@ 8453421528BE8A9500C22EEC /* SentrySpanStatus.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySpanStatus.m; sourceTree = ""; }; 84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryDevice.h; sourceTree = ""; }; 84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = ""; }; + 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDeviceTests.mm; sourceTree = ""; }; 861265F72404EC1500C4AFDE /* NSArray+SentrySanitize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "NSArray+SentrySanitize.h"; path = "include/NSArray+SentrySanitize.h"; sourceTree = ""; }; 861265F82404EC1500C4AFDE /* NSArray+SentrySanitize.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSArray+SentrySanitize.m"; sourceTree = ""; }; 8E0551DF26A7A63C00400526 /* TestProtocolClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestProtocolClient.swift; sourceTree = ""; }; @@ -2429,6 +2431,7 @@ 7B2A70DE27D60904008B0D15 /* SentryTestThreadWrapper.swift */, 7B18DE4328D9F8F6004845C6 /* TestNSNotificationCenterWrapper.swift */, 7B18DE4928DA0C8B004845C6 /* SentryNSNotificationCenterWrapperTests.swift */, + 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */, ); path = Helper; sourceTree = ""; @@ -3525,6 +3528,7 @@ D8FFE50C2703DBB400607131 /* SwizzlingCallTests.swift in Sources */, D8B76B0828081461000A58C4 /* TestSentryScreenShot.swift in Sources */, 7BE2C7F8257000A4003B66C7 /* SentryTestIntegration.m in Sources */, + 84A8892128DBD8D600C51DFD /* SentryDeviceTests.mm in Sources */, 7BC6EBF4255C044A0059822A /* SentryEventTests.swift in Sources */, 63FE721920DA66EC00CDBAE8 /* SentryCrashReportStore_Tests.m in Sources */, 03F9D37C2819A65C00602916 /* SentryProfilerTests.mm in Sources */, diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/SentryDevice.h index 78ce6ff5037..992a1a9306d 100644 --- a/Sources/Sentry/SentryDevice.h +++ b/Sources/Sentry/SentryDevice.h @@ -3,25 +3,25 @@ NS_ASSUME_NONNULL_BEGIN NSString * -getCPUArchitecture(); +getCPUArchitecture(void); NSString * -getOSName(); +getOSName(void); NSString * -getOSVersion(); +getOSVersion(void); NSString * -getDeviceModel() +getDeviceModel(void) ; NSString * -getOSBuildNumber() +getOSBuildNumber(void) ; BOOL -isSimulatorBuild() +isSimulatorBuild(void) ; NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 6c930475620..315096e6d5c 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -1,7 +1,9 @@ #import "SentryDevice.h" #import "SentryLog.h" #import +#if SENTRY_HAS_UIKIT #import +#endif namespace { /** @@ -38,82 +40,89 @@ } return [NSString stringWithUTF8String:name]; } -} // namespace -NSString * -getCPUArchitecture() -{ -# if SENTRY_HAS_UIKIT - - // This is provided for apps running in simulators on macs. - - size_t size; - cpu_type_t type; - cpu_subtype_t subtype; - size = sizeof(type); - NSMutableString *nameStr; - if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &size, NULL, 0)) == 0) { - switch (type) { - case CPU_TYPE_X86_64: - // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the x86 branch below is taken, and then the subtype retrieved below reports the 64-bit subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) - case CPU_TYPE_X86: - nameStr = [NSMutableString stringWithString:@"x86"]; - break; - case CPU_TYPE_ARM: - nameStr = [NSMutableString stringWithString:@"arm"]; - break; - case CPU_TYPE_ARM64: - nameStr = [NSMutableString stringWithString:@"arm64"]; - break; - case CPU_TYPE_ARM64_32: - nameStr = [NSMutableString stringWithString:@"arm64_32"]; - break; - default: - return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; +#if SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR + NSString *getArchitectureName_sysctlbyname() { + size_t size; + cpu_type_t type; + cpu_subtype_t subtype; + size = sizeof(type); + NSMutableString *nameStr; + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &size, NULL, 0)) == 0) { + switch (type) { + case CPU_TYPE_X86_64: + // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the x86 branch below is taken, and then the subtype retrieved below reports the 64-bit subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) + case CPU_TYPE_X86: + nameStr = [NSMutableString stringWithString:@"x86"]; + break; + case CPU_TYPE_ARM: + nameStr = [NSMutableString stringWithString:@"arm"]; + break; + case CPU_TYPE_ARM64: + nameStr = [NSMutableString stringWithString:@"arm64"]; + break; + case CPU_TYPE_ARM64_32: + nameStr = [NSMutableString stringWithString:@"arm64_32"]; + break; + default: + return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; + } } - } - size = sizeof(subtype); - if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0)) == 0) { - switch (subtype) { - default: break; - case CPU_SUBTYPE_X86_64_H: - [nameStr appendString:@"_64H"]; - break; - case CPU_SUBTYPE_X86_64_ALL: - [nameStr appendString:@"_64"]; - break; - case CPU_SUBTYPE_ARM_V6: - [nameStr appendString:@"v6"]; - break; - case CPU_SUBTYPE_ARM_V7: - [nameStr appendString:@"v7"]; - break; - case CPU_SUBTYPE_ARM_V7S: - [nameStr appendString:@"v7s"]; - break; - case CPU_SUBTYPE_ARM_V7K: - [nameStr appendString:@"v7k"]; - break; - case CPU_SUBTYPE_ARM64_V8: - // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as - // ((cpu_subtype_t) 1) - [nameStr appendString:@"v8"]; - break; - case CPU_SUBTYPE_ARM64E: - [nameStr appendString:@"e"]; - break; + size = sizeof(subtype); + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0)) == 0) { + switch (subtype) { + default: break; + case CPU_SUBTYPE_X86_64_H: + [nameStr appendString:@"_64H"]; + break; + case CPU_SUBTYPE_X86_64_ALL: + [nameStr appendString:@"_64"]; + break; + case CPU_SUBTYPE_ARM_V6: + [nameStr appendString:@"v6"]; + break; + case CPU_SUBTYPE_ARM_V7: + [nameStr appendString:@"v7"]; + break; + case CPU_SUBTYPE_ARM_V7S: + [nameStr appendString:@"v7s"]; + break; + case CPU_SUBTYPE_ARM_V7K: + [nameStr appendString:@"v7k"]; + break; + case CPU_SUBTYPE_ARM64_V8: + // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as + // ((cpu_subtype_t) 1) + [nameStr appendString:@"v8"]; + break; + case CPU_SUBTYPE_ARM64E: + [nameStr appendString:@"e"]; + break; + } } + + return nameStr; } +#endif // SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR +} // namespace - return nameStr; +NSString * +getCPUArchitecture(void) +{ +# if SENTRY_HAS_UIKIT +#if TARGET_OS_SIMULATOR + return getHardwareDescription(HW_MACHINE); +#else + return getArchitectureName_sysctlbyname(); +#endif // TARGET_OS_SIMULATOR # else return getHardwareDescription(HW_MACHINE); # endif // SENTRY_HAS_UIKIT } NSString * -getOSName() +getOSName(void) { # if SENTRY_HAS_UIKIT return UIDevice.currentDevice.systemName; @@ -123,7 +132,7 @@ } NSString * -getOSVersion() +getOSVersion(void) { # if SENTRY_HAS_UIKIT return UIDevice.currentDevice.systemVersion; @@ -150,7 +159,7 @@ } NSString * -getDeviceModel() +getDeviceModel(void) { # if SENTRY_HAS_UIKIT # if TARGET_OS_SIMULATOR @@ -164,7 +173,7 @@ } NSString * -getOSBuildNumber() +getOSBuildNumber(void) { char str[32]; size_t size = sizeof(str); @@ -175,8 +184,8 @@ return @""; } -bool -isSimulatorBuild() +BOOL +isSimulatorBuild(void) { # if TARGET_OS_SIMULATOR return true; diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm new file mode 100644 index 00000000000..89d8d2464d8 --- /dev/null +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -0,0 +1,33 @@ +#import +#import "SentryDefines.h" +#import "SentryDevice.h" + +@interface SentryDeviceTests : XCTestCase + +@end + +@implementation SentryDeviceTests + +- (void)testCPUArchitecture { +#if SENTRY_HAS_UIKIT +#if TARGET_OS_SIMULATOR + [self assertMacCPU:getCPUArchitecture()]; +#else + XCTAssert([getCPUArchitecture() containsString:@"arm"]); +#endif +#else + [self assertMacCPU:getCPUArchitecture()]; +#endif +} + +- (void)assertMacCPU:(NSString *)arch { +#if TARGET_CPU_X86_64 + XCTAssertEqual(arch, @"x86_64"); +#elif TARGET_CPU_ARM64 + XCTAssert([arch containsString:@"arm64"]); +#else + XCTFail(@"Unexpected target CPU"); +#endif +} + +@end From 4c203f5393b8677601104769cd3cbbd158d2ec08 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 22 Sep 2022 00:40:33 +0000 Subject: [PATCH 08/53] Format code --- Sources/Sentry/SentryDevice.h | 22 +- Sources/Sentry/SentryDevice.mm | 235 +++++++++--------- Sources/Sentry/SentryProfiler.mm | 2 +- Sources/Sentry/include/SentryLog.h | 12 +- Tests/SentryTests/Helper/SentryDeviceTests.mm | 14 +- 5 files changed, 141 insertions(+), 144 deletions(-) diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/SentryDevice.h index 992a1a9306d..e385854c4e4 100644 --- a/Sources/Sentry/SentryDevice.h +++ b/Sources/Sentry/SentryDevice.h @@ -2,26 +2,16 @@ NS_ASSUME_NONNULL_BEGIN -NSString * -getCPUArchitecture(void); +NSString *getCPUArchitecture(void); +NSString *getOSName(void); -NSString * -getOSName(void); +NSString *getOSVersion(void); -NSString * -getOSVersion(void); +NSString *getDeviceModel(void); -NSString * -getDeviceModel(void) -; +NSString *getOSBuildNumber(void); -NSString * -getOSBuildNumber(void) -; - -BOOL -isSimulatorBuild(void) -; +BOOL isSimulatorBuild(void); NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 315096e6d5c..0f06b762ab0 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -2,141 +2,146 @@ #import "SentryLog.h" #import #if SENTRY_HAS_UIKIT -#import +# import #endif namespace { - /** - * @brief Get the hardware description of the device. - * @discussion The values returned are different between iOS and macOS. Some examples of values - * returned on different devices: - * @code - * | device | machine | model | - * --------------------------------------------------------------- - * | m1 mbp | arm64 | MacBookPro18,3 | - * | iphone 13 mini | iPhone14,4 | D16AP | - * | intel imac | x86_64 | iMac20,1 | - * | iphone simulator on m1 mac | arm64 | MacBookPro18,3 | - * | iphone simulator on intel mac | x86_64 | iMac20,1 | - * @endcode - * @seealso See - * https://www.cocoawithlove.com/blog/2016/03/08/swift-wrapper-for-sysctl.html#looking-for-the-source - * for more info. - * @return @c sysctl value for the combination of @c CTL_HW and the provided other flag in the - * type parameter. - */ - NSString * - getHardwareDescription(int type) - { - int mib[2]; - char name[128]; - size_t len; +/** + * @brief Get the hardware description of the device. + * @discussion The values returned are different between iOS and macOS. Some examples of values + * returned on different devices: + * @code + * | device | machine | model | + * --------------------------------------------------------------- + * | m1 mbp | arm64 | MacBookPro18,3 | + * | iphone 13 mini | iPhone14,4 | D16AP | + * | intel imac | x86_64 | iMac20,1 | + * | iphone simulator on m1 mac | arm64 | MacBookPro18,3 | + * | iphone simulator on intel mac | x86_64 | iMac20,1 | + * @endcode + * @seealso See + * https://www.cocoawithlove.com/blog/2016/03/08/swift-wrapper-for-sysctl.html#looking-for-the-source + * for more info. + * @return @c sysctl value for the combination of @c CTL_HW and the provided other flag in the + * type parameter. + */ +NSString * +getHardwareDescription(int type) +{ + int mib[2]; + char name[128]; + size_t len; - mib[0] = CTL_HW; - mib[1] = type; - len = sizeof(name); - if (SENTRY_LOG_ERRNO(sysctl(mib, 2, &name, &len, NULL, 0)) != 0) { - return @""; - } - return [NSString stringWithUTF8String:name]; + mib[0] = CTL_HW; + mib[1] = type; + len = sizeof(name); + if (SENTRY_LOG_ERRNO(sysctl(mib, 2, &name, &len, NULL, 0)) != 0) { + return @""; } + return [NSString stringWithUTF8String:name]; +} #if SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR - NSString *getArchitectureName_sysctlbyname() { - size_t size; - cpu_type_t type; - cpu_subtype_t subtype; - size = sizeof(type); - NSMutableString *nameStr; - if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &size, NULL, 0)) == 0) { - switch (type) { - case CPU_TYPE_X86_64: - // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the x86 branch below is taken, and then the subtype retrieved below reports the 64-bit subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) - case CPU_TYPE_X86: - nameStr = [NSMutableString stringWithString:@"x86"]; - break; - case CPU_TYPE_ARM: - nameStr = [NSMutableString stringWithString:@"arm"]; - break; - case CPU_TYPE_ARM64: - nameStr = [NSMutableString stringWithString:@"arm64"]; - break; - case CPU_TYPE_ARM64_32: - nameStr = [NSMutableString stringWithString:@"arm64_32"]; - break; - default: - return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; - } +NSString * +getArchitectureName_sysctlbyname() +{ + size_t size; + cpu_type_t type; + cpu_subtype_t subtype; + size = sizeof(type); + NSMutableString *nameStr; + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &size, NULL, 0)) == 0) { + switch (type) { + case CPU_TYPE_X86_64: + // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the + // x86 branch below is taken, and then the subtype retrieved below reports the 64-bit + // subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) + case CPU_TYPE_X86: + nameStr = [NSMutableString stringWithString:@"x86"]; + break; + case CPU_TYPE_ARM: + nameStr = [NSMutableString stringWithString:@"arm"]; + break; + case CPU_TYPE_ARM64: + nameStr = [NSMutableString stringWithString:@"arm64"]; + break; + case CPU_TYPE_ARM64_32: + nameStr = [NSMutableString stringWithString:@"arm64_32"]; + break; + default: + return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; } + } - size = sizeof(subtype); - if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0)) == 0) { - switch (subtype) { - default: break; - case CPU_SUBTYPE_X86_64_H: - [nameStr appendString:@"_64H"]; - break; - case CPU_SUBTYPE_X86_64_ALL: - [nameStr appendString:@"_64"]; - break; - case CPU_SUBTYPE_ARM_V6: - [nameStr appendString:@"v6"]; - break; - case CPU_SUBTYPE_ARM_V7: - [nameStr appendString:@"v7"]; - break; - case CPU_SUBTYPE_ARM_V7S: - [nameStr appendString:@"v7s"]; - break; - case CPU_SUBTYPE_ARM_V7K: - [nameStr appendString:@"v7k"]; - break; - case CPU_SUBTYPE_ARM64_V8: - // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as - // ((cpu_subtype_t) 1) - [nameStr appendString:@"v8"]; - break; - case CPU_SUBTYPE_ARM64E: - [nameStr appendString:@"e"]; - break; - } + size = sizeof(subtype); + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0)) == 0) { + switch (subtype) { + default: + break; + case CPU_SUBTYPE_X86_64_H: + [nameStr appendString:@"_64H"]; + break; + case CPU_SUBTYPE_X86_64_ALL: + [nameStr appendString:@"_64"]; + break; + case CPU_SUBTYPE_ARM_V6: + [nameStr appendString:@"v6"]; + break; + case CPU_SUBTYPE_ARM_V7: + [nameStr appendString:@"v7"]; + break; + case CPU_SUBTYPE_ARM_V7S: + [nameStr appendString:@"v7s"]; + break; + case CPU_SUBTYPE_ARM_V7K: + [nameStr appendString:@"v7k"]; + break; + case CPU_SUBTYPE_ARM64_V8: + // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as + // ((cpu_subtype_t) 1) + [nameStr appendString:@"v8"]; + break; + case CPU_SUBTYPE_ARM64E: + [nameStr appendString:@"e"]; + break; } - - return nameStr; } + + return nameStr; +} #endif // SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR } // namespace NSString * getCPUArchitecture(void) { -# if SENTRY_HAS_UIKIT -#if TARGET_OS_SIMULATOR +#if SENTRY_HAS_UIKIT +# if TARGET_OS_SIMULATOR return getHardwareDescription(HW_MACHINE); -#else - return getArchitectureName_sysctlbyname(); -#endif // TARGET_OS_SIMULATOR # else + return getArchitectureName_sysctlbyname(); +# endif // TARGET_OS_SIMULATOR +#else return getHardwareDescription(HW_MACHINE); -# endif // SENTRY_HAS_UIKIT +#endif // SENTRY_HAS_UIKIT } NSString * getOSName(void) { -# if SENTRY_HAS_UIKIT +#if SENTRY_HAS_UIKIT return UIDevice.currentDevice.systemName; -# else +#else return @"macOS"; -# endif // SENTRY_HAS_UIKIT +#endif // SENTRY_HAS_UIKIT } NSString * getOSVersion(void) { -# if SENTRY_HAS_UIKIT +#if SENTRY_HAS_UIKIT return UIDevice.currentDevice.systemVersion; -# else +#else // based off of // https://github.com/lmirosevic/GBDeviceInfo/blob/98dd3c75bb0e1f87f3e0fd909e52dcf0da4aa47d/GBDeviceInfo/GBDeviceInfo_OSX.m#L107-L133 if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { @@ -146,30 +151,30 @@ } else { SInt32 major, minor, patch; -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wdeprecated-declarations" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated-declarations" Gestalt(gestaltSystemVersionMajor, &major); Gestalt(gestaltSystemVersionMinor, &minor); Gestalt(gestaltSystemVersionBugFix, &patch); -# pragma clang diagnostic pop +# pragma clang diagnostic pop return [NSString stringWithFormat:@"%d.%d.%d", major, minor, patch]; } -# endif // SENTRY_HAS_UIKIT +#endif // SENTRY_HAS_UIKIT } NSString * getDeviceModel(void) { -# if SENTRY_HAS_UIKIT -# if TARGET_OS_SIMULATOR +#if SENTRY_HAS_UIKIT +# if TARGET_OS_SIMULATOR return getHardwareDescription(HW_MODEL); -# else - return getHardwareDescription(HW_MACHINE); -# endif // TARGET_OS_SIMULATOR # else + return getHardwareDescription(HW_MACHINE); +# endif // TARGET_OS_SIMULATOR +#else return getHardwareDescription(HW_MODEL); -# endif // SENTRY_HAS_UIKIT +#endif // SENTRY_HAS_UIKIT } NSString * @@ -187,9 +192,9 @@ BOOL isSimulatorBuild(void) { -# if TARGET_OS_SIMULATOR +#if TARGET_OS_SIMULATOR return true; -# else +#else return false; -# endif +#endif } diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index a00e2e28c40..c196af12960 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -8,7 +8,7 @@ # import "SentryDebugMeta.h" # import "SentryDefines.h" # import "SentryDependencyContainer.h" -#import "SentryDevice.h" +# import "SentryDevice.h" # import "SentryEnvelope.h" # import "SentryEnvelopeItemType.h" # import "SentryFramesTracker.h" diff --git a/Sources/Sentry/include/SentryLog.h b/Sources/Sentry/include/SentryLog.h index c487707d938..14840579aff 100644 --- a/Sources/Sentry/include/SentryLog.h +++ b/Sources/Sentry/include/SentryLog.h @@ -30,12 +30,12 @@ NS_ASSUME_NONNULL_END * Logs the error code returned by executing `statement`, and returns the * error code (i.e. returns the return value of `statement`). */ -#define SENTRY_LOG_ERRNO_RETURN(statement) \ +#define SENTRY_LOG_ERRNO_RETURN(statement) \ ({ \ const int __log_errnum = statement; \ if (__log_errnum != 0) { \ - SENTRY_LOG_ERROR(@"%s failed with code: %d, description: %s", #statement, \ - __log_errnum, strerror(__log_errnum)); \ + SENTRY_LOG_ERROR(@"%s failed with code: %d, description: %s", #statement, \ + __log_errnum, strerror(__log_errnum)); \ } \ __log_errnum; \ }) @@ -45,14 +45,14 @@ NS_ASSUME_NONNULL_END * the error value is logged, and the original return value of `statement` is * returned. */ -#define SENTRY_LOG_ERRNO(statement) \ +#define SENTRY_LOG_ERRNO(statement) \ ({ \ errno = 0; \ const auto __log_rv = (statement); \ const int __log_errnum = errno; \ if (__log_errnum != 0) { \ - SENTRY_LOG_ERROR(@"%s failed with code: %d, description: %s", #statement, \ - __log_errnum, strerror(__log_errnum)); \ + SENTRY_LOG_ERROR(@"%s failed with code: %d, description: %s", #statement, \ + __log_errnum, strerror(__log_errnum)); \ } \ __log_rv; \ }) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 89d8d2464d8..61560111352 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -1,6 +1,6 @@ -#import #import "SentryDefines.h" #import "SentryDevice.h" +#import @interface SentryDeviceTests : XCTestCase @@ -8,19 +8,21 @@ @interface SentryDeviceTests : XCTestCase @implementation SentryDeviceTests -- (void)testCPUArchitecture { +- (void)testCPUArchitecture +{ #if SENTRY_HAS_UIKIT -#if TARGET_OS_SIMULATOR +# if TARGET_OS_SIMULATOR [self assertMacCPU:getCPUArchitecture()]; -#else +# else XCTAssert([getCPUArchitecture() containsString:@"arm"]); -#endif +# endif #else [self assertMacCPU:getCPUArchitecture()]; #endif } -- (void)assertMacCPU:(NSString *)arch { +- (void)assertMacCPU:(NSString *)arch +{ #if TARGET_CPU_X86_64 XCTAssertEqual(arch, @"x86_64"); #elif TARGET_CPU_ARM64 From e1a4c6d753d2582c83a094861bee507b287bc10d Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 21 Sep 2022 16:49:18 -0800 Subject: [PATCH 09/53] remove unused macro --- Sources/Sentry/include/SentryLog.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Sources/Sentry/include/SentryLog.h b/Sources/Sentry/include/SentryLog.h index 14840579aff..520690ff83e 100644 --- a/Sources/Sentry/include/SentryLog.h +++ b/Sources/Sentry/include/SentryLog.h @@ -26,20 +26,6 @@ NS_ASSUME_NONNULL_END #define SENTRY_LOG_CRITICAL(...) \ [SentryLog logWithMessage:[NSString stringWithFormat:__VA_ARGS__] andLevel:kSentryLevelCritical] -/** - * Logs the error code returned by executing `statement`, and returns the - * error code (i.e. returns the return value of `statement`). - */ -#define SENTRY_LOG_ERRNO_RETURN(statement) \ - ({ \ - const int __log_errnum = statement; \ - if (__log_errnum != 0) { \ - SENTRY_LOG_ERROR(@"%s failed with code: %d, description: %s", #statement, \ - __log_errnum, strerror(__log_errnum)); \ - } \ - __log_errnum; \ - }) - /** * If `errno` is set to a non-zero value after `statement` finishes executing, * the error value is logged, and the original return value of `statement` is From 664579025af2b1e9479f8e4c4d04c89aaab78d82 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 21 Sep 2022 20:58:22 -0800 Subject: [PATCH 10/53] refactor architecture checks; fix availability of HW_PRODUCT for macos; add simulated_device identifier --- Sources/Sentry/SentryDevice.mm | 118 ++++++++++++++----------------- Sources/Sentry/SentryProfiler.mm | 3 + 2 files changed, 55 insertions(+), 66 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 0f06b762ab0..2cc04f5d276 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -7,8 +7,9 @@ namespace { /** - * @brief Get the hardware description of the device. - * @discussion The values returned are different between iOS and macOS. Some examples of values + * @brief Get an iOS hardware model name, or for mac devices, either the hardware model name or CPU architecture of the device, depending on the option provided. + * @note For an iOS CPU architecture name, `getArchitectureName` must be used. + * @discussion The values returned are different between iOS and macOS depending on which option is provided. Some examples of values * returned on different devices: * @code * | device | machine | model | @@ -41,89 +42,68 @@ return [NSString stringWithUTF8String:name]; } -#if SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR -NSString * -getArchitectureName_sysctlbyname() -{ - size_t size; +NSString *getCPUType(NSNumber *_Nullable subtype) { cpu_type_t type; - cpu_subtype_t subtype; - size = sizeof(type); - NSMutableString *nameStr; - if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &size, NULL, 0)) == 0) { - switch (type) { + size_t typeSize = sizeof(type); + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &typeSize, NULL, 0)) != 0) { + if (subtype != nil) { + return [NSString stringWithFormat:@"no CPU type for unknown subtype %d", subtype.intValue]; + } + return @"no CPU type or subtype"; + } + switch (type) { + default: + if (subtype != nil) { + return [NSMutableString stringWithFormat:@"unknown CPU type (%d) and subtype (%d)", type, subtype.intValue]; + } + return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; case CPU_TYPE_X86_64: // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the - // x86 branch below is taken, and then the subtype retrieved below reports the 64-bit + // x86 branch is taken, and then the subtype is reported as the 64-bit // subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) + return @"x86_64"; case CPU_TYPE_X86: - nameStr = [NSMutableString stringWithString:@"x86"]; - break; + return @"x86"; case CPU_TYPE_ARM: - nameStr = [NSMutableString stringWithString:@"arm"]; - break; + return @"arm"; case CPU_TYPE_ARM64: - nameStr = [NSMutableString stringWithString:@"arm64"]; - break; + return @"arm64"; case CPU_TYPE_ARM64_32: - nameStr = [NSMutableString stringWithString:@"arm64_32"]; - break; - default: - return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; - } + return @"arm64_32"; } +} +} // namespace - size = sizeof(subtype); - if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0)) == 0) { - switch (subtype) { +NSString * +getCPUArchitecture(void) +{ + cpu_subtype_t subtype; + size_t subtypeSize = sizeof(subtype); + if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cpusubtype", &subtype, &subtypeSize, NULL, 0)) != 0) { + return getCPUType(nil); + } + switch (subtype) { default: - break; + return getCPUType(@(subtype)); case CPU_SUBTYPE_X86_64_H: - [nameStr appendString:@"_64H"]; - break; + return @"x86_64H"; case CPU_SUBTYPE_X86_64_ALL: - [nameStr appendString:@"_64"]; - break; + return @"x86_64"; case CPU_SUBTYPE_ARM_V6: - [nameStr appendString:@"v6"]; - break; + return @"armv6"; case CPU_SUBTYPE_ARM_V7: - [nameStr appendString:@"v7"]; - break; + return @"armv7"; case CPU_SUBTYPE_ARM_V7S: - [nameStr appendString:@"v7s"]; - break; + return @"armv7s"; case CPU_SUBTYPE_ARM_V7K: - [nameStr appendString:@"v7k"]; - break; + return @"armv7k"; case CPU_SUBTYPE_ARM64_V8: // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as // ((cpu_subtype_t) 1) - [nameStr appendString:@"v8"]; - break; + return @"armv8"; case CPU_SUBTYPE_ARM64E: - [nameStr appendString:@"e"]; - break; - } + return @"arm64e"; } - - return nameStr; -} -#endif // SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR -} // namespace - -NSString * -getCPUArchitecture(void) -{ -#if SENTRY_HAS_UIKIT -# if TARGET_OS_SIMULATOR - return getHardwareDescription(HW_MACHINE); -# else - return getArchitectureName_sysctlbyname(); -# endif // TARGET_OS_SIMULATOR -#else - return getHardwareDescription(HW_MACHINE); -#endif // SENTRY_HAS_UIKIT } NSString * @@ -166,14 +146,20 @@ NSString * getDeviceModel(void) { +#if defined(HW_PRODUCT) + if(@available(iOS 14, macOS 11, *)) { + return getHardwareDescription(HW_PRODUCT); + } +#endif // defined(HW_PRODUCT) + #if SENTRY_HAS_UIKIT # if TARGET_OS_SIMULATOR - return getHardwareDescription(HW_MODEL); + return getHardwareDescription(HW_MODEL); # else - return getHardwareDescription(HW_MACHINE); + return getHardwareDescription(HW_MACHINE); # endif // TARGET_OS_SIMULATOR #else - return getHardwareDescription(HW_MODEL); + return getHardwareDescription(HW_MODEL); #endif // SENTRY_HAS_UIKIT } diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index c196af12960..2eef0725136 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -213,6 +213,9 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"device_manufacturer"] = @"Apple"; profile[@"device_model"] = getDeviceModel(); profile[@"device_os_build_number"] = getOSBuildNumber(); +#if SENTRY_HAS_UIKIT && TARGET_OS_SIMULATOR + profile[@"simulated_device"] = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; +#endif profile[@"device_os_name"] = getOSName(); profile[@"device_os_version"] = getOSVersion(); profile[@"device_is_emulator"] = @(isSimulatorBuild()); From f48a0658624a0f0362019c9f9364e2c67fc7c55f Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 22 Sep 2022 04:59:14 +0000 Subject: [PATCH 11/53] Format code --- Sources/Sentry/SentryDevice.mm | 99 +++++++++++++++++--------------- Sources/Sentry/SentryProfiler.mm | 7 ++- 2 files changed, 56 insertions(+), 50 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 2cc04f5d276..2dbce4af101 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -7,10 +7,11 @@ namespace { /** - * @brief Get an iOS hardware model name, or for mac devices, either the hardware model name or CPU architecture of the device, depending on the option provided. + * @brief Get an iOS hardware model name, or for mac devices, either the hardware model name or CPU + * architecture of the device, depending on the option provided. * @note For an iOS CPU architecture name, `getArchitectureName` must be used. - * @discussion The values returned are different between iOS and macOS depending on which option is provided. Some examples of values - * returned on different devices: + * @discussion The values returned are different between iOS and macOS depending on which option is + * provided. Some examples of values returned on different devices: * @code * | device | machine | model | * --------------------------------------------------------------- @@ -42,34 +43,38 @@ return [NSString stringWithUTF8String:name]; } -NSString *getCPUType(NSNumber *_Nullable subtype) { +NSString * +getCPUType(NSNumber *_Nullable subtype) +{ cpu_type_t type; size_t typeSize = sizeof(type); if (SENTRY_LOG_ERRNO(sysctlbyname("hw.cputype", &type, &typeSize, NULL, 0)) != 0) { if (subtype != nil) { - return [NSString stringWithFormat:@"no CPU type for unknown subtype %d", subtype.intValue]; + return + [NSString stringWithFormat:@"no CPU type for unknown subtype %d", subtype.intValue]; } return @"no CPU type or subtype"; } switch (type) { - default: - if (subtype != nil) { - return [NSMutableString stringWithFormat:@"unknown CPU type (%d) and subtype (%d)", type, subtype.intValue]; - } - return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; - case CPU_TYPE_X86_64: - // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the - // x86 branch is taken, and then the subtype is reported as the 64-bit - // subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) - return @"x86_64"; - case CPU_TYPE_X86: - return @"x86"; - case CPU_TYPE_ARM: - return @"arm"; - case CPU_TYPE_ARM64: - return @"arm64"; - case CPU_TYPE_ARM64_32: - return @"arm64_32"; + default: + if (subtype != nil) { + return [NSMutableString + stringWithFormat:@"unknown CPU type (%d) and subtype (%d)", type, subtype.intValue]; + } + return [NSMutableString stringWithFormat:@"unknown CPU type (%d)", type]; + case CPU_TYPE_X86_64: + // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the + // x86 branch is taken, and then the subtype is reported as the 64-bit + // subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) + return @"x86_64"; + case CPU_TYPE_X86: + return @"x86"; + case CPU_TYPE_ARM: + return @"arm"; + case CPU_TYPE_ARM64: + return @"arm64"; + case CPU_TYPE_ARM64_32: + return @"arm64_32"; } } } // namespace @@ -83,26 +88,26 @@ return getCPUType(nil); } switch (subtype) { - default: - return getCPUType(@(subtype)); - case CPU_SUBTYPE_X86_64_H: - return @"x86_64H"; - case CPU_SUBTYPE_X86_64_ALL: - return @"x86_64"; - case CPU_SUBTYPE_ARM_V6: - return @"armv6"; - case CPU_SUBTYPE_ARM_V7: - return @"armv7"; - case CPU_SUBTYPE_ARM_V7S: - return @"armv7s"; - case CPU_SUBTYPE_ARM_V7K: - return @"armv7k"; - case CPU_SUBTYPE_ARM64_V8: - // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as - // ((cpu_subtype_t) 1) - return @"armv8"; - case CPU_SUBTYPE_ARM64E: - return @"arm64e"; + default: + return getCPUType(@(subtype)); + case CPU_SUBTYPE_X86_64_H: + return @"x86_64H"; + case CPU_SUBTYPE_X86_64_ALL: + return @"x86_64"; + case CPU_SUBTYPE_ARM_V6: + return @"armv6"; + case CPU_SUBTYPE_ARM_V7: + return @"armv7"; + case CPU_SUBTYPE_ARM_V7S: + return @"armv7s"; + case CPU_SUBTYPE_ARM_V7K: + return @"armv7k"; + case CPU_SUBTYPE_ARM64_V8: + // this also catches CPU_SUBTYPE_ARM64_32_V8 since they are both defined as + // ((cpu_subtype_t) 1) + return @"armv8"; + case CPU_SUBTYPE_ARM64E: + return @"arm64e"; } } @@ -147,19 +152,19 @@ getDeviceModel(void) { #if defined(HW_PRODUCT) - if(@available(iOS 14, macOS 11, *)) { + if (@available(iOS 14, macOS 11, *)) { return getHardwareDescription(HW_PRODUCT); } #endif // defined(HW_PRODUCT) #if SENTRY_HAS_UIKIT # if TARGET_OS_SIMULATOR - return getHardwareDescription(HW_MODEL); + return getHardwareDescription(HW_MODEL); # else - return getHardwareDescription(HW_MACHINE); + return getHardwareDescription(HW_MACHINE); # endif // TARGET_OS_SIMULATOR #else - return getHardwareDescription(HW_MODEL); + return getHardwareDescription(HW_MODEL); #endif // SENTRY_HAS_UIKIT } diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 2eef0725136..a7325146497 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -213,9 +213,10 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"device_manufacturer"] = @"Apple"; profile[@"device_model"] = getDeviceModel(); profile[@"device_os_build_number"] = getOSBuildNumber(); -#if SENTRY_HAS_UIKIT && TARGET_OS_SIMULATOR - profile[@"simulated_device"] = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; -#endif +# if SENTRY_HAS_UIKIT && TARGET_OS_SIMULATOR + profile[@"simulated_device"] + = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; +# endif profile[@"device_os_name"] = getOSName(); profile[@"device_os_version"] = getOSVersion(); profile[@"device_is_emulator"] = @(isSimulatorBuild()); From ab95fd7c484e3125711687d7e8d9912e66a0bef0 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 22 Sep 2022 15:28:30 -0800 Subject: [PATCH 12/53] run test in iOS-SwiftUITests as well --- Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj | 10 ++++++++++ Sources/Sentry/SentryDevice.mm | 11 ++++++++++- Tests/SentryTests/Helper/SentryDeviceTests.mm | 11 ++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj index b8f2cc0e2d9..6203e5143ba 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ 848A256B286E3351008A8858 /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 630853322440C44F00DDE4CE /* Sentry.framework */; }; 848A256D286E3351008A8858 /* fatal-error-binary-images-message2.json in Resources */ = {isa = PBXBuildFile; fileRef = D83A30DF279F1F5C00372D0A /* fatal-error-binary-images-message2.json */; }; 848A256F286E3351008A8858 /* Sentry.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 630853322440C44F00DDE4CE /* Sentry.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; + 84B527B928DD24BA00475E8D /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84B527B728DD24BA00475E8D /* SentryDeviceTests.mm */; }; + 84B527BD28DD25E400475E8D /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84B527BC28DD25E400475E8D /* SentryDevice.mm */; }; 84BE546F287503F100ACC735 /* SentrySDKPerformanceBenchmarkTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 84BE546E287503F100ACC735 /* SentrySDKPerformanceBenchmarkTests.m */; }; 84BE547E287645B900ACC735 /* SentryProcessInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 84BE54792876451D00ACC735 /* SentryProcessInfo.m */; }; 84FB8120283EEDB900F3A94A /* PerformanceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FB811F283EEDB900F3A94A /* PerformanceViewController.swift */; }; @@ -241,6 +243,9 @@ 7BFC8B0526D4D24B000D3504 /* LoremIpsum.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LoremIpsum.txt; sourceTree = ""; }; 848A2573286E3351008A8858 /* PerformanceBenchmarks.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PerformanceBenchmarks.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 848A2578286E3490008A8858 /* PerformanceBenchmarks-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PerformanceBenchmarks-Info.plist"; sourceTree = ""; }; + 84B527B728DD24BA00475E8D /* SentryDeviceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDeviceTests.mm; path = ../../../Tests/SentryTests/Helper/SentryDeviceTests.mm; sourceTree = ""; }; + 84B527BB28DD25E400475E8D /* SentryDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = ../../../Sources/Sentry/SentryDevice.h; sourceTree = ""; }; + 84B527BC28DD25E400475E8D /* SentryDevice.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDevice.mm; path = ../../../Sources/Sentry/SentryDevice.mm; sourceTree = ""; }; 84BE546E287503F100ACC735 /* SentrySDKPerformanceBenchmarkTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySDKPerformanceBenchmarkTests.m; sourceTree = ""; }; 84BE54782876451D00ACC735 /* SentryProcessInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryProcessInfo.h; sourceTree = ""; }; 84BE54792876451D00ACC735 /* SentryProcessInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryProcessInfo.m; sourceTree = ""; }; @@ -411,6 +416,9 @@ D83A30DF279F1F5C00372D0A /* fatal-error-binary-images-message2.json */, 7B64386A26A6C544000D0F65 /* LaunchUITests.swift */, D83A30E5279FE21F00372D0A /* SentryFileIOTrackingIntegrationTests.swift */, + 84B527B728DD24BA00475E8D /* SentryDeviceTests.mm */, + 84B527BB28DD25E400475E8D /* SentryDevice.h */, + 84B527BC28DD25E400475E8D /* SentryDevice.mm */, D83A30C7279EFD6E00372D0A /* ClearTestState.swift */, 7B64386C26A6C544000D0F65 /* Info.plist */, ); @@ -804,8 +812,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 84B527B928DD24BA00475E8D /* SentryDeviceTests.mm in Sources */, D83A30E6279FE21F00372D0A /* SentryFileIOTrackingIntegrationTests.swift in Sources */, 7B64386B26A6C544000D0F65 /* LaunchUITests.swift in Sources */, + 84B527BD28DD25E400475E8D /* SentryDevice.mm in Sources */, D83A30C8279EFD6E00372D0A /* ClearTestState.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 2dbce4af101..35351ecbb29 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -1,5 +1,14 @@ -#import "SentryDevice.h" +// This file is also compiled into iOS-SwiftUITests and doesn't have access to private Sentry API there, so we fix up a few things here. +#if !defined(SENTRY_HAS_UIKIT) +#define SENTRY_HAS_UIKIT (TARGET_OS_IOS || TARGET_OS_TV) +#endif +#if defined(SENTRY_LOG_ERRNO) #import "SentryLog.h" +#else +#define SENTRY_LOG_ERRNO(statement) statement +#endif + +#import "SentryDevice.h" #import #if SENTRY_HAS_UIKIT # import diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 61560111352..a9d4cc909ff 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -1,4 +1,3 @@ -#import "SentryDefines.h" #import "SentryDevice.h" #import @@ -10,11 +9,13 @@ @implementation SentryDeviceTests - (void)testCPUArchitecture { -#if SENTRY_HAS_UIKIT +#if TARGET_OS_IOS || TARGET_OS_TV # if TARGET_OS_SIMULATOR [self assertMacCPU:getCPUArchitecture()]; # else - XCTAssert([getCPUArchitecture() containsString:@"arm"]); + // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests cannot. + NSString *arch = getCPUArchitecture(); + XCTAssert([arch containsString:@"arm"], @"Expected an arm architecture but got '%@'", arch); # endif #else [self assertMacCPU:getCPUArchitecture()]; @@ -24,9 +25,9 @@ - (void)testCPUArchitecture - (void)assertMacCPU:(NSString *)arch { #if TARGET_CPU_X86_64 - XCTAssertEqual(arch, @"x86_64"); + XCTAssert([arch isEqualToString:@"x86_64"], @"Expected 'x86_64' but got '%@'", arch); #elif TARGET_CPU_ARM64 - XCTAssert([arch containsString:@"arm64"]); + XCTAssert([arch containsString:@"arm64"], @"Expected an arm64 arch but got '%@'", arch); #else XCTFail(@"Unexpected target CPU"); #endif From cabcd164d05689c8d08bda40118da53bd82a0d97 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 22 Sep 2022 23:36:05 +0000 Subject: [PATCH 13/53] Format code --- Sources/Sentry/SentryDevice.mm | 9 +++++---- Tests/SentryTests/Helper/SentryDeviceTests.mm | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 35351ecbb29..4225de3d6d3 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -1,11 +1,12 @@ -// This file is also compiled into iOS-SwiftUITests and doesn't have access to private Sentry API there, so we fix up a few things here. +// This file is also compiled into iOS-SwiftUITests and doesn't have access to private Sentry API +// there, so we fix up a few things here. #if !defined(SENTRY_HAS_UIKIT) -#define SENTRY_HAS_UIKIT (TARGET_OS_IOS || TARGET_OS_TV) +# define SENTRY_HAS_UIKIT (TARGET_OS_IOS || TARGET_OS_TV) #endif #if defined(SENTRY_LOG_ERRNO) -#import "SentryLog.h" +# import "SentryLog.h" #else -#define SENTRY_LOG_ERRNO(statement) statement +# define SENTRY_LOG_ERRNO(statement) statement #endif #import "SentryDevice.h" diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index a9d4cc909ff..74d6fefe258 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -13,7 +13,8 @@ - (void)testCPUArchitecture # if TARGET_OS_SIMULATOR [self assertMacCPU:getCPUArchitecture()]; # else - // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests cannot. + // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests + // cannot. NSString *arch = getCPUArchitecture(); XCTAssert([arch containsString:@"arm"], @"Expected an arm architecture but got '%@'", arch); # endif From 0bdd9d5127ac1af1ac9119d311aac8676e771ea8 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 22 Sep 2022 15:44:41 -0800 Subject: [PATCH 14/53] prevent nil in profiler payload; assert option for CPU arch on iOS devices --- Sources/Sentry/SentryDevice.mm | 3 +++ Sources/Sentry/SentryProfiler.mm | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 4225de3d6d3..c2a7e4387c0 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -40,6 +40,9 @@ NSString * getHardwareDescription(int type) { +#if SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR + NSCAssert(type != HW_MODEL, @"Don't call this method with HW_MODEL for (non-simulator) iOS devices"); +#endif int mib[2]; char name[128]; size_t len; diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index a7325146497..e3846a9915c 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -213,9 +213,11 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"device_manufacturer"] = @"Apple"; profile[@"device_model"] = getDeviceModel(); profile[@"device_os_build_number"] = getOSBuildNumber(); -# if SENTRY_HAS_UIKIT && TARGET_OS_SIMULATOR - profile[@"simulated_device"] - = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; +# if TARGET_OS_SIMULATOR + const auto simulatedDevice = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; + if (simulatedDevice != nil) { + profile[@"simulated_device"] = simulatedDevice; + } # endif profile[@"device_os_name"] = getOSName(); profile[@"device_os_version"] = getOSVersion(); From 3f31f75b6a2690f5b3f3f69372c2882cb622f2b5 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 22 Sep 2022 16:13:56 -0800 Subject: [PATCH 15/53] add/update comments --- Sources/Sentry/SentryDevice.mm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index c2a7e4387c0..473b31c5c8c 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -56,6 +56,18 @@ return [NSString stringWithUTF8String:name]; } +/** + * Provided as a fallback in case @c sysctlbyname fails in @c getCPUArchitecture using the @c hw.cpusubtype option. + * @note I've not observed a device that has needed this (armcknight 22 Sep 2022). Tested on: + * @code + * - 2015 MBP (x86_64H) + * - 2020 iMac (x86_64H) + * - 2021 MBP (M1 reported as arm64e) + * - iPhone simulators on all of those macs + * - iPhone 13 mini (arm64e) + * - iPod Touch (6th gen) (armv8) + * @endcode + */ NSString * getCPUType(NSNumber *_Nullable subtype) { @@ -78,7 +90,7 @@ case CPU_TYPE_X86_64: // I haven't observed this branch being taken for 64-bit x86 architectures. Rather, the // x86 branch is taken, and then the subtype is reported as the 64-bit - // subtype. Tested on a 2020 iMac. (armcknight 21 Sep 2022) + // subtype. Tested on a 2020 Intel-based iMac and 2015 MBP. (armcknight 21 Sep 2022) return @"x86_64"; case CPU_TYPE_X86: return @"x86"; From 465189238f05e2eb84021837262987a1370a5551 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 22 Sep 2022 16:30:51 -0800 Subject: [PATCH 16/53] update key --- Sources/Sentry/SentryProfiler.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index e3846a9915c..3ac6787bb9c 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -216,7 +216,7 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra # if TARGET_OS_SIMULATOR const auto simulatedDevice = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; if (simulatedDevice != nil) { - profile[@"simulated_device"] = simulatedDevice; + profile[@"simulated_device_model"] = simulatedDevice; } # endif profile[@"device_os_name"] = getOSName(); From 99f3f23a77490689c7399f1a8203523b34353656 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Fri, 23 Sep 2022 00:31:54 +0000 Subject: [PATCH 17/53] Format code --- Sources/Sentry/SentryDevice.mm | 6 ++++-- Sources/Sentry/SentryProfiler.mm | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 473b31c5c8c..09a98df459c 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -41,7 +41,8 @@ getHardwareDescription(int type) { #if SENTRY_HAS_UIKIT && !TARGET_OS_SIMULATOR - NSCAssert(type != HW_MODEL, @"Don't call this method with HW_MODEL for (non-simulator) iOS devices"); + NSCAssert( + type != HW_MODEL, @"Don't call this method with HW_MODEL for (non-simulator) iOS devices"); #endif int mib[2]; char name[128]; @@ -57,7 +58,8 @@ } /** - * Provided as a fallback in case @c sysctlbyname fails in @c getCPUArchitecture using the @c hw.cpusubtype option. + * Provided as a fallback in case @c sysctlbyname fails in @c getCPUArchitecture using the @c + * hw.cpusubtype option. * @note I've not observed a device that has needed this (armcknight 22 Sep 2022). Tested on: * @code * - 2015 MBP (x86_64H) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 3ac6787bb9c..c237199b0b4 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -214,7 +214,8 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"device_model"] = getDeviceModel(); profile[@"device_os_build_number"] = getOSBuildNumber(); # if TARGET_OS_SIMULATOR - const auto simulatedDevice = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; + const auto simulatedDevice + = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; if (simulatedDevice != nil) { profile[@"simulated_device_model"] = simulatedDevice; } From e4ff1abd59593619507dc31e75e8478bee70c0c2 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 22 Sep 2022 16:54:17 -0800 Subject: [PATCH 18/53] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecb1cfa779e..f93787c95a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ - Use the `component` name source for SentryPerformanceTracker (#2168) - Add support for arm64 architecture to the device context (#2185) - Align core data span operations (#2222) +- Fix device info reporting for profiling (#2205) ## 7.25.1 From b9a254b7520698c222e40f9f82421da37a52089b Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 22 Sep 2022 17:15:22 -0800 Subject: [PATCH 19/53] fix test for macs --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 74d6fefe258..6759cf31e1c 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -26,7 +26,7 @@ - (void)testCPUArchitecture - (void)assertMacCPU:(NSString *)arch { #if TARGET_CPU_X86_64 - XCTAssert([arch isEqualToString:@"x86_64"], @"Expected 'x86_64' but got '%@'", arch); + XCTAssert([arch containsString:@"x86"], @"Expected an x86 arch but got '%@'", arch); #elif TARGET_CPU_ARM64 XCTAssert([arch containsString:@"arm64"], @"Expected an arm64 arch but got '%@'", arch); #else From 2a52ff6b45a5e5ee8f5ad346188b7fbc72a30a7a Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 23 Sep 2022 14:38:38 -0800 Subject: [PATCH 20/53] refactor test, add to tvOS-SwiftUITests, working for TV simulator --- .../tvOS-Swift.xcodeproj/project.pbxproj | 10 ++ Sources/Sentry/SentryDevice.h | 30 +++++ Sources/Sentry/SentryDevice.mm | 6 + Sources/Sentry/SentryProfiler.mm | 3 +- Tests/SentryTests/Helper/SentryDeviceTests.mm | 125 +++++++++++++++--- 5 files changed, 157 insertions(+), 17 deletions(-) diff --git a/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj b/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj index 81a4e018119..c85e2e264f0 100644 --- a/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj +++ b/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj @@ -16,6 +16,8 @@ 7BA61D7A247FA35500C130A8 /* Sentry.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7BA61D78247FA35500C130A8 /* Sentry.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84D4FEBF28ECD8A800EDAAFE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D4FEBC28ECD8A100EDAAFE /* Sentry.framework */; }; 84D4FEC028ECD8AF00EDAAFE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D4FEBC28ECD8A100EDAAFE /* Sentry.framework */; }; + 8466D4E328DE64F100932CE7 /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8466D4E228DE64F100932CE7 /* SentryDeviceTests.mm */; }; + 8466D4E428DE64F100932CE7 /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8466D4E128DE64F000932CE7 /* SentryDevice.mm */; }; D822A4232760D15000E7B241 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D822A4222760D15000E7B241 /* AppDelegate.swift */; }; D822A4252760D15000E7B241 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D822A4242760D15000E7B241 /* ViewController.swift */; }; D822A4282760D15000E7B241 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D822A4262760D15000E7B241 /* Main.storyboard */; }; @@ -98,7 +100,10 @@ 7BA61D6F247FA32600C130A8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 7BA61D71247FA32600C130A8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7BA61D78247FA35500C130A8 /* Sentry.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Sentry.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 8466D4DF28DE64F000932CE7 /* SentryDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = ../../../Sources/Sentry/SentryDevice.h; sourceTree = ""; }; + 8466D4E128DE64F000932CE7 /* SentryDevice.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDevice.mm; path = ../../../Sources/Sentry/SentryDevice.mm; sourceTree = ""; }; 84D4FEB628ECD8A100EDAAFE /* Sentry.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Sentry.xcodeproj; path = ../../Sentry.xcodeproj; sourceTree = ""; }; + 8466D4E228DE64F100932CE7 /* SentryDeviceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDeviceTests.mm; path = ../../../Tests/SentryTests/Helper/SentryDeviceTests.mm; sourceTree = ""; }; D822A4202760D15000E7B241 /* tvOS-SBSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "tvOS-SBSwift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; D822A4222760D15000E7B241 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; D822A4242760D15000E7B241 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -152,6 +157,9 @@ 7B64388726A6C71A000D0F65 /* tvOS-SwiftUITests */ = { isa = PBXGroup; children = ( + 8466D4E228DE64F100932CE7 /* SentryDeviceTests.mm */, + 8466D4DF28DE64F000932CE7 /* SentryDevice.h */, + 8466D4E128DE64F000932CE7 /* SentryDevice.mm */, 7B64388826A6C71A000D0F65 /* LaunchUITests.swift */, 7B64388A26A6C71A000D0F65 /* Info.plist */, ); @@ -434,6 +442,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8466D4E328DE64F100932CE7 /* SentryDeviceTests.mm in Sources */, + 8466D4E428DE64F100932CE7 /* SentryDevice.mm in Sources */, 7B64388926A6C71A000D0F65 /* LaunchUITests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/SentryDevice.h index e385854c4e4..91423462ba5 100644 --- a/Sources/Sentry/SentryDevice.h +++ b/Sources/Sentry/SentryDevice.h @@ -1,17 +1,47 @@ #import +/** + * @seealso TargetConditionals.h has explanations and diagrams that show the relationships between different @c TARGET_OS_... and @c TARGET_CPU_... macros. + */ NS_ASSUME_NONNULL_BEGIN +/** + * @return The CPU architecture name, such as @c armv7, @c arm64 or @c x86_64. + */ NSString *getCPUArchitecture(void); +/** + * @return The name of the operating system, such as @c iOS or @c macOS. + */ NSString *getOSName(void); +/** + * @return The OS version with up to three period-delimited numbers, like @c 14 , @c 14.0 or @c 14.0.1 . + */ NSString *getOSVersion(void); +/** + * @return The Apple hardware descriptor, such as @c iPhone14,4 or @c MacBookPro10,8 . + * @note If running on a simulator, this will be the model of the mac running the simulator. + * @seealso See @c getSimulatorDeviceModel() for retrieving the model of the simulator. + */ NSString *getDeviceModel(void); +#if TARGET_OS_SIMULATOR +/** + * @return The Apple hardware descriptor of the simulated device, such as @c iPhone14,4 or @c MacBookPro10,8 . + */ +NSString *_Nullable getSimulatorDeviceModel(void); +#endif // TARGET_OS_SIMULATOR + +/** + * @return A string describing the OS version's specific build, with alphanumeric characters, like @c 21G115 . + */ NSString *getOSBuildNumber(void); +/** + * @return @c YES if built and running in a simulator on a mac device, @c NO if running on a device. + */ BOOL isSimulatorBuild(void); NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 09a98df459c..ea79c4a1819 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -195,6 +195,12 @@ #endif // SENTRY_HAS_UIKIT } +#if TARGET_OS_SIMULATOR +NSString *getSimulatorDeviceModel(void) { + return NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; +} +#endif // TARGET_OS_SIMULATOR + NSString * getOSBuildNumber(void) { diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index c237199b0b4..423c35959d5 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -214,8 +214,7 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"device_model"] = getDeviceModel(); profile[@"device_os_build_number"] = getOSBuildNumber(); # if TARGET_OS_SIMULATOR - const auto simulatedDevice - = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; + const auto simulatedDevice = getSimulatorDeviceModel(); if (simulatedDevice != nil) { profile[@"simulated_device_model"] = simulatedDevice; } diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 6759cf31e1c..481789cd31d 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -1,6 +1,12 @@ #import "SentryDevice.h" #import +#define SENTRY_ASSERT_EQUAL(actualString, expectedString) XCTAssert([expectedString isEqualToString:actualString], @"Expected %@ but got %@", expectedString, actualString) +#define SENTRY_ASSERT_CONTAINS(parentString, childString) XCTAssert([parentString containsString:childString], @"Expected %@ to contain %@", parentString, childString) + +/** + * @seealso TargetConditionals.h has explanations and diagrams that show the relationships between different @c TARGET_OS_... macros. + */ @interface SentryDeviceTests : XCTestCase @end @@ -9,29 +15,118 @@ @implementation SentryDeviceTests - (void)testCPUArchitecture { -#if TARGET_OS_IOS || TARGET_OS_TV -# if TARGET_OS_SIMULATOR - [self assertMacCPU:getCPUArchitecture()]; -# else + const auto arch = getCPUArchitecture(); +#if TARGET_OS_OSX +#if TARGET_CPU_X86_64 + SENTRY_ASSERT_CONTAINS(arch, @"x86"); +#else + SENTRY_ASSERT_CONTAINS(arch, @"arm64"); +#endif +#elif TARGET_OS_MACCATALYST + SENTRY_ASSERT_CONTAINS(arch, @"x86"); +#elif TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. - NSString *arch = getCPUArchitecture(); - XCTAssert([arch containsString:@"arm"], @"Expected an arm architecture but got '%@'", arch); -# endif + if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { + SENTRY_ASSERT_CONTAINS(arch, @"arm"); + } else if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) { + SENTRY_ASSERT_CONTAINS(arch, @"arm"); + } else { + XCTFail(@"Unsupported iOS UI idiom."); + } +#elif TARGET_OS_TV + // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests + // cannot. + XCTAssert([arch containsString:@"arm"], @"Expected %@ to contain %@", arch, @"arm"); +#elif TARGET_OS_WATCH + // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator + XCTAssert([arch containsString:@"arm"], @"Expected %@ to contain %@", arch, @"arm"); #else - [self assertMacCPU:getCPUArchitecture()]; + XCTFail(@"Unexpected device OS"); #endif } -- (void)assertMacCPU:(NSString *)arch -{ -#if TARGET_CPU_X86_64 - XCTAssert([arch containsString:@"x86"], @"Expected an x86 arch but got '%@'", arch); -#elif TARGET_CPU_ARM64 - XCTAssert([arch containsString:@"arm64"], @"Expected an arm64 arch but got '%@'", arch); +- (void)testOSVersion { + XCTAssertNotEqual(getOSVersion().length, 0U); +} + +- (void)testOSName { + const auto osName = getOSName(); +#if TARGET_OS_OSX + SENTRY_ASSERT_EQUAL(osName, @"macOS"); +#elif TARGET_OS_MACCATALYST + SENTRY_ASSERT_EQUAL(osName, @"macOS"); +#elif TARGET_OS_IOS + // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests + // cannot. + if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { + SENTRY_ASSERT_EQUAL(osName, @"iPadOS"); + } else if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) { + SENTRY_ASSERT_EQUAL(osName, @"iOS"); + } else { + XCTFail(@"Unsupported iOS UI idiom."); + } +#elif TARGET_OS_TV + // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests + // cannot. + SENTRY_ASSERT_EQUAL(osName, @"tvOS"); +#elif TARGET_OS_WATCH + // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator + SENTRY_ASSERT_EQUAL(osName, @"watchOS"); #else - XCTFail(@"Unexpected target CPU"); + XCTFail(@"Unexpected device OS"); #endif } +- (void)testDeviceModel { + const auto modelName = getDeviceModel(); + XCTAssertNotEqual(modelName.length, 0U); +#if TARGET_OS_SIMULATOR + SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); +#elif TARGET_OS_OSX + SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); +#elif TARGET_OS_MACCATALYST + SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); +#elif TARGET_OS_IOS + // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests + // cannot. + if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { + SENTRY_ASSERT_CONTAINS(modelName, @"iPad"); + } else if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) { + SENTRY_ASSERT_CONTAINS(modelName, @"iPhone"); + } else { + XCTFail(@"Unsupported iOS UI idiom."); + } +#elif TARGET_OS_TV + // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests + // cannot. + SENTRY_ASSERT_CONTAINS(modelName, @"TV"); +#elif TARGET_OS_WATCH + // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator + SENTRY_ASSERT_CONTAINS(modelName, @"Watch"); +#else + XCTFail(@"Unexpected device OS"); +#endif +} + +- (void)testOSBuildNumber { + XCTAssertNotEqual(getOSBuildNumber().length, 0U); +} + +- (void)testIsSimulator { +#if TARGET_OS_SIMULATOR + XCTAssertTrue(isSimulatorBuild()); +#else + XCTAssertFalse(isSimulatorBuild()); +#endif +} + +- (void)testSimulatedDeviceModel { +#if !TARGET_OS_SIMULATOR + XCTSkip(@"Should only run on simulators."); +#endif + + const auto name = getSimulatorDeviceModel(); +} + @end From c2a5b5a9b35d7331da1b66c9d5bfa7963b3b7b0e Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 23 Sep 2022 14:52:02 -0800 Subject: [PATCH 21/53] fixes for all simulator types and mac catalyst --- .../watchOS-Swift WatchKit App.xcscheme | 25 +++++++++++---- Tests/SentryTests/Helper/SentryDeviceTests.mm | 31 +++++++++++++++++-- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Samples/watchOS-Swift/watchOS-Swift.xcodeproj/xcshareddata/xcschemes/watchOS-Swift WatchKit App.xcscheme b/Samples/watchOS-Swift/watchOS-Swift.xcodeproj/xcshareddata/xcschemes/watchOS-Swift WatchKit App.xcscheme index 4979d444df6..7923fd3aea2 100644 --- a/Samples/watchOS-Swift/watchOS-Swift.xcodeproj/xcshareddata/xcschemes/watchOS-Swift WatchKit App.xcscheme +++ b/Samples/watchOS-Swift/watchOS-Swift.xcodeproj/xcshareddata/xcschemes/watchOS-Swift WatchKit App.xcscheme @@ -54,8 +54,10 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - + - + - + - + + + + + diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 481789cd31d..d10e6af474c 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -23,7 +23,11 @@ - (void)testCPUArchitecture SENTRY_ASSERT_CONTAINS(arch, @"arm64"); #endif #elif TARGET_OS_MACCATALYST +#if TARGET_CPU_X86_64 SENTRY_ASSERT_CONTAINS(arch, @"x86"); +#else + SENTRY_ASSERT_CONTAINS(arch, @"arm64"); +#endif #elif TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. @@ -55,7 +59,7 @@ - (void)testOSName { #if TARGET_OS_OSX SENTRY_ASSERT_EQUAL(osName, @"macOS"); #elif TARGET_OS_MACCATALYST - SENTRY_ASSERT_EQUAL(osName, @"macOS"); + SENTRY_ASSERT_EQUAL(osName, @"iPadOS"); #elif TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. @@ -124,9 +128,30 @@ - (void)testIsSimulator { - (void)testSimulatedDeviceModel { #if !TARGET_OS_SIMULATOR XCTSkip(@"Should only run on simulators."); +#else + const auto modelName = getSimulatorDeviceModel(); + XCTAssertNotEqual(modelName.length, 0U); +#if TARGET_OS_IOS + // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests + // cannot. + if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { + SENTRY_ASSERT_CONTAINS(modelName, @"iPad"); + } else if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) { + SENTRY_ASSERT_CONTAINS(modelName, @"iPhone"); + } else { + XCTFail(@"Unsupported iOS UI idiom."); + } +#elif TARGET_OS_TV + // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests + // cannot. + SENTRY_ASSERT_CONTAINS(modelName, @"TV"); +#elif TARGET_OS_WATCH + // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator + SENTRY_ASSERT_CONTAINS(modelName, @"Watch"); +#else + XCTFail(@"Unexpected device OS"); +#endif #endif - - const auto name = getSimulatorDeviceModel(); } @end From 2517dd2a0b8f2867900374ddb9920b7c5a76a624 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 23 Sep 2022 17:15:25 -0800 Subject: [PATCH 22/53] comment which checks are which device/os; combine arch checks for iOS/iPad since theyre the same; add script to help test everything --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 24 ++++------ scripts/xcode-test-devices.sh | 46 +++++++++++++++++++ 2 files changed, 55 insertions(+), 15 deletions(-) create mode 100755 scripts/xcode-test-devices.sh diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index d10e6af474c..d3b42fb6742 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -18,33 +18,27 @@ - (void)testCPUArchitecture const auto arch = getCPUArchitecture(); #if TARGET_OS_OSX #if TARGET_CPU_X86_64 - SENTRY_ASSERT_CONTAINS(arch, @"x86"); + // I observed this branch still being taken when running unit tests for macOS in Xcode 13.4.1 on an Apple Silicon MBP (armcknight 23 Sep 2022) + SENTRY_ASSERT_CONTAINS(arch, @"x86"); // Macs with Intel CPUs #else - SENTRY_ASSERT_CONTAINS(arch, @"arm64"); + SENTRY_ASSERT_CONTAINS(arch, @"arm64"); // Macs with Apple Silicon #endif #elif TARGET_OS_MACCATALYST #if TARGET_CPU_X86_64 - SENTRY_ASSERT_CONTAINS(arch, @"x86"); + // I observed this branch still being taken when running unit tests for mac catalyst in Xcode 13.4.1 on an Apple Silicon MBP (armcknight 23 Sep 2022) + SENTRY_ASSERT_CONTAINS(arch, @"x86"); // Macs with Intel CPUs #else - SENTRY_ASSERT_CONTAINS(arch, @"arm64"); + SENTRY_ASSERT_CONTAINS(arch, @"arm64"); // Macs with Apple Silicon #endif #elif TARGET_OS_IOS - // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests - // cannot. - if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { - SENTRY_ASSERT_CONTAINS(arch, @"arm"); - } else if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) { - SENTRY_ASSERT_CONTAINS(arch, @"arm"); - } else { - XCTFail(@"Unsupported iOS UI idiom."); - } + SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real iPads and iPhones #elif TARGET_OS_TV // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests // cannot. - XCTAssert([arch containsString:@"arm"], @"Expected %@ to contain %@", arch, @"arm"); + SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real TVs #elif TARGET_OS_WATCH // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator - XCTAssert([arch containsString:@"arm"], @"Expected %@ to contain %@", arch, @"arm"); + SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real Watches #else XCTFail(@"Unexpected device OS"); #endif diff --git a/scripts/xcode-test-devices.sh b/scripts/xcode-test-devices.sh new file mode 100755 index 00000000000..e674d65d12b --- /dev/null +++ b/scripts/xcode-test-devices.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# This script helps run SentryDeviceTests on all possible devices. + +set -uox pipefail + +CONFIGURATION="$1" + +# This can be one of the following options: +# - "simulators": run against all mac and simulator targets +# - "iphone": run on a real iPhone +# - "ipad": run on a real iPad +# - "tv": run on a real TV +# - "watch": run on a real Watch +DEVICE_TYPE="$2" + +if [[ $DEVICE_TYPE == "simulators" ]]; then + for DESTINATION in \ + 'platform=iOS Simulator,OS=16.0,name=iPhone SE (3rd generation)' \ + 'platform=iOS Simulator,OS=16.0,name=iPad mini (6th generation)' \ + 'platform=tvOS Simulator,OS=16.0,name=Apple TV 4K (2nd generation)' \ + 'platform=macOS,arch=arm64' \ + 'platform=macOS,arch=x86_64' \ + 'platform=macOS,arch=arm64,variant=Mac Catalyst' \ + 'platform=macOS,arch=x86_64,variant=Mac Catalyst' \ + ; do + echo "destination: '$DESTINATION'" + env NSUnbufferedIO=YES \ + xcodebuild -workspace Sentry.xcworkspace -scheme Sentry -configuration $CONFIGURATION \ + -destination "$DESTINATION" \ + -only-testing:"SentryTests/SentryDeviceTests" \ + test \ + | tee "raw-test-log-$DEVICE_TYPE-devices.log" \ + | rbenv exec bundle exec xcpretty -t + done +elif [[ $DEVICE_TYPE == "iphone" ]]; then + +elif [[ $DEVICE_TYPE == "ipad" ]]; then + +elif [[ $DEVICE_TYPE == "tv" ]]; then + +elif [[ $DEVICE_TYPE == "watch" ]]; then + +else + echo "Invalid DEVICE_TYPE. Choose from 'simulators', 'iphone', 'ipad', 'tv' or 'watch'." +fi From 96371734781698e09c2baaf4746da55884d9760a Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Mon, 26 Sep 2022 19:29:15 -0800 Subject: [PATCH 23/53] fix comment --- Sources/Sentry/SentryDevice.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index ea79c4a1819..59ac41706ef 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -58,8 +58,8 @@ } /** - * Provided as a fallback in case @c sysctlbyname fails in @c getCPUArchitecture using the @c - * hw.cpusubtype option. + * Provided as a fallback in case @c sysctlbyname fails in @c getCPUArchitecture using the + * @c hw.cpusubtype option. * @note I've not observed a device that has needed this (armcknight 22 Sep 2022). Tested on: * @code * - 2015 MBP (x86_64H) From 590500dd9b2f170d61ef7b8abc50cb50a8f4d335 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 4 Oct 2022 12:28:12 -0500 Subject: [PATCH 24/53] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f93787c95a4..1fb3c57e249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Add app start measurement to first finished transaction (#2252) - Return SentryNoOpSpan when starting a child on a finished transaction (#2239) - Fix profiling timestamps for slow/frozen frames (#2226) +- Fix device info reporting for profiling (#2205) ## 7.27.0 @@ -41,7 +42,6 @@ - Use the `component` name source for SentryPerformanceTracker (#2168) - Add support for arm64 architecture to the device context (#2185) - Align core data span operations (#2222) -- Fix device info reporting for profiling (#2205) ## 7.25.1 From e625b335e0625b20ca29f643a15316e11484a1f0 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 4 Oct 2022 12:34:34 -0500 Subject: [PATCH 25/53] fix tvOS tests to discriminate between tv simulator on m1/intel and real tv devices --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index d3b42fb6742..4460d10639a 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -35,7 +35,17 @@ - (void)testCPUArchitecture #elif TARGET_OS_TV // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests // cannot. +#if TARGET_OS_SIMULATOR +#if TARGET_CPU_ARM64 + SENTRY_ASSERT_CONTAINS(arch, @"arm"); // TV simulator on M1 macs +#elif TARGET_CPU_X86_64 + SENTRY_ASSERT_EQUAL(arch, @"x86_64"); // TV simulator on Intel macs +#else + XCTFail(@"Unexpected CPU type on test host."); +#endif // TARGET_CPU_ARM64 +#else SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real TVs +#endif #elif TARGET_OS_WATCH // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real Watches From 07486455f0445b1e6d7636e9526039705a582e30 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 4 Oct 2022 17:36:49 +0000 Subject: [PATCH 26/53] Format code --- Sources/Sentry/SentryDevice.h | 12 ++- Sources/Sentry/SentryDevice.mm | 4 +- Tests/SentryTests/Helper/SentryDeviceTests.mm | 83 +++++++++++-------- 3 files changed, 61 insertions(+), 38 deletions(-) diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/SentryDevice.h index 91423462ba5..dd58eb3cfec 100644 --- a/Sources/Sentry/SentryDevice.h +++ b/Sources/Sentry/SentryDevice.h @@ -1,6 +1,7 @@ #import /** - * @seealso TargetConditionals.h has explanations and diagrams that show the relationships between different @c TARGET_OS_... and @c TARGET_CPU_... macros. + * @seealso TargetConditionals.h has explanations and diagrams that show the relationships between + * different @c TARGET_OS_... and @c TARGET_CPU_... macros. */ NS_ASSUME_NONNULL_BEGIN @@ -16,7 +17,8 @@ NSString *getCPUArchitecture(void); NSString *getOSName(void); /** - * @return The OS version with up to three period-delimited numbers, like @c 14 , @c 14.0 or @c 14.0.1 . + * @return The OS version with up to three period-delimited numbers, like @c 14 , @c 14.0 or + * @c 14.0.1 . */ NSString *getOSVersion(void); @@ -29,13 +31,15 @@ NSString *getDeviceModel(void); #if TARGET_OS_SIMULATOR /** - * @return The Apple hardware descriptor of the simulated device, such as @c iPhone14,4 or @c MacBookPro10,8 . + * @return The Apple hardware descriptor of the simulated device, such as @c iPhone14,4 or @c + * MacBookPro10,8 . */ NSString *_Nullable getSimulatorDeviceModel(void); #endif // TARGET_OS_SIMULATOR /** - * @return A string describing the OS version's specific build, with alphanumeric characters, like @c 21G115 . + * @return A string describing the OS version's specific build, with alphanumeric characters, like + * @c 21G115 . */ NSString *getOSBuildNumber(void); diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 59ac41706ef..d7c5a68682b 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -196,7 +196,9 @@ } #if TARGET_OS_SIMULATOR -NSString *getSimulatorDeviceModel(void) { +NSString * +getSimulatorDeviceModel(void) +{ return NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; } #endif // TARGET_OS_SIMULATOR diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 4460d10639a..01d708a2086 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -1,11 +1,16 @@ #import "SentryDevice.h" #import -#define SENTRY_ASSERT_EQUAL(actualString, expectedString) XCTAssert([expectedString isEqualToString:actualString], @"Expected %@ but got %@", expectedString, actualString) -#define SENTRY_ASSERT_CONTAINS(parentString, childString) XCTAssert([parentString containsString:childString], @"Expected %@ to contain %@", parentString, childString) +#define SENTRY_ASSERT_EQUAL(actualString, expectedString) \ + XCTAssert([expectedString isEqualToString:actualString], @"Expected %@ but got %@", \ + expectedString, actualString) +#define SENTRY_ASSERT_CONTAINS(parentString, childString) \ + XCTAssert([parentString containsString:childString], @"Expected %@ to contain %@", \ + parentString, childString) /** - * @seealso TargetConditionals.h has explanations and diagrams that show the relationships between different @c TARGET_OS_... macros. + * @seealso TargetConditionals.h has explanations and diagrams that show the relationships between + * different @c TARGET_OS_... macros. */ @interface SentryDeviceTests : XCTestCase @@ -17,48 +22,53 @@ - (void)testCPUArchitecture { const auto arch = getCPUArchitecture(); #if TARGET_OS_OSX -#if TARGET_CPU_X86_64 - // I observed this branch still being taken when running unit tests for macOS in Xcode 13.4.1 on an Apple Silicon MBP (armcknight 23 Sep 2022) +# if TARGET_CPU_X86_64 + // I observed this branch still being taken when running unit tests for macOS in Xcode 13.4.1 on + // an Apple Silicon MBP (armcknight 23 Sep 2022) SENTRY_ASSERT_CONTAINS(arch, @"x86"); // Macs with Intel CPUs -#else +# else SENTRY_ASSERT_CONTAINS(arch, @"arm64"); // Macs with Apple Silicon -#endif +# endif #elif TARGET_OS_MACCATALYST -#if TARGET_CPU_X86_64 - // I observed this branch still being taken when running unit tests for mac catalyst in Xcode 13.4.1 on an Apple Silicon MBP (armcknight 23 Sep 2022) +# if TARGET_CPU_X86_64 + // I observed this branch still being taken when running unit tests for mac catalyst in + // Xcode 13.4.1 on an Apple Silicon MBP (armcknight 23 Sep 2022) SENTRY_ASSERT_CONTAINS(arch, @"x86"); // Macs with Intel CPUs -#else +# else SENTRY_ASSERT_CONTAINS(arch, @"arm64"); // Macs with Apple Silicon -#endif +# endif #elif TARGET_OS_IOS SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real iPads and iPhones #elif TARGET_OS_TV // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests // cannot. -#if TARGET_OS_SIMULATOR -#if TARGET_CPU_ARM64 +# if TARGET_OS_SIMULATOR +# if TARGET_CPU_ARM64 SENTRY_ASSERT_CONTAINS(arch, @"arm"); // TV simulator on M1 macs -#elif TARGET_CPU_X86_64 +# elif TARGET_CPU_X86_64 SENTRY_ASSERT_EQUAL(arch, @"x86_64"); // TV simulator on Intel macs -#else +# else XCTFail(@"Unexpected CPU type on test host."); -#endif // TARGET_CPU_ARM64 -#else +# endif // TARGET_CPU_ARM64 +# else SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real TVs -#endif +# endif #elif TARGET_OS_WATCH - // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator + // TODO: create a watch UI test target to test this branch as it cannot run on the watch + // simulator SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real Watches #else XCTFail(@"Unexpected device OS"); #endif } -- (void)testOSVersion { +- (void)testOSVersion +{ XCTAssertNotEqual(getOSVersion().length, 0U); } -- (void)testOSName { +- (void)testOSName +{ const auto osName = getOSName(); #if TARGET_OS_OSX SENTRY_ASSERT_EQUAL(osName, @"macOS"); @@ -79,14 +89,16 @@ - (void)testOSName { // cannot. SENTRY_ASSERT_EQUAL(osName, @"tvOS"); #elif TARGET_OS_WATCH - // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator + // TODO: create a watch UI test target to test this branch as it cannot run on the watch + // simulator SENTRY_ASSERT_EQUAL(osName, @"watchOS"); #else XCTFail(@"Unexpected device OS"); #endif } -- (void)testDeviceModel { +- (void)testDeviceModel +{ const auto modelName = getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); #if TARGET_OS_SIMULATOR @@ -110,18 +122,21 @@ - (void)testDeviceModel { // cannot. SENTRY_ASSERT_CONTAINS(modelName, @"TV"); #elif TARGET_OS_WATCH - // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator + // TODO: create a watch UI test target to test this branch as it cannot run on the watch + // simulator SENTRY_ASSERT_CONTAINS(modelName, @"Watch"); #else XCTFail(@"Unexpected device OS"); #endif } -- (void)testOSBuildNumber { +- (void)testOSBuildNumber +{ XCTAssertNotEqual(getOSBuildNumber().length, 0U); } -- (void)testIsSimulator { +- (void)testIsSimulator +{ #if TARGET_OS_SIMULATOR XCTAssertTrue(isSimulatorBuild()); #else @@ -129,13 +144,14 @@ - (void)testIsSimulator { #endif } -- (void)testSimulatedDeviceModel { +- (void)testSimulatedDeviceModel +{ #if !TARGET_OS_SIMULATOR XCTSkip(@"Should only run on simulators."); #else const auto modelName = getSimulatorDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); -#if TARGET_OS_IOS +# if TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) { @@ -145,16 +161,17 @@ - (void)testSimulatedDeviceModel { } else { XCTFail(@"Unsupported iOS UI idiom."); } -#elif TARGET_OS_TV +# elif TARGET_OS_TV // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests // cannot. SENTRY_ASSERT_CONTAINS(modelName, @"TV"); -#elif TARGET_OS_WATCH - // TODO: create a watch UI test target to test this branch as it cannot run on the watch simulator +# elif TARGET_OS_WATCH + // TODO: create a watch UI test target to test this branch as it cannot run on the watch + // simulator SENTRY_ASSERT_CONTAINS(modelName, @"Watch"); -#else +# else XCTFail(@"Unexpected device OS"); -#endif +# endif #endif } From 76e4134ddab3d3d5ff5011e50d94ab502882432b Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 4 Oct 2022 12:48:31 -0500 Subject: [PATCH 27/53] fix some tv/watch stuff, and simulator device names in CI --- Sources/Sentry/SentryDevice.mm | 4 +++- Tests/SentryTests/Helper/SentryDeviceTests.mm | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index d7c5a68682b..f80230bc417 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -151,7 +151,9 @@ NSString * getOSVersion(void) { -#if SENTRY_HAS_UIKIT +#if TARGET_OS_WATCH + return WKInterfaceDevice.currentDevice.systemVersion; +#elif SENTRY_HAS_UIKIT return UIDevice.currentDevice.systemVersion; #else // based off of diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 01d708a2086..149803df188 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -38,7 +38,17 @@ - (void)testCPUArchitecture SENTRY_ASSERT_CONTAINS(arch, @"arm64"); // Macs with Apple Silicon # endif #elif TARGET_OS_IOS +#if TARGET_OS_SIMULATOR +#if TARGET_CPU_ARM64 + SENTRY_ASSERT_CONTAINS(arch, @"arm"); // iPhone simulator on M1 macs +#elif TARGET_CPU_X86_64 + SENTRY_ASSERT_CONTAINS(arch, @"x86"); // iPhone simulator on Intel macs +#else + XCTFail(@"Unexpected CPU type on test host."); +#endif // TARGET_CPU_ARM64 +#else SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real iPads and iPhones +#endif #elif TARGET_OS_TV // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests // cannot. @@ -46,7 +56,7 @@ - (void)testCPUArchitecture # if TARGET_CPU_ARM64 SENTRY_ASSERT_CONTAINS(arch, @"arm"); // TV simulator on M1 macs # elif TARGET_CPU_X86_64 - SENTRY_ASSERT_EQUAL(arch, @"x86_64"); // TV simulator on Intel macs + SENTRY_ASSERT_CONTAINS(arch, @"x86"); // TV simulator on Intel macs # else XCTFail(@"Unexpected CPU type on test host."); # endif // TARGET_CPU_ARM64 @@ -102,7 +112,11 @@ - (void)testDeviceModel const auto modelName = getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); #if TARGET_OS_SIMULATOR +#if defined(TESTCI) + SENTRY_ASSERT_CONTAINS(modelName, @"VMware"); +#else SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); +#endif #elif TARGET_OS_OSX SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); #elif TARGET_OS_MACCATALYST From 58028bf99eb4ff77d2b2a869201b9e4646578482 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 4 Oct 2022 17:52:44 +0000 Subject: [PATCH 28/53] Format code --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 149803df188..3492072ec84 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -38,17 +38,17 @@ - (void)testCPUArchitecture SENTRY_ASSERT_CONTAINS(arch, @"arm64"); // Macs with Apple Silicon # endif #elif TARGET_OS_IOS -#if TARGET_OS_SIMULATOR -#if TARGET_CPU_ARM64 +# if TARGET_OS_SIMULATOR +# if TARGET_CPU_ARM64 SENTRY_ASSERT_CONTAINS(arch, @"arm"); // iPhone simulator on M1 macs -#elif TARGET_CPU_X86_64 +# elif TARGET_CPU_X86_64 SENTRY_ASSERT_CONTAINS(arch, @"x86"); // iPhone simulator on Intel macs -#else +# else XCTFail(@"Unexpected CPU type on test host."); -#endif // TARGET_CPU_ARM64 -#else +# endif // TARGET_CPU_ARM64 +# else SENTRY_ASSERT_CONTAINS(arch, @"arm"); // Real iPads and iPhones -#endif +# endif #elif TARGET_OS_TV // We must test this branch in tvOS-SwiftUITests since it must run on device, which SentryTests // cannot. @@ -112,11 +112,11 @@ - (void)testDeviceModel const auto modelName = getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); #if TARGET_OS_SIMULATOR -#if defined(TESTCI) +# if defined(TESTCI) SENTRY_ASSERT_CONTAINS(modelName, @"VMware"); -#else +# else SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); -#endif +# endif #elif TARGET_OS_OSX SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); #elif TARGET_OS_MACCATALYST From 0a07458806435ae71a8ea677511e71efeba98204 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 4 Oct 2022 15:32:55 -0500 Subject: [PATCH 29/53] fall back to older method if HW_PRODUCT returns empty string --- Sources/Sentry/SentryDevice.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index f80230bc417..458b7acac95 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -7,6 +7,7 @@ # import "SentryLog.h" #else # define SENTRY_LOG_ERRNO(statement) statement +# define SENTRY_LOG_DEBUG(...) NSLog(__VA_ARGS__) #endif #import "SentryDevice.h" @@ -182,7 +183,12 @@ { #if defined(HW_PRODUCT) if (@available(iOS 14, macOS 11, *)) { - return getHardwareDescription(HW_PRODUCT); + const auto model = getHardwareDescription(HW_PRODUCT); + if (model.length > 0) { + return model; + } else { + SENTRY_LOG_DEBUG(@"Model name from HW_PRODUCT was empty."); + } } #endif // defined(HW_PRODUCT) From 2b4a260d485f3cbf1ae5087935ebe0658dfe73e3 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 5 Oct 2022 12:14:47 -0500 Subject: [PATCH 30/53] logs, comments and fix conditionally-compiled imports/polyfills --- Sources/Sentry/SentryDevice.mm | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 458b7acac95..eac68e073d2 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -1,14 +1,18 @@ // This file is also compiled into iOS-SwiftUITests and doesn't have access to private Sentry API -// there, so we fix up a few things here. -#if !defined(SENTRY_HAS_UIKIT) +// there, so we add a few polyfills: +#if __has_include("SentryDefines.h") +#import "SentryDefines.h" +#else # define SENTRY_HAS_UIKIT (TARGET_OS_IOS || TARGET_OS_TV) #endif -#if defined(SENTRY_LOG_ERRNO) + +#if __has_include("SentryLog.h") # import "SentryLog.h" #else # define SENTRY_LOG_ERRNO(statement) statement # define SENTRY_LOG_DEBUG(...) NSLog(__VA_ARGS__) #endif +// #import "SentryDevice.h" #import @@ -55,7 +59,19 @@ if (SENTRY_LOG_ERRNO(sysctl(mib, 2, &name, &len, NULL, 0)) != 0) { return @""; } - return [NSString stringWithUTF8String:name]; + + const auto nameNSString = [NSString stringWithUTF8String:name]; + + NSString *argName; + switch (type) { + case HW_PRODUCT: argName = @"HW_PRODUCT"; break; + case HW_MACHINE: argName = @"HW_MACHINE"; break; + case HW_MODEL: argName = @"HW_MODEL"; break; + default: NSCAssert(NO, @"Illegal argument"); + } + + SENTRY_LOG_DEBUG(@"Model name using %@: %@", argName, nameNSString); + return nameNSString; } /** @@ -185,6 +201,7 @@ if (@available(iOS 14, macOS 11, *)) { const auto model = getHardwareDescription(HW_PRODUCT); if (model.length > 0) { + SENTRY_LOG_DEBUG(@"Model name using HW_PRODUCT: %@", model); return model; } else { SENTRY_LOG_DEBUG(@"Model name from HW_PRODUCT was empty."); @@ -194,11 +211,14 @@ #if SENTRY_HAS_UIKIT # if TARGET_OS_SIMULATOR + // iPhone/iPad or TV simulators return getHardwareDescription(HW_MODEL); # else + // iPhone/iPad or TV devices return getHardwareDescription(HW_MACHINE); # endif // TARGET_OS_SIMULATOR #else + // macs and watch devices TODO: test on watch devices, may need to separate that with TARGET_OS_WATCH return getHardwareDescription(HW_MODEL); #endif // SENTRY_HAS_UIKIT } From c04f0da33883ac25447c00b32f9cb9705abe4d8e Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 5 Oct 2022 21:34:06 -0500 Subject: [PATCH 31/53] update how simulators are handled --- Sources/Sentry/SentryDevice.mm | 14 ++++++++------ Tests/SentryTests/Helper/SentryDeviceTests.mm | 8 +------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index eac68e073d2..ded366f3622 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -197,6 +197,12 @@ NSString * getDeviceModel(void) { +#if TARGET_OS_SIMULATOR + // iPhone/iPad, Watch and TV simulators + const auto simulatedDeviceModelName = getSimulatorDeviceModel(); + SENTRY_LOG_DEBUG(@"Got simulated device model name %@ (running on %@)", simulatedDeviceModelName, getHardwareDescription(HW_MODEL)); + return simulatedDeviceModelName; +#else #if defined(HW_PRODUCT) if (@available(iOS 14, macOS 11, *)) { const auto model = getHardwareDescription(HW_PRODUCT); @@ -210,17 +216,13 @@ #endif // defined(HW_PRODUCT) #if SENTRY_HAS_UIKIT -# if TARGET_OS_SIMULATOR - // iPhone/iPad or TV simulators - return getHardwareDescription(HW_MODEL); -# else // iPhone/iPad or TV devices return getHardwareDescription(HW_MACHINE); -# endif // TARGET_OS_SIMULATOR #else - // macs and watch devices TODO: test on watch devices, may need to separate that with TARGET_OS_WATCH + // macs and watch devices TODO: test on watch devices, may need to separate TARGET_OS_WATCH return getHardwareDescription(HW_MODEL); #endif // SENTRY_HAS_UIKIT +#endif // TARGET_OS_SIMULATOR } #if TARGET_OS_SIMULATOR diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 3492072ec84..2e5bfd4dfab 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -111,13 +111,7 @@ - (void)testDeviceModel { const auto modelName = getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); -#if TARGET_OS_SIMULATOR -# if defined(TESTCI) - SENTRY_ASSERT_CONTAINS(modelName, @"VMware"); -# else - SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); -# endif -#elif TARGET_OS_OSX +#if TARGET_OS_OSX SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); #elif TARGET_OS_MACCATALYST SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); From e93406f1de63af2850bdb4362901dc8c888dbd7b Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 5 Oct 2022 21:34:18 -0500 Subject: [PATCH 32/53] add some questions under todos --- .../Recording/Monitors/SentryCrashMonitor_System.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m index d7953ab4eff..cf987b09857 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m @@ -114,6 +114,8 @@ * @param name The sysctl name. * * @return The result of the sysctl call. + * + * @todo Combine into SentryDevice? */ static const char * stringSysctl(const char *name) @@ -401,7 +403,7 @@ sentrycrashsysctl_getMacAddress("en0", [data mutableBytes]); } - // Append some device-specific data. + // Append some device-specific data. TODO: use SentryDevice API here now? [data appendData:(NSData *_Nonnull)[nsstringSysctl(@"hw.machine") dataUsingEncoding:NSUTF8StringEncoding]]; [data appendData:(NSData *_Nonnull)[nsstringSysctl(@"hw.model") @@ -555,6 +557,7 @@ = cString([NSProcessInfo processInfo].environment[@"SIMULATOR_MODEL_IDENTIFIER"]); g_systemData.model = "simulator"; } else { + // TODO: combine this into SentryDevice? #if SentryCrashCRASH_HOST_MAC // MacOS has the machine in the model field, and no model g_systemData.machine = stringSysctl("hw.model"); From c6d8225c7d4fc96bc56e70881715e878f7e7ce44 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 5 Oct 2022 21:50:07 -0500 Subject: [PATCH 33/53] tweak haswell x86 name --- Sources/Sentry/SentryDevice.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index ded366f3622..b3149ad69ca 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -79,8 +79,8 @@ * @c hw.cpusubtype option. * @note I've not observed a device that has needed this (armcknight 22 Sep 2022). Tested on: * @code - * - 2015 MBP (x86_64H) - * - 2020 iMac (x86_64H) + * - 2015 MBP (x86_64h) + * - 2020 iMac (x86_64h) * - 2021 MBP (M1 reported as arm64e) * - iPhone simulators on all of those macs * - iPhone 13 mini (arm64e) @@ -135,7 +135,7 @@ default: return getCPUType(@(subtype)); case CPU_SUBTYPE_X86_64_H: - return @"x86_64H"; + return @"x86_64h"; case CPU_SUBTYPE_X86_64_ALL: return @"x86_64"; case CPU_SUBTYPE_ARM_V6: From 70431584a95ccdcaf49b35e190068898410c3465 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 5 Oct 2022 21:50:39 -0500 Subject: [PATCH 34/53] fix mac targets in ci; fix failure message --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 2e5bfd4dfab..12ae44360d3 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -111,10 +111,12 @@ - (void)testDeviceModel { const auto modelName = getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); -#if TARGET_OS_OSX - SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); -#elif TARGET_OS_MACCATALYST +#if TARGET_OS_OSX || TARGET_OS_MACCATALYST +#if defined(TESTCI) + SENTRY_ASSERT_CONTAINS(modelName, @"VMWare"); +#else SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); +#endif // defined(TESTCI) #elif TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. @@ -134,7 +136,7 @@ - (void)testDeviceModel // simulator SENTRY_ASSERT_CONTAINS(modelName, @"Watch"); #else - XCTFail(@"Unexpected device OS"); + XCTFail(@"Unexpected target OS"); #endif } From 97735c01fa709982cc85b8153fd938aa5f65e236 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 5 Oct 2022 21:57:54 -0500 Subject: [PATCH 35/53] import watchkit to fix watchOS build breakage --- Sources/Sentry/SentryDevice.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index b3149ad69ca..3d22bb7be0f 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -18,6 +18,8 @@ #import #if SENTRY_HAS_UIKIT # import +#elif TARGET_OS_WATCH +#import #endif namespace { From 07fb5df69f6dd54b0769eeea6ac465e11a8626f4 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 6 Oct 2022 18:21:30 +0000 Subject: [PATCH 36/53] Format code --- Sources/Sentry/SentryDevice.mm | 32 ++++++++++++------- Tests/SentryTests/Helper/SentryDeviceTests.mm | 6 ++-- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 3d22bb7be0f..4c71eb79f50 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -1,7 +1,7 @@ // This file is also compiled into iOS-SwiftUITests and doesn't have access to private Sentry API // there, so we add a few polyfills: #if __has_include("SentryDefines.h") -#import "SentryDefines.h" +# import "SentryDefines.h" #else # define SENTRY_HAS_UIKIT (TARGET_OS_IOS || TARGET_OS_TV) #endif @@ -19,7 +19,7 @@ #if SENTRY_HAS_UIKIT # import #elif TARGET_OS_WATCH -#import +# import #endif namespace { @@ -66,10 +66,17 @@ NSString *argName; switch (type) { - case HW_PRODUCT: argName = @"HW_PRODUCT"; break; - case HW_MACHINE: argName = @"HW_MACHINE"; break; - case HW_MODEL: argName = @"HW_MODEL"; break; - default: NSCAssert(NO, @"Illegal argument"); + case HW_PRODUCT: + argName = @"HW_PRODUCT"; + break; + case HW_MACHINE: + argName = @"HW_MACHINE"; + break; + case HW_MODEL: + argName = @"HW_MODEL"; + break; + default: + NSCAssert(NO, @"Illegal argument"); } SENTRY_LOG_DEBUG(@"Model name using %@: %@", argName, nameNSString); @@ -202,10 +209,11 @@ #if TARGET_OS_SIMULATOR // iPhone/iPad, Watch and TV simulators const auto simulatedDeviceModelName = getSimulatorDeviceModel(); - SENTRY_LOG_DEBUG(@"Got simulated device model name %@ (running on %@)", simulatedDeviceModelName, getHardwareDescription(HW_MODEL)); + SENTRY_LOG_DEBUG(@"Got simulated device model name %@ (running on %@)", + simulatedDeviceModelName, getHardwareDescription(HW_MODEL)); return simulatedDeviceModelName; #else -#if defined(HW_PRODUCT) +# if defined(HW_PRODUCT) if (@available(iOS 14, macOS 11, *)) { const auto model = getHardwareDescription(HW_PRODUCT); if (model.length > 0) { @@ -215,15 +223,15 @@ SENTRY_LOG_DEBUG(@"Model name from HW_PRODUCT was empty."); } } -#endif // defined(HW_PRODUCT) +# endif // defined(HW_PRODUCT) -#if SENTRY_HAS_UIKIT +# if SENTRY_HAS_UIKIT // iPhone/iPad or TV devices return getHardwareDescription(HW_MACHINE); -#else +# else // macs and watch devices TODO: test on watch devices, may need to separate TARGET_OS_WATCH return getHardwareDescription(HW_MODEL); -#endif // SENTRY_HAS_UIKIT +# endif // SENTRY_HAS_UIKIT #endif // TARGET_OS_SIMULATOR } diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 12ae44360d3..b7bc81e92f9 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -112,11 +112,11 @@ - (void)testDeviceModel const auto modelName = getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); #if TARGET_OS_OSX || TARGET_OS_MACCATALYST -#if defined(TESTCI) +# if defined(TESTCI) SENTRY_ASSERT_CONTAINS(modelName, @"VMWare"); -#else +# else SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); -#endif // defined(TESTCI) +# endif // defined(TESTCI) #elif TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. From 464d81f23e5084e5d9e3ef828f0b976a5a93f652 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 6 Oct 2022 13:33:07 -0500 Subject: [PATCH 37/53] also check for VMWare for TEST config --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index b7bc81e92f9..232df82d8d9 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -112,7 +112,7 @@ - (void)testDeviceModel const auto modelName = getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); #if TARGET_OS_OSX || TARGET_OS_MACCATALYST -# if defined(TESTCI) +# if defined(TESTCI) || defined(TEST) SENTRY_ASSERT_CONTAINS(modelName, @"VMWare"); # else SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); From 2ef5878176cc356b58adf954d480c55352b7ca84 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 6 Oct 2022 14:15:55 -0500 Subject: [PATCH 38/53] link watchkit for watch builds --- Sentry.xcodeproj/project.pbxproj | 4 ---- Sources/Configuration/Sentry.xcconfig | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 24f160ff10e..ace4d5055b3 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -3876,7 +3876,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3915,7 +3914,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = NO; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -4082,7 +4080,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -4216,7 +4213,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; PRODUCT_NAME = Sentry; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/Sources/Configuration/Sentry.xcconfig b/Sources/Configuration/Sentry.xcconfig index c70747b54c4..c5ae0439da0 100644 --- a/Sources/Configuration/Sentry.xcconfig +++ b/Sources/Configuration/Sentry.xcconfig @@ -51,6 +51,8 @@ LD_RUNPATH_SEARCH_PATHS[sdk=iphone*] = $(inherited) @executable_path/Frameworks LD_RUNPATH_SEARCH_PATHS[sdk=watch*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks; LD_RUNPATH_SEARCH_PATHS[sdk=appletv*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks; +OTHER_LDFLAGS[sdk=watch*] = $(inherited) -framework WatchKit + MODULEMAP_FILE = $(SRCROOT)/Sources/Sentry/Sentry.modulemap //SWIFT_INCLUDE_PATHS = $(SRCROOT)/Sources/Sentry From 18f3a9e15e2c8f2e79429968140a597521c44b38 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 6 Oct 2022 14:16:07 -0500 Subject: [PATCH 39/53] fix capitalization on VMware --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 232df82d8d9..faffab8f644 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -113,7 +113,7 @@ - (void)testDeviceModel XCTAssertNotEqual(modelName.length, 0U); #if TARGET_OS_OSX || TARGET_OS_MACCATALYST # if defined(TESTCI) || defined(TEST) - SENTRY_ASSERT_CONTAINS(modelName, @"VMWare"); + SENTRY_ASSERT_CONTAINS(modelName, @"VMware"); # else SENTRY_ASSERT_CONTAINS(modelName, @"Mac"); # endif // defined(TESTCI) From 156d09b9fd4184d1521ba7dc5e36c4705a5cadc6 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 7 Oct 2022 10:27:04 -0500 Subject: [PATCH 40/53] link watchkit in home assistant integration test patch --- scripts/add-sentry-to-homekit.patch | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/add-sentry-to-homekit.patch b/scripts/add-sentry-to-homekit.patch index 8de5a08a625..4290874f931 100644 --- a/scripts/add-sentry-to-homekit.patch +++ b/scripts/add-sentry-to-homekit.patch @@ -1,3 +1,15 @@ +git diff HomeAssistant.xcconfig +diff --git a/Configuration/HomeAssistant.xcconfig b/Configuration/HomeAssistant.xcconfig +index 2b1cdd31..962ec867 100644 +--- a/Configuration/HomeAssistant.xcconfig ++++ b/Configuration/HomeAssistant.xcconfig +@@ -92,3 +92,5 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES + CLANG_ANALYZER_NONNULL = YES + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES + GCC_NO_COMMON_BLOCKS = YES ++ ++OTHER_LDFLAGS[sdk=watch*] = $(inherited) -framework WatchKit + diff --git a/Podfile b/Podfile index d2d83b14..6756f31b 100644 --- a/Podfile From dd4770d887ebe5844fc6cfee1022198a2c734939 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 7 Oct 2022 10:56:23 -0500 Subject: [PATCH 41/53] dont report host machine model, only simulated device model --- Sources/Sentry/SentryDevice.h | 5 +---- Sources/Sentry/SentryDevice.mm | 2 -- Sources/Sentry/SentryProfiler.mm | 11 +++-------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/SentryDevice.h index dd58eb3cfec..56504f398de 100644 --- a/Sources/Sentry/SentryDevice.h +++ b/Sources/Sentry/SentryDevice.h @@ -24,18 +24,15 @@ NSString *getOSVersion(void); /** * @return The Apple hardware descriptor, such as @c iPhone14,4 or @c MacBookPro10,8 . - * @note If running on a simulator, this will be the model of the mac running the simulator. - * @seealso See @c getSimulatorDeviceModel() for retrieving the model of the simulator. + * @note If running on a simulator, this will be the model of the simulated device. */ NSString *getDeviceModel(void); -#if TARGET_OS_SIMULATOR /** * @return The Apple hardware descriptor of the simulated device, such as @c iPhone14,4 or @c * MacBookPro10,8 . */ NSString *_Nullable getSimulatorDeviceModel(void); -#endif // TARGET_OS_SIMULATOR /** * @return A string describing the OS version's specific build, with alphanumeric characters, like diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 4c71eb79f50..4595ec1ee08 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -235,13 +235,11 @@ #endif // TARGET_OS_SIMULATOR } -#if TARGET_OS_SIMULATOR NSString * getSimulatorDeviceModel(void) { return NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; } -#endif // TARGET_OS_SIMULATOR NSString * getOSBuildNumber(void) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 423c35959d5..5878ccec4f8 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -211,17 +211,12 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"device_architecture"] = getCPUArchitecture(); profile[@"device_locale"] = NSLocale.currentLocale.localeIdentifier; profile[@"device_manufacturer"] = @"Apple"; - profile[@"device_model"] = getDeviceModel(); + const auto isEmulated = isSimulatorBuild(); + profile[@"device_model"] = isEmulated ? getSimulatorDeviceModel() : getDeviceModel(); profile[@"device_os_build_number"] = getOSBuildNumber(); -# if TARGET_OS_SIMULATOR - const auto simulatedDevice = getSimulatorDeviceModel(); - if (simulatedDevice != nil) { - profile[@"simulated_device_model"] = simulatedDevice; - } -# endif profile[@"device_os_name"] = getOSName(); profile[@"device_os_version"] = getOSVersion(); - profile[@"device_is_emulator"] = @(isSimulatorBuild()); + profile[@"device_is_emulator"] = @(isEmulated); profile[@"device_physical_memory_bytes"] = [@(NSProcessInfo.processInfo.physicalMemory) stringValue]; profile[@"environment"] = hub.scope.environmentString ?: hub.getClient.options.environment ?: kSentryDefaultEnvironment; From 6daa6717d68e6b5b39c4aa749649d74afa64500b Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 7 Oct 2022 10:58:36 -0500 Subject: [PATCH 42/53] try linking watchkit just for pod watch targets --- Sentry.podspec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sentry.podspec b/Sentry.podspec index deba1824aec..47fff792370 100644 --- a/Sentry.podspec +++ b/Sentry.podspec @@ -20,7 +20,10 @@ Pod::Spec.new do |s| 'GCC_ENABLE_CPP_EXCEPTIONS' => 'YES', 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14', 'CLANG_CXX_LIBRARY' => 'libc++' -} + } + s.watchos.pod_target_xcconfig = { + 'OTHER_LDFLAGS' => '$(inherited) -framework WatchKit' + } s.default_subspecs = ['Core'] From 0811632d913f74715850eb755835300d19db69fb Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 7 Oct 2022 11:35:30 -0500 Subject: [PATCH 43/53] fix changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fb3c57e249..e83e265e632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Features - [Custom measurements API](https://docs.sentry.io/platforms/apple/performance/instrumentation/custom-instrumentation/) (#2268) +### Fixes + +- Device info details for profiling (#2205) ## 7.27.1 @@ -13,7 +16,6 @@ - Add app start measurement to first finished transaction (#2252) - Return SentryNoOpSpan when starting a child on a finished transaction (#2239) - Fix profiling timestamps for slow/frozen frames (#2226) -- Fix device info reporting for profiling (#2205) ## 7.27.0 From a490b9f157abd1d1c11a63b2b92481cdfa63bd51 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 11 Oct 2022 12:37:11 -0500 Subject: [PATCH 44/53] TEMP: try changing the expected catalyst OS name in test assertion --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index faffab8f644..590a0f27b10 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -83,7 +83,7 @@ - (void)testOSName #if TARGET_OS_OSX SENTRY_ASSERT_EQUAL(osName, @"macOS"); #elif TARGET_OS_MACCATALYST - SENTRY_ASSERT_EQUAL(osName, @"iPadOS"); + SENTRY_ASSERT_EQUAL(osName, @"iOS"); #elif TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. From 735f61ea8a2e1e3713b43339080dc8e5060027c5 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 11 Oct 2022 12:59:32 -0500 Subject: [PATCH 45/53] hardcode Catalyst OS name --- Sources/Sentry/SentryDevice.mm | 4 +++- Tests/SentryTests/Helper/SentryDeviceTests.mm | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 4595ec1ee08..e492d8cce4e 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -167,7 +167,9 @@ NSString * getOSName(void) { -#if SENTRY_HAS_UIKIT +#if TARGET_OS_MACCATALYST + return @"Catalyst"; +#elif SENTRY_HAS_UIKIT return UIDevice.currentDevice.systemName; #else return @"macOS"; diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index 590a0f27b10..d3f603e1c36 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -83,7 +83,7 @@ - (void)testOSName #if TARGET_OS_OSX SENTRY_ASSERT_EQUAL(osName, @"macOS"); #elif TARGET_OS_MACCATALYST - SENTRY_ASSERT_EQUAL(osName, @"iOS"); + SENTRY_ASSERT_EQUAL(osName, @"Catalyst"); #elif TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests // cannot. From 9812bcb02612a77b26bf4b60c76e09c4cd0fce94 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 11 Oct 2022 12:59:52 -0500 Subject: [PATCH 46/53] reset testing to use debug config by default --- Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme b/Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme index e2e8db46043..a09c4a9edea 100644 --- a/Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme +++ b/Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme @@ -23,7 +23,7 @@ Date: Tue, 11 Oct 2022 13:01:06 -0500 Subject: [PATCH 47/53] remove unused script --- scripts/xcode-test-devices.sh | 46 ----------------------------------- 1 file changed, 46 deletions(-) delete mode 100755 scripts/xcode-test-devices.sh diff --git a/scripts/xcode-test-devices.sh b/scripts/xcode-test-devices.sh deleted file mode 100755 index e674d65d12b..00000000000 --- a/scripts/xcode-test-devices.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# This script helps run SentryDeviceTests on all possible devices. - -set -uox pipefail - -CONFIGURATION="$1" - -# This can be one of the following options: -# - "simulators": run against all mac and simulator targets -# - "iphone": run on a real iPhone -# - "ipad": run on a real iPad -# - "tv": run on a real TV -# - "watch": run on a real Watch -DEVICE_TYPE="$2" - -if [[ $DEVICE_TYPE == "simulators" ]]; then - for DESTINATION in \ - 'platform=iOS Simulator,OS=16.0,name=iPhone SE (3rd generation)' \ - 'platform=iOS Simulator,OS=16.0,name=iPad mini (6th generation)' \ - 'platform=tvOS Simulator,OS=16.0,name=Apple TV 4K (2nd generation)' \ - 'platform=macOS,arch=arm64' \ - 'platform=macOS,arch=x86_64' \ - 'platform=macOS,arch=arm64,variant=Mac Catalyst' \ - 'platform=macOS,arch=x86_64,variant=Mac Catalyst' \ - ; do - echo "destination: '$DESTINATION'" - env NSUnbufferedIO=YES \ - xcodebuild -workspace Sentry.xcworkspace -scheme Sentry -configuration $CONFIGURATION \ - -destination "$DESTINATION" \ - -only-testing:"SentryTests/SentryDeviceTests" \ - test \ - | tee "raw-test-log-$DEVICE_TYPE-devices.log" \ - | rbenv exec bundle exec xcpretty -t - done -elif [[ $DEVICE_TYPE == "iphone" ]]; then - -elif [[ $DEVICE_TYPE == "ipad" ]]; then - -elif [[ $DEVICE_TYPE == "tv" ]]; then - -elif [[ $DEVICE_TYPE == "watch" ]]; then - -else - echo "Invalid DEVICE_TYPE. Choose from 'simulators', 'iphone', 'ipad', 'tv' or 'watch'." -fi From f225838442c5eccba3fafddb4d45c991e9a951e0 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 11 Oct 2022 10:12:36 -0800 Subject: [PATCH 48/53] prefix global functions with "sentry_" --- Sources/Sentry/SentryDevice.h | 18 +++++++++--------- Sources/Sentry/SentryDevice.mm | 18 +++++++++--------- Sources/Sentry/SentryProfiler.mm | 12 ++++++------ Tests/SentryTests/Helper/SentryDeviceTests.mm | 16 ++++++++-------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/SentryDevice.h index 56504f398de..59f1f4af961 100644 --- a/Sources/Sentry/SentryDevice.h +++ b/Sources/Sentry/SentryDevice.h @@ -9,40 +9,40 @@ NS_ASSUME_NONNULL_BEGIN /** * @return The CPU architecture name, such as @c armv7, @c arm64 or @c x86_64. */ -NSString *getCPUArchitecture(void); +NSString *sentry_getCPUArchitecture(void); /** * @return The name of the operating system, such as @c iOS or @c macOS. */ -NSString *getOSName(void); +NSString *sentry_getOSName(void); /** * @return The OS version with up to three period-delimited numbers, like @c 14 , @c 14.0 or * @c 14.0.1 . */ -NSString *getOSVersion(void); +NSString *sentry_getOSVersion(void); /** * @return The Apple hardware descriptor, such as @c iPhone14,4 or @c MacBookPro10,8 . * @note If running on a simulator, this will be the model of the simulated device. */ -NSString *getDeviceModel(void); +NSString *sentry_getDeviceModel(void); /** - * @return The Apple hardware descriptor of the simulated device, such as @c iPhone14,4 or @c - * MacBookPro10,8 . + * @return The Apple hardware descriptor of the simulated device, such as @c iPhone14,4 or + * @c MacBookPro10,8 . */ -NSString *_Nullable getSimulatorDeviceModel(void); +NSString *_Nullable sentry_getSimulatorDeviceModel(void); /** * @return A string describing the OS version's specific build, with alphanumeric characters, like * @c 21G115 . */ -NSString *getOSBuildNumber(void); +NSString *sentry_getOSBuildNumber(void); /** * @return @c YES if built and running in a simulator on a mac device, @c NO if running on a device. */ -BOOL isSimulatorBuild(void); +BOOL sentry_isSimulatorBuild(void); NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index e492d8cce4e..c831c438e0d 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -84,7 +84,7 @@ } /** - * Provided as a fallback in case @c sysctlbyname fails in @c getCPUArchitecture using the + * Provided as a fallback in case @c sysctlbyname fails in @c sentry_getCPUArchitecture using the * @c hw.cpusubtype option. * @note I've not observed a device that has needed this (armcknight 22 Sep 2022). Tested on: * @code @@ -133,7 +133,7 @@ } // namespace NSString * -getCPUArchitecture(void) +sentry_getCPUArchitecture(void) { cpu_subtype_t subtype; size_t subtypeSize = sizeof(subtype); @@ -165,7 +165,7 @@ } NSString * -getOSName(void) +sentry_getOSName(void) { #if TARGET_OS_MACCATALYST return @"Catalyst"; @@ -177,7 +177,7 @@ } NSString * -getOSVersion(void) +sentry_getOSVersion(void) { #if TARGET_OS_WATCH return WKInterfaceDevice.currentDevice.systemVersion; @@ -206,11 +206,11 @@ } NSString * -getDeviceModel(void) +sentry_getDeviceModel(void) { #if TARGET_OS_SIMULATOR // iPhone/iPad, Watch and TV simulators - const auto simulatedDeviceModelName = getSimulatorDeviceModel(); + const auto simulatedDeviceModelName = sentry_getSimulatorDeviceModel(); SENTRY_LOG_DEBUG(@"Got simulated device model name %@ (running on %@)", simulatedDeviceModelName, getHardwareDescription(HW_MODEL)); return simulatedDeviceModelName; @@ -238,13 +238,13 @@ } NSString * -getSimulatorDeviceModel(void) +sentry_getSimulatorDeviceModel(void) { return NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; } NSString * -getOSBuildNumber(void) +sentry_getOSBuildNumber(void) { char str[32]; size_t size = sizeof(str); @@ -256,7 +256,7 @@ } BOOL -isSimulatorBuild(void) +sentry_isSimulatorBuild(void) { #if TARGET_OS_SIMULATOR return true; diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 5878ccec4f8..294d90af157 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -208,14 +208,14 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"debug_meta"] = @{ @"images" : debugImages }; } - profile[@"device_architecture"] = getCPUArchitecture(); + profile[@"device_architecture"] = sentry_getCPUArchitecture(); profile[@"device_locale"] = NSLocale.currentLocale.localeIdentifier; profile[@"device_manufacturer"] = @"Apple"; - const auto isEmulated = isSimulatorBuild(); - profile[@"device_model"] = isEmulated ? getSimulatorDeviceModel() : getDeviceModel(); - profile[@"device_os_build_number"] = getOSBuildNumber(); - profile[@"device_os_name"] = getOSName(); - profile[@"device_os_version"] = getOSVersion(); + const auto isEmulated = sentry_isSimulatorBuild(); + profile[@"device_model"] = isEmulated ? sentry_getSimulatorDeviceModel() : sentry_getDeviceModel(); + profile[@"device_os_build_number"] = sentry_getOSBuildNumber(); + profile[@"device_os_name"] = sentry_getOSName(); + profile[@"device_os_version"] = sentry_getOSVersion(); profile[@"device_is_emulator"] = @(isEmulated); profile[@"device_physical_memory_bytes"] = [@(NSProcessInfo.processInfo.physicalMemory) stringValue]; diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index d3f603e1c36..a70a18287ae 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -20,7 +20,7 @@ @implementation SentryDeviceTests - (void)testCPUArchitecture { - const auto arch = getCPUArchitecture(); + const auto arch = sentry_getCPUArchitecture(); #if TARGET_OS_OSX # if TARGET_CPU_X86_64 // I observed this branch still being taken when running unit tests for macOS in Xcode 13.4.1 on @@ -74,12 +74,12 @@ - (void)testCPUArchitecture - (void)testOSVersion { - XCTAssertNotEqual(getOSVersion().length, 0U); + XCTAssertNotEqual(sentry_getOSVersion().length, 0U); } - (void)testOSName { - const auto osName = getOSName(); + const auto osName = sentry_getOSName(); #if TARGET_OS_OSX SENTRY_ASSERT_EQUAL(osName, @"macOS"); #elif TARGET_OS_MACCATALYST @@ -109,7 +109,7 @@ - (void)testOSName - (void)testDeviceModel { - const auto modelName = getDeviceModel(); + const auto modelName = sentry_getDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); #if TARGET_OS_OSX || TARGET_OS_MACCATALYST # if defined(TESTCI) || defined(TEST) @@ -142,15 +142,15 @@ - (void)testDeviceModel - (void)testOSBuildNumber { - XCTAssertNotEqual(getOSBuildNumber().length, 0U); + XCTAssertNotEqual(sentry_getOSBuildNumber().length, 0U); } - (void)testIsSimulator { #if TARGET_OS_SIMULATOR - XCTAssertTrue(isSimulatorBuild()); + XCTAssertTrue(sentry_isSimulatorBuild()); #else - XCTAssertFalse(isSimulatorBuild()); + XCTAssertFalse(sentry_isSimulatorBuild()); #endif } @@ -159,7 +159,7 @@ - (void)testSimulatedDeviceModel #if !TARGET_OS_SIMULATOR XCTSkip(@"Should only run on simulators."); #else - const auto modelName = getSimulatorDeviceModel(); + const auto modelName = sentry_getSimulatorDeviceModel(); XCTAssertNotEqual(modelName.length, 0U); # if TARGET_OS_IOS // We must test this branch in iOS-SwiftUITests since it must run on device, which SentryTests From 390784713591b8139b3e6edac57c2c29a48826b6 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 11 Oct 2022 18:13:47 +0000 Subject: [PATCH 49/53] Format code --- Sources/Sentry/SentryProfiler.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 294d90af157..b7f030a5051 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -212,7 +212,8 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransaction:(SentryTransaction *)tra profile[@"device_locale"] = NSLocale.currentLocale.localeIdentifier; profile[@"device_manufacturer"] = @"Apple"; const auto isEmulated = sentry_isSimulatorBuild(); - profile[@"device_model"] = isEmulated ? sentry_getSimulatorDeviceModel() : sentry_getDeviceModel(); + profile[@"device_model"] + = isEmulated ? sentry_getSimulatorDeviceModel() : sentry_getDeviceModel(); profile[@"device_os_build_number"] = sentry_getOSBuildNumber(); profile[@"device_os_name"] = sentry_getOSName(); profile[@"device_os_version"] = sentry_getOSVersion(); From fa218e421d5446b41433840a33b51cc1734345cb Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 12 Oct 2022 17:03:10 -0800 Subject: [PATCH 50/53] move header to /include --- Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj | 2 +- Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj | 8 ++++---- Sentry.xcodeproj/project.pbxproj | 2 +- Sources/Sentry/{ => include}/SentryDevice.h | 0 4 files changed, 6 insertions(+), 6 deletions(-) rename Sources/Sentry/{ => include}/SentryDevice.h (100%) diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj index 6203e5143ba..df7878a350c 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj @@ -244,7 +244,7 @@ 848A2573286E3351008A8858 /* PerformanceBenchmarks.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PerformanceBenchmarks.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 848A2578286E3490008A8858 /* PerformanceBenchmarks-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PerformanceBenchmarks-Info.plist"; sourceTree = ""; }; 84B527B728DD24BA00475E8D /* SentryDeviceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDeviceTests.mm; path = ../../../Tests/SentryTests/Helper/SentryDeviceTests.mm; sourceTree = ""; }; - 84B527BB28DD25E400475E8D /* SentryDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = ../../../Sources/Sentry/SentryDevice.h; sourceTree = ""; }; + 84B527BB28DD25E400475E8D /* SentryDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = ../../../Sources/Sentry/include/SentryDevice.h; sourceTree = ""; }; 84B527BC28DD25E400475E8D /* SentryDevice.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDevice.mm; path = ../../../Sources/Sentry/SentryDevice.mm; sourceTree = ""; }; 84BE546E287503F100ACC735 /* SentrySDKPerformanceBenchmarkTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySDKPerformanceBenchmarkTests.m; sourceTree = ""; }; 84BE54782876451D00ACC735 /* SentryProcessInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryProcessInfo.h; sourceTree = ""; }; diff --git a/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj b/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj index c85e2e264f0..051c92971b3 100644 --- a/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj +++ b/Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj @@ -14,10 +14,10 @@ 7BA61D6A247FA32600C130A8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7BA61D69247FA32600C130A8 /* Assets.xcassets */; }; 7BA61D70247FA32600C130A8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7BA61D6E247FA32600C130A8 /* LaunchScreen.storyboard */; }; 7BA61D7A247FA35500C130A8 /* Sentry.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7BA61D78247FA35500C130A8 /* Sentry.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 84D4FEBF28ECD8A800EDAAFE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D4FEBC28ECD8A100EDAAFE /* Sentry.framework */; }; - 84D4FEC028ECD8AF00EDAAFE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D4FEBC28ECD8A100EDAAFE /* Sentry.framework */; }; 8466D4E328DE64F100932CE7 /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8466D4E228DE64F100932CE7 /* SentryDeviceTests.mm */; }; 8466D4E428DE64F100932CE7 /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8466D4E128DE64F000932CE7 /* SentryDevice.mm */; }; + 84D4FEBF28ECD8A800EDAAFE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D4FEBC28ECD8A100EDAAFE /* Sentry.framework */; }; + 84D4FEC028ECD8AF00EDAAFE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D4FEBC28ECD8A100EDAAFE /* Sentry.framework */; }; D822A4232760D15000E7B241 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D822A4222760D15000E7B241 /* AppDelegate.swift */; }; D822A4252760D15000E7B241 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D822A4242760D15000E7B241 /* ViewController.swift */; }; D822A4282760D15000E7B241 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D822A4262760D15000E7B241 /* Main.storyboard */; }; @@ -100,10 +100,10 @@ 7BA61D6F247FA32600C130A8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 7BA61D71247FA32600C130A8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7BA61D78247FA35500C130A8 /* Sentry.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Sentry.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 8466D4DF28DE64F000932CE7 /* SentryDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = ../../../Sources/Sentry/SentryDevice.h; sourceTree = ""; }; + 8466D4DF28DE64F000932CE7 /* SentryDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = ../../../Sources/Sentry/include/SentryDevice.h; sourceTree = ""; }; 8466D4E128DE64F000932CE7 /* SentryDevice.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDevice.mm; path = ../../../Sources/Sentry/SentryDevice.mm; sourceTree = ""; }; - 84D4FEB628ECD8A100EDAAFE /* Sentry.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Sentry.xcodeproj; path = ../../Sentry.xcodeproj; sourceTree = ""; }; 8466D4E228DE64F100932CE7 /* SentryDeviceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryDeviceTests.mm; path = ../../../Tests/SentryTests/Helper/SentryDeviceTests.mm; sourceTree = ""; }; + 84D4FEB628ECD8A100EDAAFE /* Sentry.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Sentry.xcodeproj; path = ../../Sentry.xcodeproj; sourceTree = ""; }; D822A4202760D15000E7B241 /* tvOS-SBSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "tvOS-SBSwift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; D822A4222760D15000E7B241 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; D822A4242760D15000E7B241 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index ace4d5055b3..63b73d3b2f9 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -1367,7 +1367,7 @@ 844DA81F28246DE300E6B62E /* scripts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = scripts; sourceTree = ""; }; 8453421128BE855D00C22EEC /* SentrySampleDecision.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySampleDecision.m; sourceTree = ""; }; 8453421528BE8A9500C22EEC /* SentrySpanStatus.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySpanStatus.m; sourceTree = ""; }; - 84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryDevice.h; sourceTree = ""; }; + 84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = include/SentryDevice.h; sourceTree = ""; }; 84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = ""; }; 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDeviceTests.mm; sourceTree = ""; }; 861265F72404EC1500C4AFDE /* NSArray+SentrySanitize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "NSArray+SentrySanitize.h"; path = "include/NSArray+SentrySanitize.h"; sourceTree = ""; }; diff --git a/Sources/Sentry/SentryDevice.h b/Sources/Sentry/include/SentryDevice.h similarity index 100% rename from Sources/Sentry/SentryDevice.h rename to Sources/Sentry/include/SentryDevice.h From 008e1b4d421aa3258cd0495ffa2bff31363e0f98 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 12 Oct 2022 17:37:29 -0800 Subject: [PATCH 51/53] check major versions of reported versions --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index a70a18287ae..edbe4990d64 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -7,6 +7,18 @@ #define SENTRY_ASSERT_CONTAINS(parentString, childString) \ XCTAssert([parentString containsString:childString], @"Expected %@ to contain %@", \ parentString, childString) +#define SENTRY_ASSERT_PREFIX(reportedVersion, ...) \ + const auto acceptableVersions = @[ __VA_ARGS__ ]; \ + auto foundPrefix = NO; \ + for (NSString * prefix in acceptableVersions) { \ + if ([osVersion hasPrefix:prefix]) { \ + foundPrefix = YES; \ + break; \ + } \ + } \ + XCTAssertTrue(foundPrefix, \ + @"Expected major version to be one of %@. Actual version reported was %@", \ + acceptableVersions, reportedVersion); /** * @seealso TargetConditionals.h has explanations and diagrams that show the relationships between @@ -74,7 +86,19 @@ - (void)testCPUArchitecture - (void)testOSVersion { - XCTAssertNotEqual(sentry_getOSVersion().length, 0U); + const auto osVersion = sentry_getOSVersion(); + XCTAssertNotEqual(osVersion.length, 0U); +#if TARGET_OS_OSX || TARGET_OS_MACCATALYST + SENTRY_ASSERT_PREFIX(osVersion, @"10.", @"11.", @"12.", @"13."); +#elif TARGET_OS_IOS + SENTRY_ASSERT_PREFIX(osVersion, @"9.", @"10.", @"11.", @"12.", @"13.", @"14.", @"15.", @"16."); +#elif TARGET_OS_TV + SENTRY_ASSERT_PREFIX(osVersion, @"9.", @"10.", @"11.", @"12.", @"13.", @"14.", @"15.", @"16."); +#elif TARGET_OS_WATCH + SENTRY_ASSERT_PREFIX(osVersion, @"2.", @"3.", @"4.", @"5.", @"6.", @"7.", @"8.", @"9."); +#else + XCTFail(@"Unexpected OS."); +#endif } - (void)testOSName From db0d21b2aaa143c37eab6eda38b59efa1a7caa13 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 12 Oct 2022 17:56:01 -0800 Subject: [PATCH 52/53] fix osVersion tests --- Tests/SentryTests/Helper/SentryDeviceTests.mm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Tests/SentryTests/Helper/SentryDeviceTests.mm b/Tests/SentryTests/Helper/SentryDeviceTests.mm index edbe4990d64..669acf36d6c 100644 --- a/Tests/SentryTests/Helper/SentryDeviceTests.mm +++ b/Tests/SentryTests/Helper/SentryDeviceTests.mm @@ -88,11 +88,9 @@ - (void)testOSVersion { const auto osVersion = sentry_getOSVersion(); XCTAssertNotEqual(osVersion.length, 0U); -#if TARGET_OS_OSX || TARGET_OS_MACCATALYST +#if TARGET_OS_OSX SENTRY_ASSERT_PREFIX(osVersion, @"10.", @"11.", @"12.", @"13."); -#elif TARGET_OS_IOS - SENTRY_ASSERT_PREFIX(osVersion, @"9.", @"10.", @"11.", @"12.", @"13.", @"14.", @"15.", @"16."); -#elif TARGET_OS_TV +#elif TARGET_OS_IOS || TARGET_OS_MACCATALYST || TARGET_OS_TV SENTRY_ASSERT_PREFIX(osVersion, @"9.", @"10.", @"11.", @"12.", @"13.", @"14.", @"15.", @"16."); #elif TARGET_OS_WATCH SENTRY_ASSERT_PREFIX(osVersion, @"2.", @"3.", @"4.", @"5.", @"6.", @"7.", @"8.", @"9."); From 5e5fc5054776ca35bdd62114f7e7466d87dfaeaf Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 13 Oct 2022 10:14:57 -0800 Subject: [PATCH 53/53] fixup changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e83e265e632..f78a7248079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - [Custom measurements API](https://docs.sentry.io/platforms/apple/performance/instrumentation/custom-instrumentation/) (#2268) + ### Fixes - Device info details for profiling (#2205)