【问题标题】:How to start and stop Firebase performance traces from a singleton dictionary with DispatchQueue如何使用 DispatchQueue 从单例字典启动和停止 Firebase 性能跟踪
【发布时间】:2021-04-26 09:11:06
【问题描述】:

我正在实施 Firebase 性能跟踪,因此我创建了一个共享实例并添加了一个字典来保存它们。 我理解的字典不是线程安全的,我需要添加一个调度队列来处理这个。

我应该如何使用 DispatchQueue 来获得最准确的跟踪? 还是我采取了错误的方法来测量痕迹?

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
            }
        }
    }

  }

【问题讨论】:

    标签: swift firebase thread-safety firebase-performance dispatch-queue


    【解决方案1】:

    您已尝试使用synchronus 方法,请尝试使用Asynchronus 并告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      相关资源
      最近更新 更多