Metrics Library for iOS Performance Debugging Using OSLog and Xray
A step-by-step guide for using Xray programmatically.
Promoted provides an "Xray" functionality in the iOS and Android SDKs for debugging purposes.
Setup
In your ClientConfig
(PROClientConfig
) object, set the xrayEnabled
and osLogEnabled
flags to true (YES). This must be done before service startup. For example, this would occur in AppDelegate.m
in the promotedMetricsModule
method:
- (PromotedMetricsModule *)promotedMetricsModule {
PROClientConfig *config = [[PROClientConfig alloc] init];
// ...
config.osLogEnabled = YES;
config.xrayEnabled = YES;
PROMetricsLoggerService *service =
[[PROMetricsLoggerService alloc] initWithInitialConfig:config];
[service startLoggingServices];
return [[PromotedMetricsModule alloc] initWithMetricsLoggerService:service];
}
OSLog
Logs will be sent to the subsystem ai.promoted with categories MetricsLogger
and Xray
.
To view these logs in development via Xcode, look in Xcode’s console output and look for the categories above. You can filter the logs to these categories.
To view these logs when not running under Xcode, either on debug or production:
- If your iPhone is connected to your Mac, open the Console app and select your iPhone from the sidebar. Then hit Start in the toolbar to begin collecting logs. You can filter the logs to narrow them down.
- If your iPhone is not connected to a Mac, capture a sysdiagnose and inspect the logs inside the resulting file.
Xray
You can access the Xray object programmatically at MetricsLoggerService.xray
. The relevant properties on Xray are:
Properties | Description |
---|---|
| Total serialized bytes sent across the network. |
| Total number of requests sent across the network. |
| Total time spent in Promoted logging code. |
| Most recent network batches. |
| Flattened logging calls across networkBatches. |
| Flattened errors across networkBatches. |
Xray also prints a summary of metrics for the latest batch and cumulative resources used at the end of every network flush.
Set a breakpoint in MetricsLogger.handleFlushResponse()
to view the result of metrics logging calls. You can inspect the properties of Xray via the debugger via the xray property of MetricsLogger
.
private func handleFlushResponse(data: Data?, error: Error?) {
osLog?.info("Logging finished")
if let e = error {
osLog?.error("flush/sendMessage: %{public}@",
e.localizedDescription)
xray?.metricsLoggerBatchResponseDidError(e)
}
xray?.metricsLoggerBatchResponseDidComplete()
}
If you would like to use OSLog or Xray for debugging, please coordinate with the Promoted team for additional details and guidance.
Updated 2 months ago