英文:
MetrikKit: signpostMetrics is always empty
问题
我已设置MetricKit
在我的iOS应用程序中,以便将从os_signpost
获取的性能测量数据发送到我的自定义分析端点。我按照例如这里描述的方式进行了设置:https://nshipster.com/metrickit/ 或者这里 https://www.avanderlee.com/swift/metrickit-launch-time/。
这是相关的代码:
import MetricKit
class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: LaunchOptions?) -> Bool {
MXMetricManager.shared.add(self)
// ...
}
}
class Elsewhere {
func someFunc() {
// 我已经验证过这确实被调用了
let log = OSLog(subsystem: OSLog.subsystem, category: "someFunc")
let signpostID = OSSignpostID(log: log, object: self)
os_signpost(.begin, log: log, name: "someFunc", signpostID: signpostID)
// 一些代码
os_signpost(.end, log: log, name: "someFunc", signpostID: signpostID)
}
}
extension AppDelegate: MXMetricManagerSubscriber {
public func didReceive(_ payloads: [MXMetricPayload]) {
for payload in payloads {
for metric in payload.signpostMetrics {
// 这从不会被调用,因为signpostMetrics始终为空 :(
}
}
}
}
所以我的问题是,signpostMetrics
总是为空。我期望它包含了由我的代码中的 os_signpost
收集的数据。
英文:
I have set up MetricKit
in my iOS app in order to send performance measurements taken from os_signpost
to my custom analytics endpoint.
I did the setup like it is described for example here:
https://nshipster.com/metrickit/
or here
https://www.avanderlee.com/swift/metrickit-launch-time/ .
This is the relevant code:
import MetricKit
class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication
, didFinishLaunchingWithOptions launchOptions: LaunchOptions?) -> Bool {
MXMetricManager.shared.add(self)
// ...
}
}
class Elsewhere {
func someFunc() {
// I verified that this is indeed being called
let log = OSLog(subsystem: OSLog.subsystem, category: "someFunc")
let signpostID = OSSignpostID(log: log, object: self)
os_signpost(.begin, log: log, name: "someFunc", signpostID: signpostID)
// some code
os_signpost(.end, log: log, name: "someFunc", signpostID: signpostID)
}
}
extension AppDelegate: MXMetricManagerSubscriber {
public func didReceive(_ payloads: [MXMetricPayload]) {
for payload in payloads {
for metric in payload.signpostMetrics {
// this never gets called because signpostMetrics is always empty :(
}
}
}
}
So my problem is, that signpostMetrics
is always empty. I would expect it to contain the data that got collected by the os_signpost in my code.
答案1
得分: 1
尝试使用MetricKit方法
mxSignpost(.begin, ...)
mxSignpost(.end, ...)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论