I am in the process of implementing Firebase performance traces, so i made a shared instance and added a dictionary to hold them. What i understand dictionaries are not thread safe and i need to add a dispatch queue to handle this.
How should i be using DispatchQueue to get the most accurate trace? Or am I taking the wrong approach to measure traces?
import FirebasePerformance
class Tracing {
static let shared = Tracing()
let queue = DispatchQueue(label: "thread-safe-tracing")
var traces = [String: Trace]()
static func startTracing(name: String) {
shared.queue.sync {
if let trace = Performance.startTrace(name: name) {
shared.traces[name] = trace
}
}
}
static func stop(name: String) {
shared.queue.sync {
if let trace = shared.traces[name] {
trace.stop()
shared.traces[name] = nil
}
}
}
}
you are tried with
synchronus
method please try withAsynchronus
and let me know.