Git Product home page Git Product logo

watchdoginspector's Introduction

WatchdogInspector

Shows your current framerate (fps) in the status bar of your iOS app

Be a good citizen! Don't block your main thread!

Build Status Cocoapods Version CocoaPods Platform Carthage Compatible Twitter

WatchdogInspector counts your app's framerate and displays the fps in the status bar. The coloured status bar lets you know when your framerate drops below 60 fps. If everything is fine your status bar gets happy and will stay green. To detect unwanted main thread stalls you can set a custom watchdog timeout.

Features

  • Status bar displays the current framerate in fps (measured every 2 seconds)
  • Colours the status bar from green (good fps) to red (bad fps)
  • Custom watchdog timeout: Exception when main thread stalls for a defined time

screencast

Install

CocoaPods

pod "WatchdogInspector"

and run pod install You can see the example project how to setup and run WatchdogInspector Make sure that you don't use WatchdogInspector in production.

Carthage

You can use Carthage. Specify in Cartfile:

github "tapwork/WatchdogInspector"

Usage

Objective-C | Swift

Start

After launch or whenever you want.

import WatchdogInspector
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        TWWatchdogInspector.start()
        return true
}

Stop

To stop it just call

TWWatchdogInspector.stop()

Main Thread Stalling Exceptions

You can set a custom watchdog timeout for stalling exceptions (Default: 3 seconds)

TWWatchdogInspector.setStallingThreshhold(10.0)

You could also disable the Main Thread exceptions

TWWatchdogInspector.setEnableMainthreadStallingException(false)

Logging

To log all measured framerates you can log them in the console by calling (Default: on)

TWWatchdogInspector.setUseLogs(true)

How it works

There are basically two timers running to measure the framerate.

  1. The background thread timer fires every 2 seconds to count how many frames were set by the main thread. Ideally the result would be 120 frames in 2 seconds to get 60 fps. The background timer resets the frames counter every event. He also sends the measured fps to the status bar on the main thread.

  2. The main thread timer should fire every 1/60 second (60 fps is optimum for a smooth animation) to increment the frames counter. If the main thread is blocked and can't run every 1/60 second the framerate will drop the 60 fps.

There is also a run loop observer running to detect main thread stalls for a defined timeout. If the timeout has been reached an exception will be thrown.

Related projects

Author

License

MIT

watchdoginspector's People

Contributors

andresbrun avatar clementpadovani avatar eraydiler avatar tapwork avatar zeveisenberg avatar

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  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  avatar  avatar  avatar  avatar

watchdoginspector's Issues

Port to tvOS

I don't know if you're interested, but I made it working on tvOS. At least I get a "status bar" (just a CGRect) showing on top of the screen. This is the code modified, file "TWWatchdogInspector.m"

#pragma mark - UI Updates

+ (void)setupStatusView
{
#if TARGET_OS_IOS
    CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
#elif TARGET_OS_TV
    CGRect statusBarFrame = CGRectMake(0, 0, 1920, 20);
#endif
    CGSize size =  statusBarFrame.size;
    CGRect frame = CGRectMake(0, 0, size.width, size.height);
    UIWindow *window = [[UIWindow alloc] initWithFrame:frame];
    window.rootViewController = [[TWWatchdogInspectorViewController alloc] init];
    [window setHidden:NO];
#if TARGET_OS_IOS
    window.windowLevel = UIWindowLevelStatusBar + 50;
#elif TARGET_OS_TV
    window.windowLevel = UIWindowLevelNormal + 50;
#endif
    kInspectorWindow = window;
}

I tested it in (yet another) port to tvOS of this git on my Apple TV 4K. It compiles just fine (well.. after messing up with the project configuration to manage to actually make it compiling and importing as a tvOS framework - not an Objective C guy, here) and runs beautifully:

screen shot 2018-08-06 at 11 16 43

Although I am not sure if the fps text is supposed to overlap the chart.

Allow to customize kUpdateWatchdogInterval

2 seconds is a bit high to my liking โ€” I would've preferred the status bar to update more frequently. (I'm more concerned about FPS drops rather than general FPS trends...)

Private API usage - confirmation needed.

HI!

In readme you wrote:

Make sure that you don't use WatchdogInspector in production.

I would like to keep Watchdoginspector for sometime for my development and staging build. Hence,

#if ENV_DEVELOPMENT || ENV_STAGING
    TWWatchdogInspector.setEnableMainthreadStallingException(false)
    TWWatchdogInspector.start()
#endif

and so my question is: is it enough to protect myself from app rejection? Does Watchdoginspector use any private API? I'm asking because in release mode Watchdoginspector framework is bundled inside *.ipa.

Best,
Pikor

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.