0001 // Timeline.swift 0002 // 0003 // Copyright (c) 2014–2016 Alamofire Software Foundation (http://alamofire.org/) 0004 // 0005 // Permission is hereby granted, free of charge, to any person obtaining a copy 0006 // of this software and associated documentation files (the "Software"), to deal 0007 // in the Software without restriction, including without limitation the rights 0008 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0009 // copies of the Software, and to permit persons to whom the Software is 0010 // furnished to do so, subject to the following conditions: 0011 // 0012 // The above copyright notice and this permission notice shall be included in 0013 // all copies or substantial portions of the Software. 0014 // 0015 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0016 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0017 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0018 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0019 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0020 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0021 // THE SOFTWARE. 0022 0023 import Foundation 0024 0025 /// Responsible for computing the timing metrics for the complete lifecycle of a `Request`. 0026 public struct Timeline{ 0027 /// The time the request was initialized. 0028 public let requestStartTime
Response.swift:40 public let timeline: TimelineResponse.swift:59 timeline: Timeline = Timeline())Response.swift:59 timeline: Timeline = Timeline())ResponseSerialization.swift:125 let timeline = Timeline(Timeline.swift:83 extension Timeline: CustomStringConvertible {Timeline.swift:105 extension Timeline: CustomDebugStringConvertible {: CFAbsoluteTime 0029 0030 /// The time the first bytes were received from or sent to the server. 0031 public let initialResponseTime
Timeline.swift:69 self.requestStartTime = requestStartTimeTimeline.swift:111 "\"Request Start Time\": \(requestStartTime)",: CFAbsoluteTime 0032 0033 /// The time when the request was completed. 0034 public let requestCompletedTime
Timeline.swift:70 self.initialResponseTime = initialResponseTimeTimeline.swift:112 "\"Initial Response Time\": \(initialResponseTime)",: CFAbsoluteTime 0035 0036 /// The time when the response serialization was completed. 0037 public let serializationCompletedTime
Timeline.swift:71 self.requestCompletedTime = requestCompletedTimeTimeline.swift:113 "\"Request Completed Time\": \(requestCompletedTime)",: CFAbsoluteTime 0038 0039 /// The time interval in seconds from the time the request started to the initial response from the server. 0040 public let latency
Timeline.swift:72 self.serializationCompletedTime = serializationCompletedTimeTimeline.swift:114 "\"Serialization Completed Time\": \(serializationCompletedTime)",: NSTimeInterval 0041 0042 /// The time interval in seconds from the time the request started to the time the request completed. 0043 public let requestDuration
Timeline.swift:74 self.latency = initialResponseTime - requestStartTimeTimeline.swift:87 let latency = String(format: "%.3f", self.latency)Timeline.swift:115 "\"Latency\": \(latency) secs",: NSTimeInterval 0044 0045 /// The time interval in seconds from the time the request completed to the time response serialization completed. 0046 public let serializationDuration
Timeline.swift:75 self.requestDuration = requestCompletedTime - requestStartTimeTimeline.swift:88 let requestDuration = String(format: "%.3f", self.requestDuration)Timeline.swift:116 "\"Request Duration\": \(requestDuration) secs",: NSTimeInterval 0047 0048 /// The time interval in seconds from the time the request started to the time response serialization completed. 0049 public let totalDuration
Timeline.swift:76 self.serializationDuration = serializationCompletedTime - requestCompletedTimeTimeline.swift:89 let serializationDuration = String(format: "%.3f", self.serializationDuration)Timeline.swift:117 "\"Serialization Duration\": \(serializationDuration) secs",: NSTimeInterval 0050 0051 /** 0052 Creates a new `Timeline` instance with the specified request times. 0053 0054 - parameter requestStartTime: The time the request was initialized. Defaults to `0.0`. 0055 - parameter initialResponseTime: The time the first bytes were received from or sent to the server. 0056 Defaults to `0.0`. 0057 - parameter requestCompletedTime: The time when the request was completed. Defaults to `0.0`. 0058 - parameter serializationCompletedTime: The time when the response serialization was completed. Defaults 0059 to `0.0`. 0060 0061 - returns: The new `Timeline` instance. 0062 */ 0063 public init
Timeline.swift:77 self.totalDuration = serializationCompletedTime - requestStartTimeTimeline.swift:90 let totalDuration = String(format: "%.3f", self.totalDuration)Timeline.swift:118 "\"Total Duration\": \(totalDuration) secs"( 0064 requestStartTime: CFAbsoluteTime = 0.0, 0065 initialResponseTime: CFAbsoluteTime = 0.0, 0066 requestCompletedTime: CFAbsoluteTime = 0.0, 0067 serializationCompletedTime: CFAbsoluteTime = 0.0) 0068 { 0069 self.requestStartTime = requestStartTime 0070 self.initialResponseTime = initialResponseTime 0071 self.requestCompletedTime = requestCompletedTime 0072 self.serializationCompletedTime = serializationCompletedTime 0073 0074 self.latency = initialResponseTime - requestStartTime 0075 self.requestDuration = requestCompletedTime - requestStartTime 0076 self.serializationDuration = serializationCompletedTime - requestCompletedTime 0077 self.totalDuration = serializationCompletedTime - requestStartTime 0078 } 0079 } 0080 0081 // MARK: - CustomStringConvertible 0082 0083 extension Timeline: CustomStringConvertible { 0084 /// The textual representation used when written to an output stream, which includes the latency, the request 0085 /// duration and the total duration. 0086 public var description: String { 0087 let latency = String(format: "%.3f", self.latency) 0088 let requestDuration = String(format: "%.3f", self.requestDuration) 0089 let serializationDuration = String(format: "%.3f", self.serializationDuration) 0090 let totalDuration = String(format: "%.3f", self.totalDuration) 0091 0092 let timings = [ 0093 "\"Latency\": \(latency) secs", 0094 "\"Request Duration\": \(requestDuration) secs", 0095 "\"Serialization Duration\": \(serializationDuration) secs", 0096 "\"Total Duration\": \(totalDuration) secs" 0097 ] 0098 0099 return "Timeline: { \(timings.joinWithSeparator(", ")) }" 0100 } 0101 } 0102 0103 // MARK: - CustomDebugStringConvertible 0104 0105 extension Timeline: CustomDebugStringConvertible { 0106 /// The textual representation used when written to an output stream, which includes the request start time, the 0107 /// initial response time, the request completed time, the serialization completed time, the latency, the request 0108 /// duration and the total duration. 0109 public var debugDescription
Response.swift:59 timeline: Timeline = Timeline())ResponseSerialization.swift:125 let timeline = Timeline(: String { 0110 let timings = [ 0111 "\"Request Start Time\": \(requestStartTime)", 0112 "\"Initial Response Time\": \(initialResponseTime)", 0113 "\"Request Completed Time\": \(requestCompletedTime)", 0114 "\"Serialization Completed Time\": \(serializationCompletedTime)", 0115 "\"Latency\": \(latency) secs", 0116 "\"Request Duration\": \(requestDuration) secs", 0117 "\"Serialization Duration\": \(serializationDuration) secs", 0118 "\"Total Duration\": \(totalDuration) secs" 0119 ] 0120 0121 return "Timeline: { \(timings.joinWithSeparator(", ")) }" 0122 } 0123 } 0124
Response.swift:91 output.append("[Timeline]: \(timeline.debugDescription)")