Giter VIP home page Giter VIP logo

tumbleweed's Introduction

Tumbleweed

Logs detailed metrics about URLSession tasks to the console, such as DNS lookup durations, request and response times and more. Tumbleweed works by parsing the metrics collected by the URLSessionTaskMetrics introduced in iOS 10.0.

Example output

Task ID: 1 lifetime: 594.9ms redirects: 0
GET https://github.com/ -> 200 text/html, through network-load
protocol: http/1.1 proxy: false reusedconn: false
domain lookup     |#                                                                               |   3.0ms
connect           |###############################################                                 | 330.0ms
secure connection |               ################################                                 | 223.0ms
request           |                                               #                                |   0.2ms
server            |                                               ###################              | 130.9ms
response          |                                                                 ###############| 105.8ms
                                                                                             total   575.0ms

A few notes on the data:

  • Task lifetime is the time of the URLSessionTask creation to the response is delivered.
  • The "through" key on the second line will tell you whether the response was fetched from cache, delivered by server push or by network load.
  • "server" is how long the server spent processing the request

Note that not all responses will deliver complete metrics, such as local cache fetches and other non-network loaded responses.

Usage

In your URLSessionDelegate:

func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
    let stats = SessionMetrics(source: metrics, task: task)
    let renderer = ConsoleRenderer()
    renderer.render(with: stats)
}

As a convenience Tumbleweed provides the SessionMetricsLogger which can be set as the URLSessionDelegate on URLSession, if you're not using any of the other delegates.

let sessionDelegate: URLSessionDelegate?
if #available(iOS 10.0, *) {
sessionDelegate = SessionMetricsLogger()
} else {
    sessionDelegate = nil
}
let session = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)

Installation

Tumbleweed is available as a CocoaPod (pod 'Tumbleweed') and the Swift Package Manager. Framework installation is also available by dragging the Tumbleweed.xcodeproj into your project or via Carthage.

Tumbleweed has no dependencies outside of Foundation.

License

See the LICENSE file

tumbleweed's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.