Class for logging excessive blocking on the main thread

Overview

Watchdog

Language Build Status Platform support CocoaPods Compatible Carthage compatible License MIT

Class for logging excessive blocking on the main thread. It watches the main thread and checks if it doesn’t get blocked for more than defined threshold.

👮 Main thread was blocked for 1.25s 👮

You can also inspect which part of your code is blocking the main thread.

Usage

Simply, just instantiate Watchdog with number of seconds that must pass to consider the main thread blocked. Additionally you can enable strictMode that stops the execution whenever the threshold is reached. This way, you can inspect which part of your code is blocking the main thread.

let watchdog = Watchdog(threshold: 0.4, strictMode: true)

Don't forget to retain Watchdog somewhere or it will get released when it goes out of scope.

Requirements

  • iOS 8.0+, tvOS 9.0+ or macOS 10.9+
  • Swift 5.0

Installation

Carthage

Add the following to your Cartfile:

github "wojteklu/Watchdog"

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

CocoaPods

Add the following to your Podfile:

pod 'Watchdog'

You will also need to make sure you're opting into using frameworks:

use_frameworks!

Manually

Manually add the file into your Xcode project. Slightly simpler, but updates are also manual.

Author

Wojtek Lukaszuk @wojteklu

License

Watchdog is available under the MIT license. See the LICENSE file for more info.

Comments
  • strip unnecessary the exclamation marks

    strip unnecessary the exclamation marks

    through the swift programming guide, when you know that the variable will never be nil when it has been initiated, maybe treat it as a normal variable is a better way, after all, you can see its type in the quick help window

    opened by inatu 6
  • Can't get it to work

    Can't get it to work

    Am I missing something?

    I wrote some code in viewDidLoad() of a VC to block the main thread for seconds (just a long loop), and the watchdog won't fire (not printing anything). Am I missing something?

    opened by JaviSoto 5
  • The duration display the thresold duration instead of how long the app has been blocked

    The duration display the thresold duration instead of how long the app has been blocked

    In the v1.x, the duration logs in the console was the duration of how long the main thread has been blocked. Starting with the 2.0, the duration is always displaying the threshold duration.

    That's a sad regression, it was a really interesting feature. Do you think to bring it back?

    opened by tbaranes 3
  • No functional change: expose an initializer that allows the client to have custom behavior when the watch dog fires.

    No functional change: expose an initializer that allows the client to have custom behavior when the watch dog fires.

    This is useful if an app wants to do something other than log with NSLog or call assertionFailure()

    Other than that I made some nit-picky changes for correctness, like changing some vars for lets and using final.

    opened by JaviSoto 3
  • Watchdog is so cool,and I want a new feature

    Watchdog is so cool,and I want a new feature

    Watchdog is so cool, it works well, when watchdog find on the main thread is blocking, and I want to know who block the main thread. but I do not know how to print the callstack?

    opened by zixun 2
  • Credit the original?

    Credit the original?

    This looks like a port of existing Objective-C code that's floated around for a while. You should probably give credit to the original

    https://gist.github.com/jspahrsummers/419266f5231832602bec

    There may be other implementations out there to but that's what I found with a quick search.

    opened by neilpa 2
  • Is it possible to disable the Watchdog when a breakpoint is reached?

    Is it possible to disable the Watchdog when a breakpoint is reached?

    I realised that the watchdog (of course) times out when the execution stops at a breakpoint. Does this really mean that I have to disable the initialisation of the watchdog normally during development, and enable it only when the app is running "freely"?

    opened by zeh4soft 1
  • Is it possible to change the timeout time during execution?

    Is it possible to change the timeout time during execution?

    Watchdog is very useful, thanks a lot, but I have a problem: During normal execution of my app, I can set a rather small timeout time, say 0.5 sec. This works fine. However, I have a number of unit stress tests that use unrealistic large data, just to identify potential bottlenecks. To setup these tests, the main thread is busy more than the timeout time of 0.5 sec. I could of course increase it, but then I would not catch certain problems. So, what I would like to do is either to disable Watchdog only during the execution of my test setup, or change its timeout time. Is this possible?

    opened by zeh4soft 1
  • It's a beauty class, but I just have a question

    It's a beauty class, but I just have a question

    When It's switched to main thread, and execute

    self.pingTaskIsRunning = false
    self.semaphore.signal()
    

    Is it will consume main thread resources too much, if I set threshold a little number(just like 50 ms)?

    opened by DeepMissea 1
  • Fully downloaded file from Chrome is not observed. Only the .crdownload is observed.

    Fully downloaded file from Chrome is not observed. Only the .crdownload is observed.

    ('Was Created/Downloaded: ', '/Users/username/Downloads/LoadConf (1).pdf.crdownload')

    ` import sys import os import time from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler

    class Event(FileSystemEventHandler): def on_created(self, event): print('Was Created/Downloaded: ', event.src_path)

    if name == 'main': path = sys.argv[1] if len(sys.argv) > 1 else '.' event_handler = Event() observer = Observer() observer.schedule(event_handler, path, recursive=True) observer.start() try: while True: time.sleep(5) print('Waiting for a change...') except KeyboardInterrupt: observer.stop() observer.join() `

    opened by rlgn 1
  • Xcode/Swift Migration & the fixing of @objc inference

    Xcode/Swift Migration & the fixing of @objc inference

    This pull request contains the following update:

    • Fixing @objc inference that changed in Swift 4
    • Migrating to Xcode 9.3
    • Updating project to use Swift 4.1

    I originally created my branch to fix the @objc issues. With Swift 4 and above, rather than put @objc at the top of the class, they now must be put before (or above) each method to expose the method in Objective-C. Without this update, a user who consumes Watchdog will not be able to use it with Objective-C.

    I've updated the project and migrated to Swift 4.1 while I was at it at well.

    opened by rbaumbach 1
