Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK profiler #412

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:
name: Build and analyse default scheme using xcodebuild command
runs-on: macos-latest
runs-on: macos-15 # public preview, we want xcode 16.0 for swift testing

steps:
- name: Checkout
Expand All @@ -18,4 +18,4 @@ jobs:
env:
scheme: RadarSDK
run: |
xcodebuild clean build analyze test -scheme RadarSDK -workspace Example/Example.xcodeproj/project.xcworkspace -destination 'name=iPhone 15 Pro' | xcpretty && exit ${PIPESTATUS[0]}
xcodebuild clean build analyze test -scheme RadarSDK -workspace Example/Example.xcodeproj/project.xcworkspace -destination 'name=iPhone 16' | xcpretty && exit ${PIPESTATUS[0]}
6 changes: 3 additions & 3 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIWindowSceneDelegate, UN
let radarInitializeOptions = RadarInitializeOptions()
// Uncomment to enable automatic setup for notification conversions
// radarInitializeOptions.autoSetupNotificationConversion = true
Radar.initialize(publishableKey: "prj_test_pk_0000000000000", options: radarInitializeOptions )
Radar.initialize(publishableKey: "prj_test_pk_0000000000000000000000000000000000000000", options: radarInitializeOptions )
Radar.setUserId("testUserId")
Radar.setMetadata([ "foo": "bar" ])
Radar.setDelegate(self)
Expand Down Expand Up @@ -113,13 +113,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIWindowSceneDelegate, UN

demoButton(text: "getVerifiedLocationToken") {
Radar.getVerifiedLocationToken() { (status, token) in
print("getVerifiedLocationToken: status = \(status); token = \(token?.dictionaryValue())")
print("getVerifiedLocationToken: status = \(Radar.stringForStatus(status)); token = \(String(describing: token?.dictionaryValue()))")
}
}

demoButton(text: "trackVerified") {
Radar.trackVerified() { (status, token) in
print("TrackVerified: status = \(status); token = \(token?.dictionaryValue())")
print("TrackVerified: status = \(Radar.stringForStatus(status)); token = \(String(describing: token?.dictionaryValue()))")
}
}

