Class

URLSessionTaskTransactionMetrics

An object encapsulating the performance metrics collected during the execution of a session task.

Declaration

class URLSessionTaskTransactionMetrics : NSObject

Overview

Each URLSessionTaskTransactionMetrics object consists of a request and response property, corresponding to the request and response of the corresponding task. It also contains temporal metrics, starting with fetchStartDate and ending with responseEndDate, as well as other characteristics like networkProtocolName and resourceFetchType.

Understanding Temporal Metrics

Figure 1 shows the sequence of events for a URL session task, which correspond to the temporal metrics captured by URLSessionTaskTransactionMetrics.

Figure 1

Timeline of temporal metrics for a URL session task

Diagram showing the temporal metrics for a URL session task. When a task starts, it performs a DNS lookup and then starts a connection. If the connection is encrypted, the user agent starts a TLS security handshake to secure the connection. After the connection to the server is established, the user agent requests the specified resource, and receives a response.

For all metrics with a start and end date, if an aspect of the task was not completed, then its corresponding end date metric is nil. This can happen if name lookup begins, but the operation either times out, fails, or the client cancels the task before the name can be resolved. In this case, the domainLookupEndDate property is nil, along with all metrics for aspects that occurred afterwards.

Topics

Creating Transaction Metrics

init()

Creates a transaction metrics instance.

Deprecated

Accessing Request and Response

var request: URLRequest

The transaction request.

var response: URLResponse?

The transaction response.

Accessing Temporal Metrics

var fetchStartDate: Date?

The time when the task started fetching the resource, from the server or locally.

var domainLookupStartDate: Date?

The time immediately before the task started the name lookup for the resource.

var domainLookupEndDate: Date?

The time after the name lookup was completed.

var connectStartDate: Date?

The time immediately before the task started establishing a TCP connection to the server.

var secureConnectionStartDate: Date?

The time immediately before the task started the TLS security handshake to secure the current connection.

var secureConnectionEndDate: Date?

The time immediately after the security handshake completed.

var connectEndDate: Date?

The time immediately after the task finished establishing the connection to the server.

var requestStartDate: Date?

The time immediately before the task started requesting the resource, regardless of whether it is retrieved from the server or local resources.

var requestEndDate: Date?

The time immediately after the task finished requesting the resource, regardless of whether it was retrieved from the server or local resources.

var responseStartDate: Date?

The time immediately after the task received the first byte of the response from the server or from local resources.

var responseEndDate: Date?

The time immediately after the task received the last byte of the resource.

Accessing Transaction Characteristics

var networkProtocolName: String?

The network protocol used to fetch the resource.

var isProxyConnection: Bool

A Boolean value indicating whether a proxy connection was used to fetch the resource.

var isReusedConnection: Bool

A Boolean value indicating whether a persistent connection was used to fetch the resource.

var resourceFetchType: URLSessionTaskMetrics.ResourceFetchType

A value indicating whether the resource was loaded, pushed, or retrieved from the local cache.

enum URLSessionTaskMetrics.ResourceFetchType

The manner in which a resource is fetched.

Type Methods

Relationships

Inherits From

Conforms To

See Also

Accessing Task Metrics

var transactionMetrics: [URLSessionTaskTransactionMetrics]

An array of metrics for each individual request-response transaction made during the execution of the task.

var taskInterval: DateInterval

The time interval between when a task is instantiated and when the task is completed.

var redirectCount: Int

The number of redirects that occurred during the execution of the task.