-
Notifications
You must be signed in to change notification settings - Fork 6
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
Try to reduce time taken to get a trackable online #481
Draft
lawrence-forooghian
wants to merge
3
commits into
main
Choose a base branch
from
425-only-first-trackable-added-comes-online-when-stationary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Tools/Analysis/AnalyzeLocationEventFrequencies/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-argument-parser", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-argument-parser", | ||
"state" : { | ||
"revision" : "fddd1c00396eed152c45a46bea9f47b98e59301d", | ||
"version" : "1.2.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
24 changes: 24 additions & 0 deletions
24
Tools/Analysis/AnalyzeLocationEventFrequencies/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// swift-tools-version: 5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "AnalyzeLocationEventFrequencies", | ||
platforms: [ | ||
.macOS(.v12) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"), | ||
.package(path: "../../Library/LogParser") | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "AnalyzeLocationEventFrequencies", | ||
dependencies: [ | ||
.product(name: "LogParser", package: "LogParser"), | ||
.product(name: "ArgumentParser", package: "swift-argument-parser") | ||
] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# AnalyzeLocationEventFrequencies | ||
|
||
This script is intended to help analyse the impact of restarting `CLLocationManager` each time `AblyAssetTrackingPublisher.DefaultLocationManager`’s `requestLocationUpdate` is called, specifically whether it negatively impacts: | ||
|
||
- the frequency at which the SDK receives location updates | ||
- the Mapbox SDK’s location recording | ||
|
||
You can run it on a file containing log output from the publisher example app by running the following command from the current directory: | ||
|
||
```bash | ||
swift run AnalyzeLocationEventFrequencies <file> | ||
``` | ||
|
||
There is an example log file `example.txt` that you can try this out on. It produces a CSV with contents like this: | ||
|
||
|Timestamp (ISO 8601) |Event type |Time since last location update|Time since last recorded location| | ||
|------------------------|-----------------------|-------------------------------|---------------------------------| | ||
|2022-12-15T19:52:19.421Z|Recorded location | | | | ||
|2022-12-15T19:52:20.035Z|Location update | | | | ||
|2022-12-15T19:52:32.429Z|Recorded location | |13.007 | | ||
|2022-12-15T19:52:32.443Z|Location update |12.408 | | | ||
|2022-12-15T19:52:38.433Z|Recorded location | |6.004 | | ||
|2022-12-15T19:52:38.441Z|Location update |5.998 | | | ||
|2022-12-15T19:52:43.423Z|Recorded location | |4.990 | | ||
|2022-12-15T19:52:43.439Z|Location update |4.998 | | | ||
|2022-12-15T19:52:47.419Z|Recorded location | |3.996 | | ||
|2022-12-15T19:52:47.434Z|Location update |3.995 | | | ||
|2022-12-15T19:52:51.421Z|Recorded location | |4.002 | | ||
|2022-12-15T19:52:51.442Z|Location update |4.008 | | | ||
|2022-12-15T19:52:53.428Z|Recorded location | |2.007 | | ||
|2022-12-15T19:52:53.603Z|Request location update| | | | ||
|2022-12-15T19:52:53.615Z|Location update |2.173 | | | ||
|2022-12-15T19:52:57.420Z|Recorded location | |3.992 | | ||
|2022-12-15T19:52:57.429Z|Location update |3.814 | | | ||
|2022-12-15T19:53:01.427Z|Recorded location | |4.007 | | ||
|2022-12-15T19:53:01.433Z|Location update |4.004 | | | ||
|2022-12-15T19:53:04.429Z|Recorded location | |3.002 | | ||
|2022-12-15T19:53:04.445Z|Location update |3.012 | | | ||
|2022-12-15T19:53:07.434Z|Recorded location | |3.005 | | ||
|2022-12-15T19:53:07.447Z|Location update |3.002 | | | ||
|2022-12-15T19:53:10.433Z|Recorded location | |2.999 | | ||
|2022-12-15T19:53:10.443Z|Location update |2.996 | | | ||
|2022-12-15T19:53:11.424Z|Recorded location | |0.991 | | ||
|2022-12-15T19:53:11.923Z|Request location update| | | | ||
|2022-12-15T19:53:11.928Z|Location update |1.485 | | | ||
|2022-12-15T19:53:15.418Z|Recorded location | |3.994 | | ||
|2022-12-15T19:53:15.433Z|Location update |3.505 | | | ||
|2022-12-15T19:53:19.424Z|Recorded location | |4.006 | | ||
|2022-12-15T19:53:19.439Z|Location update |4.006 | | | ||
|2022-12-15T19:53:23.433Z|Recorded location | |4.010 | | ||
|2022-12-15T19:53:23.448Z|Location update |4.009 | | | ||
|2022-12-15T19:53:26.420Z|Recorded location | |2.987 | | ||
|2022-12-15T19:53:26.436Z|Location update |2.988 | | | ||
|2022-12-15T19:53:29.429Z|Recorded location | |3.009 | | ||
|2022-12-15T19:53:29.445Z|Location update |3.009 | | | ||
|2022-12-15T19:53:33.429Z|Recorded location | |4.000 | | ||
|2022-12-15T19:53:33.443Z|Location update |3.998 | | |
15 changes: 15 additions & 0 deletions
15
...nalysis/AnalyzeLocationEventFrequencies/Sources/AnalyzeLocationEventFrequencies/CSV.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
protocol CSVRowConvertible { | ||
var csvRows: [String] { get } | ||
} | ||
|
||
protocol CSVRowWithColumnNamesConvertible: CSVRowConvertible { | ||
static var csvHeaders: [String] { get } | ||
} | ||
|
||
enum CSVExport { | ||
// A very rudimentary CSV export that does no quoting or escaping or anything like that. | ||
static func export<T: CSVRowWithColumnNamesConvertible>(rows: [T]) -> String { | ||
let csvRowStrings = ([T.csvHeaders] + rows.map(\.csvRows)).map { $0.joined(separator: ",") } | ||
return csvRowStrings.joined(separator: "\n") | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...lysis/AnalyzeLocationEventFrequencies/Sources/AnalyzeLocationEventFrequencies/Event.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Foundation | ||
|
||
struct Event: Comparable, CSVRowWithColumnNamesConvertible { | ||
var timestamp: Date | ||
var type: EventType | ||
|
||
enum EventType: CSVRowWithColumnNamesConvertible, Hashable { | ||
case locationUpdate | ||
case requestLocationUpdate | ||
case recordedLocation | ||
|
||
static var csvHeaders: [String] { | ||
return ["Event type"] | ||
} | ||
|
||
var csvRows: [String] { | ||
switch self { | ||
case .locationUpdate: | ||
return ["Location update"] | ||
case .requestLocationUpdate: | ||
return ["Request location update"] | ||
case .recordedLocation: | ||
return ["Recorded location"] | ||
} | ||
} | ||
} | ||
|
||
static func < (lhs: Event, rhs: Event) -> Bool { | ||
return lhs.timestamp < rhs.timestamp | ||
} | ||
|
||
static func fromLogLine(_ logLine: LogLine) -> [Self] { | ||
switch logLine { | ||
case let .locationUpdate(timestamp): | ||
return [.init(timestamp: timestamp, type: .locationUpdate)] | ||
case let .requestLocationUpdate(timestamp): | ||
return [.init(timestamp: timestamp, type: .requestLocationUpdate)] | ||
case let .locationHistoryData(locationHistoryData): | ||
return locationHistoryData.events.map { event in | ||
return .init(timestamp: Date(timeIntervalSince1970: event.properties.time), type: .recordedLocation) | ||
} | ||
} | ||
} | ||
|
||
static var csvHeaders: [String] { | ||
return ["Timestamp (ISO 8601)"] + EventType.csvHeaders | ||
} | ||
|
||
var csvRows: [String] { | ||
let formatter = ISO8601DateFormatter() | ||
formatter.formatOptions = [.withFractionalSeconds, .withInternetDateTime] | ||
return [formatter.string(from: timestamp)] + type.csvRows | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ationEventFrequencies/Sources/AnalyzeLocationEventFrequencies/EventWithCalculations.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Foundation | ||
|
||
struct EventWithCalculations: CSVRowWithColumnNamesConvertible { | ||
var event: Event | ||
var timeSinceLastOfType: TimeInterval? | ||
|
||
static func fromEvents(_ events: [Event]) -> [EventWithCalculations] { | ||
var lastTimestamps: [Event.EventType : Date] = [:] | ||
|
||
return events.map { event in | ||
let timeSinceLastOfType: TimeInterval? | ||
if let lastTimestamp = lastTimestamps[event.type] { | ||
timeSinceLastOfType = event.timestamp.timeIntervalSince(lastTimestamp) | ||
} else { | ||
timeSinceLastOfType = nil | ||
} | ||
|
||
lastTimestamps[event.type] = event.timestamp | ||
|
||
return .init(event: event, timeSinceLastOfType: timeSinceLastOfType) | ||
} | ||
} | ||
|
||
static var csvHeaders: [String] { | ||
return Event.csvHeaders + ["Time since last location update", "Time since last recorded location"] | ||
} | ||
|
||
var csvRows: [String] { | ||
let formattedTimeSinceLastOfType: String | ||
if let timeSinceLastOfType { | ||
formattedTimeSinceLastOfType = String(format: "%.3f", timeSinceLastOfType) | ||
} else { | ||
formattedTimeSinceLastOfType = "" | ||
} | ||
|
||
return event.csvRows + [ | ||
event.type == .locationUpdate ? formattedTimeSinceLastOfType : "", | ||
event.type == .recordedLocation ? formattedTimeSinceLastOfType : "" | ||
] | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ocationEventFrequencies/Sources/AnalyzeLocationEventFrequencies/LocationHistoryData.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/// A subset of AblyAssetTrackingCore’s same type. | ||
struct LocationHistoryData: Codable { | ||
var events: [GeoJSONMessage] | ||
|
||
struct GeoJSONMessage: Codable { | ||
var properties: GeoJSONProperties | ||
|
||
struct GeoJSONProperties: Codable { | ||
/** | ||
Timestamp from a moment when measurment was done (in seconds since 1st of January 1970) | ||
*/ | ||
let time: Double | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...sis/AnalyzeLocationEventFrequencies/Sources/AnalyzeLocationEventFrequencies/LogLine.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
import LogParser | ||
|
||
enum LogLine { | ||
case locationUpdate(timestamp: Date) | ||
case requestLocationUpdate(timestamp: Date) | ||
case locationHistoryData(LocationHistoryData) | ||
|
||
private struct KnownLogMessage { | ||
var lastSubsystem: String | ||
var prefix: String | ||
|
||
static let locationUpdate = Self(lastSubsystem: "DefaultLocationService", prefix: "passiveLocationManager.didUpdateLocation") | ||
static let requestLocationUpdate = Self(lastSubsystem: "DefaultLocationService", prefix: "Received requestLocationUpdate") | ||
|
||
func matches(_ exampleAppSDKLine: ExampleAppSDKLogLine) -> Bool { | ||
return exampleAppSDKLine.message.subsystems.last == lastSubsystem && exampleAppSDKLine.message.message.hasPrefix(prefix) | ||
} | ||
} | ||
|
||
init?(exampleAppLine: ExampleAppLogFile.Line) { | ||
switch exampleAppLine { | ||
case let .other(line): | ||
let prefix = "Received location history data: " | ||
guard let prefixRange = line.range(of: prefix) else { | ||
return nil | ||
} | ||
|
||
let jsonString = line[prefixRange.upperBound...] | ||
let jsonData = jsonString.data(using: .utf8)! | ||
let locationHistoryData = try! JSONDecoder().decode(LocationHistoryData.self, from: jsonData) | ||
self = .locationHistoryData(locationHistoryData) | ||
case let .sdk(exampleAppSDKLine): | ||
if KnownLogMessage.locationUpdate.matches(exampleAppSDKLine) { | ||
self = .locationUpdate(timestamp: exampleAppSDKLine.timestamp) | ||
} else if KnownLogMessage.requestLocationUpdate.matches(exampleAppSDKLine) { | ||
self = .requestLocationUpdate(timestamp: exampleAppSDKLine.timestamp) | ||
} else { | ||
return nil | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how this affects the Mapbox SDK 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all good questions, I'll look into it and get back to you 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a script for analysing the logs from the publisher example app, to find out if the frequencies of location updates and recorded locations is affected. My brief investigation using the iOS simulator suggests that they are not. However, I want to test on a device too, and for that we'll probably need to add the ability to log to a file. Once I've done that and gathered some results from a device, I'll post my findings here in detail.
As for resources (which I'm mainly taking to mean battery life), I do not know what the impact would be. I could have a think about how to investigate it, but I don't have any ideas off the top of my head.