【发布时间】:2022-11-17 14:43:38
【问题描述】:
我正在尝试使用 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