Skip to content

Commit

Permalink
noisy callstack frame debugging (#166)
Browse files Browse the repository at this point in the history
* noisy callstack frame debugging
* check length of callstack frames before slicing
  • Loading branch information
heckj authored May 7, 2024
1 parent 6ffcf5b commit c19ba09
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/Automerge/BoundTypes/AutomergeText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ extension AutomergeText: CustomStringConvertible {
extension AutomergeText: CustomDebugStringConvertible {
public var debugDescription: String {
guard let doc, let objId else {
return "AutomergeText(unbound): \(self._unboundStorage)"
return "AutomergeText(unbound): \(_unboundStorage)"
}
do {
let path = try doc.path(obj: objId).stringPath()
Expand All @@ -399,6 +399,16 @@ extension AutomergeText: ObservableObject {
if #available(macOS 11, iOS 14, *) {
let logger = Logger(subsystem: "Automerge", category: "AutomergeText")
logger.trace("\(self.debugDescription) sending ObjectWillChange")
let callStacks = Thread.callStackSymbols
if callStacks.count > 5 {
for callStackFrame in callStacks[0 ... 5] {
logger.trace(" - \(callStackFrame)")
}
} else {
for callStackFrame in callStacks {
logger.trace(" - \(callStackFrame)")
}
}
}
#endif
objectWillChange.send()
Expand Down
23 changes: 23 additions & 0 deletions Sources/Automerge/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,32 @@ struct WrappedDoc {

#if canImport(Combine)
import Combine
import OSLog

extension Document: ObservableObject {
fileprivate func sendObjectWillChange() {
#if canImport(os)
if #available(macOS 11, iOS 14, *) {
let logger = Logger(subsystem: "Automerge", category: "AutomergeText")

logger.trace("Document \(String(describing: self)) sending ObjectWillChange")
// concurrency violation
// let headsString = self.heads().map { ch in
// ch.debugDescription
// }.joined(separator: ".")
// logger.trace("heads: \(headsString)")
let callStacks = Thread.callStackSymbols
if callStacks.count > 5 {
for callStackFrame in callStacks[0 ... 5] {
logger.trace(" - \(callStackFrame)")
}
} else {
for callStackFrame in callStacks {
logger.trace(" - \(callStackFrame)")
}
}
}
#endif
objectWillChange.send()
}
}
Expand Down

0 comments on commit c19ba09

Please sign in to comment.