仪器 OSSignpost 间隔未记录或显示

问题描述 投票:0回答:2

我正在尝试使用 OSSignposter 捕获我们应用程序中的间隔以在 Instruments 中使用。此处的示例代码适用于新项目。我看到间隔、路标图标等。但是,相同的代码(集成到更大的应用程序中)不会记录或显示任何间隔。

我可以获取两个应用程序的 oslog 配置的配置状态,没有区别。

sudo log config --status --subsystem **.*******.*******.signposttest
Mode for '**.*******.*******.signposttest'  INFO PERSIST_DEFAULT

我已经检查了工作区和方案。这些项目之间没有区别。此时我唯一能想到的是可能影响它的构建设置。 (我没有使用 OS_ACTIVITY_MODE = 禁用)。

也许这是配置文件问题?权利?但是,我尝试使用调试配置文件在调试模式下进行分析,并得到了相同的结果。

immediate mode
deferred mode
中没有看到任何路标活动。我在“列表:事件”视图的底部窗格中看到事件。在
last n seconds mode
中,没有数据,没有车道,时间线上也没有任何内容。

这是示例代码。我在这两个项目中都尝试过。


import os.signpost

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var blackWindow: UIWindow?
    var alertWindow: UIWindow?
    static var originalAppDelegate: AppDelegate!

    var signposter: OSSignposter
    var signpostInterval: OSSignpostIntervalState?

    override init() {
        signposter = OSSignposter(subsystem: Bundle.main.bundleIdentifier ?? "unknown", category: "app")
        signposter.emitEvent(#function)
    }


  func applicationWillResignActive(_ application: UIApplication) {
        guard let interval =  signpostInterval else {
            assertionFailure("no interval")
            return
        }
        print("backgrounding, ending active state")
        signposter.endInterval("active", interval)
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        signpostInterval = signposter.beginInterval("active")
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
}

这就是我期望看到的,路标和间隔。

但是,这是在非工作项目中运行的示例代码。


更新

如果我以编程方式检查 OSSignposter 是否已启用,我会得到

false
。我不知道这是如何从外部禁用的,因为我没有明确禁用 OSSignposter。我也没有找到以编程方式启用它的方法。

signposter = OSSignposter(subsystem: Bundle.main.bundleIdentifier ?? "unknown", category: category)
assert(signposter.isEnabled)

这总是断言。

swift logging instruments signpost oslog
2个回答
1
投票

尝试进入您的方案并添加此环境变量。这应该可以解决断言问题,并希望在 Instruments 中创建一些跟踪。


0
投票

我遇到了同样的问题,我可以通过指定

category: .pointsOfInterest
使路标间隔出现在仪器中。

let signposter = OSSignposter(subsystem: Bundle.main.bundleIdentifier ?? "unknown", category: .pointsOfInterest)

这也使得

signposter.isEnabled
返回true。
category
参数的其他值似乎不起作用(无论是字符串还是其他
OSLog.Category
值)。

© www.soinside.com 2019 - 2024. All rights reserved.