Expand Down
3 changes: 2 additions & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Pod::Spec.new do |s|
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
s.platform = :ios
s.source = { :git => 'https://github.com/radarlabs/radar-sdk-ios.git', :tag => s.version.to_s }
s.source_files = ["RadarSDK/*.{h,m}", "RadarSDK/Internal/*.{h,m}", "RadarSDK/Include/*.h"]
s.source_files = ["RadarSDK/*.{h,m,swift}", "RadarSDK/Include/*.h"]
s.module_name = 'RadarSDK'
s.ios.deployment_target = '10.0'
s.frameworks = 'CoreLocation'
s.requires_arc = true
s.license = { :type => 'Apache-2.0' }
s.resource_bundles = {'RadarSDK' => ['RadarSDK/PrivacyInfo.xcprivacy']}
s.swift_version = '5.0'
end
29 changes: 27 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
F65AF72C2C10B242002BA009 /* get_config_response.json in Resources */ = {isa = PBXBuildFile; fileRef = F65AF72B2C10B242002BA009 /* get_config_response.json */; };
F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */; };
F667F8292BFBF3D1001F2F67 /* RadarSdkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */; };
F69AA9602CE52FB1009CF18B /* RadarTelemetry.h in Headers */ = {isa = PBXBuildFile; fileRef = F69AA95F2CE52FAC009CF18B /* RadarTelemetry.h */; };
F69AA9622CE52FC6009CF18B /* RadarTelemetry.swift in Sources */ = {isa = PBXBuildFile; fileRef = F69AA9612CE52FC6009CF18B /* RadarTelemetry.swift */; };
F69AA9652CE53E08009CF18B /* RadarSDKTestsSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = F69AA9642CE53E08009CF18B /* RadarSDKTestsSwift.swift */; };
F69AA9662CE53FAE009CF18B /* RadarTelemetry.swift in Sources */ = {isa = PBXBuildFile; fileRef = F69AA9612CE52FC6009CF18B /* RadarTelemetry.swift */; };
F6F959802C3D7D9900BC30FE /* RadarTimeZone.h in Headers */ = {isa = PBXBuildFile; fileRef = F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */; settings = {ATTRIBUTES = (Public, ); }; };
F6F959822C3D7EA200BC30FE /* RadarTimeZone+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = F6F959812C3D7EA200BC30FE /* RadarTimeZone+Internal.h */; };
F6F959842C3D7EDE00BC30FE /* RadarTimeZone.m in Sources */ = {isa = PBXBuildFile; fileRef = F6F959832C3D7EDE00BC30FE /* RadarTimeZone.m */; };
Expand Down Expand Up @@ -356,6 +360,10 @@
F65AF72B2C10B242002BA009 /* get_config_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = get_config_response.json; sourceTree = "<group>"; };
F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarSdkConfiguration.m; sourceTree = "<group>"; };
F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarSdkConfiguration.h; sourceTree = "<group>"; };
F69AA95F2CE52FAC009CF18B /* RadarTelemetry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarTelemetry.h; sourceTree = "<group>"; };
F69AA9612CE52FC6009CF18B /* RadarTelemetry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadarTelemetry.swift; sourceTree = "<group>"; };
F69AA9632CE53E07009CF18B /* RadarSDKTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RadarSDKTests-Bridging-Header.h"; sourceTree = "<group>"; };
F69AA9642CE53E08009CF18B /* RadarSDKTestsSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadarSDKTestsSwift.swift; sourceTree = "<group>"; };
F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarTimeZone.h; sourceTree = "<group>"; };
F6F959812C3D7EA200BC30FE /* RadarTimeZone+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RadarTimeZone+Internal.h"; sourceTree = "<group>"; };
F6F959832C3D7EDE00BC30FE /* RadarTimeZone.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarTimeZone.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -502,6 +510,8 @@
E6EEC56F2B20F45D00DD096B /* RadarFileStorage.m */,
96A5A11727ADA02E007B960B /* RadarDelegateHolder.h */,
DD4C104925D87E3E009C2E36 /* RadarDelegateHolder.m */,
F69AA95F2CE52FAC009CF18B /* RadarTelemetry.h */,
F69AA9612CE52FC6009CF18B /* RadarTelemetry.swift */,
DD236CF723088F8400EB88F9 /* RadarLocationManager.h */,
DD236CF823088F8400EB88F9 /* RadarLocationManager.m */,
96A5A11527ADA02E007B960B /* RadarLog.h */,
Expand Down Expand Up @@ -542,6 +552,7 @@
DD236C822308797B00EB88F9 /* RadarSDKTests */ = {
isa = PBXGroup;
children = (
F69AA9632CE53E07009CF18B /* RadarSDKTests-Bridging-Header.h */,
96B465BB27D6732500D7119B /* CLLocation+RadarTests.m */,
DD8E2F7824018C37002D51AB /* CLLocationManagerMock.h */,
DD8E2F7924018C37002D51AB /* CLLocationManagerMock.m */,
Expand All @@ -551,6 +562,7 @@
DD8E2F7524018C25002D51AB /* RadarAPIHelperMock.h */,
DD8E2F7624018C25002D51AB /* RadarAPIHelperMock.m */,
DD8E2F7224018C17002D51AB /* RadarPermissionsHelperMock.h */,
F69AA9642CE53E08009CF18B /* RadarSDKTestsSwift.swift */,
DD8E2F7324018C17002D51AB /* RadarPermissionsHelperMock.m */,
DD103210237E0C47003DD408 /* RadarSDKTests.m */,
DD8E2F6F24018BF8002D51AB /* RadarTestUtils.h */,
Expand Down Expand Up @@ -672,6 +684,7 @@
96A5A10427AD9F7F007B960B /* RadarDelegate.h in Headers */,
01F810702AF0119800BD7088 /* RadarVerifiedDelegate.h in Headers */,
96A5A0CA27AD9F41007B960B /* RadarTrip+Internal.h in Headers */,
F69AA9602CE52FB1009CF18B /* RadarTelemetry.h in Headers */,
96A5A0FF27AD9F7F007B960B /* RadarGeofenceGeometry.h in Headers */,
96A5A0CB27AD9F41007B960B /* RadarRoute+Internal.h in Headers */,
96A5A10527AD9F7F007B960B /* RadarTrackingOptions.h in Headers */,
Expand Down Expand Up @@ -767,14 +780,14 @@
TargetAttributes = {
0107A9E72621FFB9008AB52F = {
CreatedOnToolsVersion = 12.4;
LastSwiftMigration = 1320;
LastSwiftMigration = 1610;
};
0107AB3826220308008AB52F = {
CreatedOnToolsVersion = 12.4;
};
DD236C7D2308797B00EB88F9 = {
CreatedOnToolsVersion = 11.0;
LastSwiftMigration = 1320;
LastSwiftMigration = 1610;
};
};
};
Expand Down Expand Up @@ -886,6 +899,7 @@
96FC90F7277379C1000757DF /* RadarFraud.m in Sources */,
F6F959842C3D7EDE00BC30FE /* RadarTimeZone.m in Sources */,
0107AB1D262201E5008AB52F /* RadarLocationManager.m in Sources */,
F69AA9622CE52FC6009CF18B /* RadarTelemetry.swift in Sources */,
0107AAB02622016B008AB52F /* RadarPlace.m in Sources */,
0107AAE6262201A1008AB52F /* RadarSegment.m in Sources */,
0107AB20262201E9008AB52F /* RadarPermissionsHelper.m in Sources */,
Expand Down Expand Up @@ -922,8 +936,10 @@
DD8E2F7424018C17002D51AB /* RadarPermissionsHelperMock.m in Sources */,
DD8E2F7724018C25002D51AB /* RadarAPIHelperMock.m in Sources */,
E658DB0A2CB462AA004E0F01 /* RadarOperatingHour.m in Sources */,
F69AA9652CE53E08009CF18B /* RadarSDKTestsSwift.swift in Sources */,
96B465BC27D6732500D7119B /* CLLocation+RadarTests.m in Sources */,
E6B93B742C90E5B8003CB858 /* RadarInitializeOptions.m in Sources */,
F69AA9662CE53FAE009CF18B /* RadarTelemetry.swift in Sources */,
DD103211237E0C47003DD408 /* RadarSDKTests.m in Sources */,
DD8E2F7124018BF9002D51AB /* RadarTestUtils.m in Sources */,
DD8E2F7D24018C54002D51AB /* CLVisitMock.m in Sources */,
Expand All @@ -937,6 +953,7 @@
0107A9ED2621FFB9008AB52F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -959,6 +976,8 @@
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
};
Expand All @@ -967,6 +986,7 @@
0107A9EE2621FFB9008AB52F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -989,6 +1009,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
};
Expand Down Expand Up @@ -1143,6 +1164,7 @@
DEVELOPMENT_TEAM = 96GHH65B9D;
HEADER_SEARCH_PATHS = "$(SRCROOT)/RadarSDK";
INFOPLIST_FILE = RadarSDKTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1151,6 +1173,7 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = io.radar.RadarSDKTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "RadarSDKTests/RadarSDKTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -1165,6 +1188,7 @@
DEVELOPMENT_TEAM = 96GHH65B9D;
HEADER_SEARCH_PATHS = "$(SRCROOT)/RadarSDK";
INFOPLIST_FILE = RadarSDKTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1173,6 +1197,7 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = io.radar.RadarSDKTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "RadarSDKTests/RadarSDKTests-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
2 changes: 2 additions & 0 deletions RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ typedef NS_ENUM(NSInteger, RadarLogType) {
RadarLogTypeAppLifecycleEvent = 4,
/// Permission Event
RadarLogTypePermissionEvent = 5,
/// Telemetry
RadarLogTypeTelemetry = 6,
};

