GithubHelp home page GithubHelp logo

kconner / kmcgeigercounter Goto Github PK

View Code? Open in Web Editor NEW
2.3K 58.0 274.0 875 KB

A framerate meter that clicks like a Geiger counter when your animation drops a frame

License: MIT License

Objective-C 67.03% Ruby 4.78% Swift 28.19%

kmcgeigercounter's Introduction

KMCGeigerCounter

This tool is a framerate meter that clicks like a Geiger counter when your animation drops a frame.

A Geiger counter detects invisible particles and alerts you to what you can't see. Dropped frames aren't invisible, but it can be hard to tell the difference between 55 and 60 fps. KMCGeigerCounter makes each dropped frame obvious.

  • If you're not consistently animating smoothly, you'll hear a rough, staticky noise.
  • If your app runs at a smooth 60 fps, you'll hear the occasional drops to 59 and 58.
  • You will hear dropped frames from occasional CPU spikes, like when custom table view cells enter the screen and require layout.

The meter shows two numbers:

  • The number of frames dropped in the past second
  • The number of frames drawn in the past second

The meter will be orange when you've dropped at least three frames in the past second.

Installation

pod 'KMCGeigerCounter'

Or copy these files into your project:

  • KMCGeigerCounter.h
  • KMCGeigerCounter.m
  • KMCGeigerCounter.aiff

If you're not using CocoaPods, you may need to add this framework to your Link Binary With Libraries build phase:

  • AudioToolbox.framework

Usage

In your UIApplicationDelegate, enable the tool:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //
    [self.window makeKeyAndVisible];

    [KMCGeigerCounter sharedGeigerCounter].enabled = YES;
}

Build and run your app. Navigate through your app and listen for clicks.

Known issue

Dropped frames on iOS can be divided into two types, which I'll call CPU and GPU drops. CPU drops happen when main thread activity delays the preparation of your layer tree, like when Auto Layout evaluates a complex set of constraints. CPU drops are easy to measure by observing the delivery timing of regularly scheduled events on the main thread. GPU drops happen when the layer tree is expensive to draw, such as when there are too many blended layers. Due to the nature of iOS, GPU drops happen in a system process responsible for drawing. I haven't found a way to measure them without adversely affecting the app's framerate. The upshot is that only CPU drops can be detected by this library today. Fortunately, more powerful iOS devices have made GPU drops much less common than they used to be, and you can always use the Core Animation instrument to measure them faithfully.

Notes

Remember to turn off Silent mode, or you won't hear anything.

You should remove KMCGeigerCounter before shipping to the App Store. It can't be good for battery life.

The iOS Simulator doesn't simulate device performance, so consider enabling the tool only for device builds:

#if !TARGET_IPHONE_SIMULATOR
[KMCGeigerCounter sharedGeigerCounter].enabled = YES;
#endif

kmcgeigercounter's People

Contributors

dependabot[bot] avatar kconner avatar spenrose 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  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

kmcgeigercounter's Issues

Needs SpriteKit if not using Pods

Installation instructions need to be say that you have to add SpriteKit to "Build Phases - Link Binary With Libraries" for users not using Cocoapods.

Floating point conversion errors

When you have Warnings set to be treated as Errors in Xcode the following prevent the app from building:

KMCGeigerCounter.m:198:74: Implicit conversion loses floating-point precision: 'double' to 'CGFloat' (aka 'float')

KMCGeigerCounter.m:237:47: Implicit conversion loses floating-point precision: 'double' to 'UIWindowLevel' (aka 'float')

inXcode7 and ios9 appCrash

this is how i use:

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[[UIApplication sharedApplication] delegate] setWindow:_window];

// main view controller
homeViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateInitialViewController];
[homeViewController setDelegate:self];

UINavigationController* navView = [[DirectionUINavigationController alloc] initWithRootViewController:homeViewController];

[_window setRootViewController:navView];
[_window makeKeyAndVisible];

#ifndef APP_STORE_RELEASE
    [KMCGeigerCounter sharedGeigerCounter].enabled = YES;
#endif

error info:
*** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3505.16/UIApplication.m:3294