Owner
Wojtek Lukaszuk
I can't stand workarounds and spaghetti code.
Wojtek Lukaszuk
Twitter Logging Service is a robust and performant logging framework for iOS clients

Twitter Logging Service Background Twitter created a framework for logging in order to fulfill the following requirements: fast (no blocking the main

Twitter 290 Nov 15, 2022
A logging backend for swift-log that sends logging messages to Logstash (eg. the ELK stack)

LoggingELK LoggingELK is a logging backend library for Apple's swift-log The LoggingELK library provides a logging backend for Apple's apple/swift-log

null 17 Nov 15, 2022
Simple logging for simples needs.

Simple logging for simples needs.

native.dev.br 0 May 30, 2022
Convenient & secure logging during development & release in Swift 3, 4 & 5

Colorful, flexible, lightweight logging for Swift 3, Swift 4 & Swift 5. Great for development & release with support for Console, File & cloud platfor

SwiftyBeaver 5.6k Jan 4, 2023
CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant

CleanroomLogger CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant. The API provided by Cleanro

null 1.3k Dec 8, 2022
Willow is a powerful, yet lightweight logging library written in Swift.

Willow Willow is a powerful, yet lightweight logging library written in Swift. Features Requirements Migration Guides Communication Installation Cocoa

Nike Inc. 1.3k Nov 16, 2022
Swift Logging Utility for Xcode & Google Docs

QorumLogs Swift Logging Utility in Xcode & Google Docs

Goktug Yilmaz 777 Jul 15, 2022
A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

Kitura 174 Nov 30, 2022
A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

Kitura 174 Nov 30, 2022
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.

Please star this github repository to stay up to date. TraceLog Introduction TraceLog is a highly configurable, flexible, portable, and simple to use

Tony Stone 52 Oct 28, 2022
A flexible logging library written in Swift

Puppy Puppy is a flexible logging library written in Swift ?? It supports multiple transports(console, file, syslog, and oslog) as loggers. It not onl

Koichi Yokota 92 Dec 29, 2022
In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.

The debugger tool for iOS developer. Display logs, network request, device informations, crash logs while using the app. Easy accessible with its bubble head button ?? . Easy to integrate in any apps, to handle development or testing apps easier. First version, there is plenty of room for improvement.

Remi ROBERT 1.8k Dec 29, 2022
An extensible logging framework for Swift

Log is a powerful logging framework that provides built-in themes and formatters, and a nice API to define your owns. Get the most out of Log by insta

Damien 825 Nov 6, 2022
Logging utility for Swift and Objective C

Swell - Swift Logging A logging utility for Swift and Objective C. ##Features Turn on logging during development, turn them off when building for the

Hubert Rabago 361 Jun 29, 2022
A powerful input-agnostic swift logging framework made to speed up development with maximum readability.

The Swift logging framework. Atlantis is an extremely powerful logging framework that I've created for everyday use, including enterprise development

Andrew Aquino 199 Jan 2, 2023
Most natural Swift logging

Evergreen Most natural Swift logging Evergreen is a logging framework written in Swift. It is designed to work just as you would expect, yet so versat

Nils Leif Fischer 72 Aug 12, 2022
Simple, lightweight and flexible debug logging framework written in Swift

AELog Simple, lightweight and flexible debug logging minion written in Swift If you find yourself in upcoming statements, then you probably want to us

Marko Tadić 28 Jul 6, 2022
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

null 12.9k Jan 9, 2023
A modern, flexible logging tool

NSLogger NSLogger is a high performance logging utility which displays traces emitted by client applications running on macOS, iOS and Android. It rep

Florent Pillet 5k Dec 22, 2022