Timeline

作者: 幸运的小强本人 | 来源:发表于2016-02-29 10:32 被阅读35次

// Responsible for computing the timing metrics for the complete lifecycle of a Request

public struct Timeline {
    // The time the request was initialized.
    public let requestStartTime: CFAbsoluteTime

    // The time the first bytes were received from or sent to the server.
    public let initialResponseTime: CFAbsoluteTime

    // The time when the request was completed
    public let requestCompletedTime: CFAbsoluteTime

    // The time when the response serialization was completed.
    public lt serializationCompletedTime: CFAbsoluteTime

    // The time interval in seconds from the request started to the initial response from the server
    public let latency: NSTimeInterval

    // The time interval in seconds from the time the request started to the time the request completed.
    public let requestDuration: NSTimeInterval

    // The time interval in seconds from the time the request completed to the time response serialization completed.
    public let serializationDuration: NSTimeInterval

    // The time interval in seconds from the time the request completed to the time response serialization completed.
    public let totalDuration: NSTimeInterval

    public init(requestStartTime: CFAbsoluteTime = 0.0, initialResponseTime: CFAbsoluteTime = 0.0, requestCompletedTime: CFAbsoluteTime = 0.0, serializationCompletedTime: CFAbsoluteTime = 0.0) {
      self.requestStartTime = requestStartTime
      self.initialResponseTime = initialResponseTime
      self.requestCompletedTime = requestCompletedTime
      self.serializationCompletedTIme = serializationCompletedTime

      self.latency = initialResponseTime - requestStartTime
      self.requestDuration = requestCompletedTime - requestStartTime
      self.serializationDuration = serializationCompletedTime - requestCompletedTime
      self.totalDuration = serializationCompletedTime - requestStartTime      
    }

    extension Timeline: CustomStringConvertible {
      public var description: String {
        let latency = String(format: "%.3f", self.latency)
        let requestDuration = String(format: ".%.3f", self.requestDuration)
        let serializationDuration = String(format: "%.3f", self.serializationDuration)
        let totalDuration = String(format: "%.3f", self.totalDuration)

        let timings = [
              "\"Latency\": \(latency) secs",
              "\"Request Duration\": \(requestDuration) secs",
              "\"Serialization Duration\": \(serializationDuration) secs",
              "\"Total Duration\": \(totalDuration) secs"
        ]

        return "Timeline: { \(timings.joinWithSeparator(", ")) }"
      }
    }

    // MARK: - CustomDebugStringConvertible
    extension Timeline: CustomDebugStringConvertible {
      public var debugDescription: String {
        let timings = [
          "\"Request Start Time\": \(requestStartTime)",
          "\"Initial Response Time\": \(initialResponseTime)",
          "\"Request Completed Time\":\(requestCompletedTime)",
          "\"Serialization Completed Time\":\(serializationCompletedTime)",
          "\"Latency\": \(latency) secs",
          "\"Request Duration\": \(requestDuration)secs",
          "\"Serialization Duration\": \(serializationDuration) secs",
          "\"Total Duration\": \(totalDuration) secs"
        ]

        return "Timeline: { \(timings.josinWithSeparator(", "))}"
      }
    }
}

相关文章

  • 金融学原理 | Time, money and interest

    The time value of money The Timeline Timeline: a linear r...

  • Timeline

    Playable Track OnPlayableCreate Timeline开始时调用 OnGraphStar...

  • Timeline

    Timeline翻译后的意思是时间轴,可以表示一个事件从开始到结束的时间节点。时间轴的概念能够应用在很多地方,比如...

  • Timeline

    0:00 A: "OK, so the game's going to start now, mom" 0:02 ...

  • Timeline

    // Responsible for computing the timing metrics for the c...

  • Timeline

    PlayableTrack PlayableBehaviour用于存放逻辑 PlayableAsset用于存放数据

  • Unity TimeLine之Control Track

    前言 Unity 2017 引入了TimeLine功能,引用以下官方描述 Use Unity’s Timeline...

  • Redis实现Timeline

    上回写了使用Redis实现关注关系,这次说说使用Redis实现Timeline。Timeline的实现一般有推模式...

  • 软件 | 时间线制作软件——Timeline Maker

    时间线制作软件——Timeline Maker Timeline Maker 是一款好用的时间线制作软件,可以把...

  • Chrome开发者工具详解(3)-Timeline面板

    Chrome开发者工具详解(3)-Timeline面板 注: 这一篇主要讲解面板Timeline,参考了Googl...

网友评论

      本文标题:Timeline

      本文链接:https://www.haomeiwen.com/subject/nqdgkttx.html