remove KMCGeigerCounter app ok.

iOS 9+: SKView presence for measurement affects performance of regular views

I've fixed some bugs in the iOS 9 branch:

  • Overlay window needed a root view controller
  • Example application didn't create its table views properly
  • The meter window would be hidden if the status bar was hidden

Thanks for writing in about those. But I'm not able to ship a new release of the pod yet, because I haven't solved the most serious problem, which has to do with my method of measuring the timing of drawing.

    // Low framerates can be caused by CPU activity on the main thread or by long compositing time in (I suppose)
    // the graphics driver. If compositing time is the problem, and it doesn't require a lot of main thread activity
    // between frames, then the framerate can drop without CADisplayLink detecting it.
    // Therefore, put an empty 1pt x 1pt SKView in the window. It shouldn't interfere with the framerate, but
    // should cause the CADisplayLink callbacks to match the timing of drawing.
    // TODO: This should be lightweight but affects the framerate on iOS 9, particularly in the example application.
    // Maybe if I use only the SKView and not the CADisplayLink?
    // No, that doesn't help. The SKView alone is causing the drawing latency. The CADisplayLink does not interfere.
    // SceneKit doens't exist before iOS 8, so I'd prefer not to rely on it.
    // A GLKViewController works on the default run loop, so it doesn't get updates during core animation scrolling.
    // Using a custom view with -drawRect: or -displayLayer:, callbacks happen just as often as CADisplayLink.
    // I need a new way to accurately detect when a frame is drawn to the screen without affecting the framerate.

I've tried several things, but I don't have a solution yet. If you want to see where I am on this, check out the ios9 branch. To see the problem for yourself, try running the example application on your device with and without this line in -[KMCGeigerCounter start]:

    [[UIApplication sharedApplication].keyWindow addSubview:self.sceneView];

You'll notice that without the line, the framerate on scrolling the first tab is not smooth, but the meter reads 60. This is because the cost of rendering that view is not on the main thread like layout. With that line included, I'm able to detect the delays, but the framerate actually gets worse and should not.

iPhone X incompatible

The KMCGeigerCounter is enabled on the top center of the main screen, however it's the safe area of iPhone X.

What's the meter window ?????

Always crash like this "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'"

sample project cannot run

2017-08-26 18:35:17.370 KMCGeigerCounter[71863:6870637] *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UIApplication.m:3677
2017-08-26 18:35:17.432 KMCGeigerCounter[71863:6870637] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a365b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001098c2141 objc_exception_throw + 48
2 CoreFoundation 0x000000010a369cf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010945c536 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x000000010b2f6c46 -[UIApplication _runWithMainScene:transitionContext:completion:] + 3343
5 UIKit 0x000000010b2f37f3 -[UIApplication workspaceDidEndTransaction:] + 182
6 FrontBoardServices 0x000000010e3bd5f6 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
7 FrontBoardServices 0x000000010e3bd46d -[FBSSerialQueue _performNext] + 186
8 FrontBoardServices 0x000000010e3bd7f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
9 CoreFoundation 0x000000010a30bc01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
10 CoreFoundation 0x000000010a2f10cf __CFRunLoopDoSources0 + 527
11 CoreFoundation 0x000000010a2f05ff __CFRunLoopRun + 911
12 CoreFoundation 0x000000010a2f0016 CFRunLoopRunSpecific + 406
13 UIKit 0x000000010b2f208f -[UIApplication _run] + 468
14 UIKit 0x000000010b2f8134 UIApplicationMain + 159
15 KMCGeigerCounter 0x00000001092e47af main + 111
16 libdyld.dylib 0x000000010dd3e65d start + 1
17 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

iOS 9.3.X: Crash because window has no UIViewController

Using this pod on a device with iOS 9.3.2 I get a crash because UIKit complains that every window needs to have a rootViewController set after application:didFinishLaunchingWithOptions:.

This happens because the KMCGeigerCounter creates its own window but doesn't set a rootViewController there. So the fix is to just set some UIViewController on it:

[self.window setRootViewController:[UIViewController new]];

Would be nice if you could please make this small change and push out a new release to CocoaPods. 😉

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.