Skip to content

Commit c189644

Browse files
committed
Add more signposter intervals
1 parent 5bfd1a6 commit c189644

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

Sources/AppBundle/layout/refresh.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ func runRefreshSession(
1616

1717
@MainActor
1818
func runRefreshSessionBlocking(_ event: RefreshSessionEvent) async throws {
19+
let state = signposter.beginInterval(#function, "event: \(event) axTaskLocalAppThreadToken: \(axTaskLocalAppThreadToken?.idForDebug)")
20+
defer {
21+
signposter.endInterval(#function, state)
22+
}
1923
if !TrayMenuModel.shared.isEnabled { return }
2024
try await $refreshSessionEventForDebug.withValue(event) {
2125
try await refresh()
@@ -37,6 +41,10 @@ func runSession<T>(
3741
_ token: RunSessionGuard,
3842
body: @MainActor () async throws -> T
3943
) async throws -> T {
44+
let state = signposter.beginInterval(#function, "event: \(event) axTaskLocalAppThreadToken: \(axTaskLocalAppThreadToken?.idForDebug)")
45+
defer {
46+
signposter.endInterval(#function, state)
47+
}
4048
activeRefreshTask?.cancel() // Give priority to runSession
4149
activeRefreshTask = nil
4250
return try await $refreshSessionEventForDebug.withValue(event) {

Sources/AppBundle/tree/MacApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ final class MacApp: AbstractApp {
290290
}
291291
}
292292

293-
for window in axApp.threadGuarded.get(Ax.windowsAttr, signpostEvent: nsApp.idForDebug) ?? [] {
293+
for window in axApp.threadGuarded.get(Ax.windowsAttr) ?? [] {
294294
try job.checkCancellation()
295295
result.getOrRegisterAxWindow(window, nsApp)
296296
}

Sources/AppBundle/util/accessibility.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,20 @@ private func tryGetWindow(_ any: Any?) -> AXUIElement? {
300300
}
301301

302302
extension AXUIElement {
303-
func get<Attr: ReadableAttr>(_ attr: Attr, signpostEvent: String? = nil, function: String = #function) -> Attr.T? {
304-
let state = signposter.beginInterval("AXUIElement.get", "\(function): \(signpostEvent)")
303+
func get<Attr: ReadableAttr>(_ attr: Attr) -> Attr.T? {
304+
let state = signposter.beginInterval(#function, "axTaskLocalAppThreadToken: \(axTaskLocalAppThreadToken?.idForDebug)")
305305
defer {
306-
signposter.endInterval("AXUIElement.get", state)
306+
signposter.endInterval(#function, state)
307307
}
308308
var raw: AnyObject?
309309
return AXUIElementCopyAttributeValue(self, attr.key as CFString, &raw) == .success ? attr.getter(raw!) : nil
310310
}
311311

312312
@discardableResult func set<Attr: WritableAttr>(_ attr: Attr, _ value: Attr.T) -> Bool {
313+
let state = signposter.beginInterval(#function, "axTaskLocalAppThreadToken: \(axTaskLocalAppThreadToken?.idForDebug)")
314+
defer {
315+
signposter.endInterval(#function, state)
316+
}
313317
guard let value = attr.setter(value) else { return false }
314318
return AXUIElementSetAttributeValue(self, attr.key as CFString, value) == .success
315319
}

Sources/Common/model/AxAppThreadToken.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
@TaskLocal
44
public var axTaskLocalAppThreadToken: AxAppThreadToken? = nil
55

6-
public struct AxAppThreadToken: Sendable, Equatable {
6+
public struct AxAppThreadToken: Sendable, Equatable, CustomStringConvertible {
77
public let pid: pid_t
88
public let idForDebug: String
99

@@ -17,4 +17,6 @@ public struct AxAppThreadToken: Sendable, Equatable {
1717
public func checkEquals(_ other: AxAppThreadToken?) {
1818
check(self == other, "\(self) != \(other.optionalToPrettyString())")
1919
}
20+
21+
public var description: String { idForDebug }
2022
}

Sources/Common/util/commonUtil.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public func dieT<T>(
6666
fatalError("\n" + message)
6767
}
6868

69-
public enum RefreshSessionEvent: Sendable {
69+
public enum RefreshSessionEvent: Sendable, CustomStringConvertible {
7070
case globalObserver(String)
7171
case globalObserverLeftMouseUp
7272
case menuBarButton
@@ -76,6 +76,20 @@ public enum RefreshSessionEvent: Sendable {
7676
case socketServer
7777
case resetManipulatedWithMouse
7878
case ax(String)
79+
80+
public var description: String {
81+
switch self {
82+
case .ax(let str): "ax(\(str))"
83+
case .globalObserver(let str): "globalObserver(\(str))"
84+
case .globalObserverLeftMouseUp: "globalObserverLeftMouseUp"
85+
case .hotkeyBinding: "hotkeyBinding"
86+
case .menuBarButton: "menuBarButton"
87+
case .resetManipulatedWithMouse: "resetManipulatedWithMouse"
88+
case .socketServer: " socketServer"
89+
case .startup1: "startup1"
90+
case .startup2: "startup2"
91+
}
92+
}
7993
}
8094

8195
public func throwT<T>(_ error: Error) throws -> T {

0 commit comments

Comments
 (0)