MetrikKit: signpostMetrics is always empty

huangapple go评论51阅读模式
英文:

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, ...)

英文:

Try to use MetricKit methods

mxSignpost(.begin, ...)

mxSignpost(.end, ...)

huangapple
  • 本文由 发表于 2023年3月9日 21:00:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684983.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定