/**
Expand Down
23 changes: 23 additions & 0 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "RadarReplayBuffer.h"
#import "RadarNotificationHelper.h"
#import "RadarTripOptions.h"
#import "RadarTelemetry.h"

@interface Radar ()

Expand Down Expand Up @@ -175,10 +176,17 @@ + (void)trackOnceWithCompletionHandler:(RadarTrackCompletionHandler)completionHa
}

+ (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desiredAccuracy beacons:(BOOL)beacons completionHandler:(RadarTrackCompletionHandler)completionHandler {

RadarTelemetry* telemetry = [[RadarTelemetry alloc] init];
[telemetry start:@"total"];
[telemetry start:@"getLocation"];

[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"trackOnce()"];
[[RadarLocationManager sharedInstance]
getLocationWithDesiredAccuracy:desiredAccuracy
completionHandler:^(RadarStatus status, CLLocation *_Nullable location, BOOL stopped) {
[telemetry end:@"getLocation"];

if (status != RadarStatusSuccess) {
if (completionHandler) {
[RadarUtils runOnMainThread:^{
Expand All @@ -190,6 +198,7 @@ + (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desire
}

void (^callTrackAPI)(NSArray<RadarBeacon *> *_Nullable) = ^(NSArray<RadarBeacon *> *_Nullable beacons) {
[telemetry start:@"trackAPI"];
[[RadarAPIClient sharedInstance]
trackWithLocation:location
stopped:stopped
Expand All @@ -199,6 +208,9 @@ + (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desire
beacons:beacons
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarEvent *> *_Nullable events, RadarUser *_Nullable user,
NSArray<RadarGeofence *> *_Nullable nearbyGeofences, RadarConfig *_Nullable config, RadarVerifiedLocationToken *_Nullable token) {
[telemetry end:@"trackAPI"];
[telemetry end:@"total"];

if (status == RadarStatusSuccess) {
[[RadarLocationManager sharedInstance] replaceSyncedGeofences:nearbyGeofences];
if (config != nil) {
Expand All @@ -207,6 +219,11 @@ + (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desire

}

[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo
type:RadarLogTypeTelemetry
message:[NSString stringWithFormat:@"trackOnce | %@",
[telemetry formatted]]];

if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, location, events, user);
Expand All @@ -216,18 +233,22 @@ + (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desire
};

if (beacons) {
[telemetry start:@"getBeacons"];
[[RadarAPIClient sharedInstance]
searchBeaconsNear:location
radius:1000
limit:10
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarBeacon *> *_Nullable beacons,
NSArray<NSString *> *_Nullable beaconUUIDs) {
[telemetry end:@"getBeacons"];
if (beaconUUIDs && beaconUUIDs.count) {
[[RadarLocationManager sharedInstance] replaceSyncedBeaconUUIDs:beaconUUIDs];

[RadarUtils runOnMainThread:^{
[telemetry start:@"rangeBeacons"];
[[RadarBeaconManager sharedInstance] rangeBeaconUUIDs:beaconUUIDs
completionHandler:^(RadarStatus status, NSArray<RadarBeacon *> *_Nullable beacons) {
[telemetry end:@"rangeBeacons"];
if (status != RadarStatusSuccess || !beacons) {
callTrackAPI(nil);

Expand All @@ -241,8 +262,10 @@ + (void)trackOnceWithDesiredAccuracy:(RadarTrackingOptionsDesiredAccuracy)desire
[[RadarLocationManager sharedInstance] replaceSyncedBeacons:beacons];

[RadarUtils runOnMainThread:^{
[telemetry start:@"rangeBeacons"];
[[RadarBeaconManager sharedInstance] rangeBeacons:beacons
completionHandler:^(RadarStatus status, NSArray<RadarBeacon *> *_Nullable beacons) {
[telemetry end:@"rangeBeacons"];
if (status != RadarStatusSuccess || !beacons) {
callTrackAPI(nil);

Expand Down
1 change: 1 addition & 0 deletions RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import "RadarUtils.h"
#import "RadarVerificationManager.h"
#import "RadarVerifiedLocationToken+Internal.h"

#import <os/log.h>

@implementation RadarAPIClient
Expand Down
3 changes: 3 additions & 0 deletions RadarSDK/RadarLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ + (NSString *)stringForLogType:(RadarLogType)type {
case RadarLogTypePermissionEvent:
str = @"PERMISSION_EVENT";
break;
case RadarLogTypeTelemetry:
str = @"TELEMETRY";
break;
}
return str;
}
Expand Down
18 changes: 18 additions & 0 deletions RadarSDK/RadarTelemetry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// RadarProfiler.h
// RadarSDK
//
// Copyright © 2024 Radar Labs, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface RadarTelemetry: NSObject

- (void)start:(NSString*_Nullable)tag;
- (void)end:(NSString*_Nullable)tag;
- (double)get:(NSString*_Nullable)tag;
- (NSString*_Nonnull)formatted;

@end
Loading