GithubHelp home page GithubHelp logo

wasabeef / takt Goto Github PK

View Code? Open in Web Editor NEW
1.1K 29.0 111.0 13.19 MB

Takt is Android library for measuring the FPS using Choreographer.

License: Apache License 2.0

Java 88.30% Kotlin 11.70%
android android-library fps

takt's Introduction

Android Arsenal License Maven Central

Takt is Android library for measuring the FPS using Choreographer.

Takt

Screenshot

How do I use it?

Setup

Dependencies
repositories {
  mavenCentral()
}

dependencies {
  releaseImplementation 'jp.wasabeef:takt-no-op:2.1.1'
  debugImplementation 'jp.wasabeef:takt:2.1.1'
}

Functions

There is a simple initialization step which occurs in your Application class:
Simple

class MyApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    Takt.stock(this)
  }
}

Options

  • seat(Seat seat) is a position
  • interval(int ms) is a interval
  • color(int color) is a text color.
  • size(int size) is a text size
  • alpha(float alpha) is a text alpha
  • listener(Audience audience) is a Listener
  • useCustomControl to manually start/stop Takt (disabled by default)
  • showOverlaySetting to enable/disable showing system overlay setting (enabled by default)
Takt.stock(this)
  .seat(Seat.BOTTOM_RIGHT)
  .interval(250)
  .color(Color.WHITE)
  .size(14f)
  .alpha(.5f)
  .listener { fps ->
    Log.d("Excellent!", fps.toString() + " fps")

    // Logcat
    // jp.wasabeef.example.takt D/Excellent!﹕ 59.28853754940712 fps
    // jp.wasabeef.example.takt D/Excellent!﹕ 59.523809523809526 fps
    // jp.wasabeef.example.takt D/Excellent!﹕ 59.05511811023622 fps
    // jp.wasabeef.example.takt D/Excellent!﹕ 55.33596837944664 fps
    // jp.wasabeef.example.takt D/Excellent!﹕ 59.523809523809526 fps
  }

Position

Takt.stock(this)
  .seat(Seat.RIGHT_CENTER)

  /**
   * TOP_RIGHT,
   * TOP_LEFT,
   * TOP_CENTER,
   *
   * CENTER,
   * RIGHT_CENTER,
   * LEFT_CENTER,
   *
   * BOTTOM_RIGHT,
   * BOTTOM_LEFT,
   * BOTTOM_CENTER
   */

Hide fps label

Takt.stock(this)
  .hide()
  .listener { fps -> Log.d("Excellent!", fps.toString() + " fps") }

Requirements

Android 4.1+ (using the Choreographer)

Developed By

Daichi Furiya (Wasabeef) - [email protected]

Follow me on Twitter

License

Copyright (C) 2020 Wasabeef

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

takt's People

Contributors

aleien avatar anoop44 avatar beigirad avatar takke avatar ttymsd avatar wasabeef avatar yukimatsumura 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

takt's Issues

did this work for games ?

i test it i run my game on 30 fps and its still says 59.8 fps
made my game run on 90 FPS and its saying 59.7 fps its like get the screen framerate

Takt.finish() will never be called

Hi, ReadMe says that finish() methos should be call in onTerminate. But this method is only used in emulated process environments and it will never be called on production device.

I suppose you can just remove this part from ReadMe or add a comment that finish() will be called only in emulated process environments.

Broken on 8.1

Hello!
Is library currently not supported? It looks like it doesn't work all good on 8.1 (didn't check other os versions). Also "how to use" is misleading.

  1. You have to use '.showOverlaySetting(true)', otherwise it won't prompt you to enable setting (and without it it doesn't show
  2. You have to add android.permission.SYSTEM_ALERT_WINDOW to your manifest, otherwise you won't be able to enable setting
  3. Misleading guide: onTerminate won't be called ever, so Takt won't be finished until system kills your process, so you need to move Takt.finish() to some other place.

Also it may be only my problem, but it somehow duplicates one over other, even when launched only once, so it's essentially impossible to see current fps :(

App crashes on startup on Samsung device on Android 7

Bug Reporting

Steps to Reproduce

Open app on Samsung device on Android version 7.1.1, app crashes

Actual Results

2020-01-08 16:16:34.919 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: package_name, PID: 29421
    java.lang.RuntimeException: Unable to start activity ComponentInfo{activity_name}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3003)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6823)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
     Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
        at android.view.ViewRootImpl.setView(ViewRootImpl.java:922)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:105)
        at jp.wasabeef.takt.Takt$Program.play(Takt.java:131)
        at jp.wasabeef.takt.Takt$Program.onAppForeground(Takt.java:110)
        at jp.wasabeef.takt.LifecycleListener.onActivityStarted(LifecycleListener.java:28)
        at android.app.Application.dispatchActivityStarted(Application.java:231)
        at android.app.Activity.onStart(Activity.java:1275)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:614)
        at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1256)
        at android.app.Activity.performStart(Activity.java:6994)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2956)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6823) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) 

OS details

  • Device: Samsung Galaxy Note 8
  • OS: Android 7.1.1

Not working on Mi Redmi Note device OS 4.4

Getting following exception after adding Takt.
android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@420f9140 -- permission denied for this window type

Leak memory

The library has memory leak. I found it with leak canary.

┬───
│ GC Root: Local variable in native code

├─ android.os.HandlerThread instance
│ Leaking: NO (PathClassLoader↓ is not leaking)
│ Thread name: 'LeakCanary-Heap-Dump'
│ ↓ Thread.contextClassLoader
├─ dalvik.system.PathClassLoader instance
│ Leaking: NO (Takt↓ is not leaking and A ClassLoader is never leaking)
│ ↓ ClassLoader.runtimeInternalObjects
├─ java.lang.Object[] array
│ Leaking: NO (Takt↓ is not leaking)
│ ↓ Object[].[3001]
├─ jp.wasabeef.takt.Takt class
│ Leaking: NO (a class is never leaking)
│ ↓ static Takt.program
│ ~~~~~~~
├─ jp.wasabeef.takt.Takt$Program instance
│ Leaking: UNKNOWN
│ Retaining 5.4 kB in 109 objects
│ app instance of com.zbs.android.App
│ ↓ Takt$Program.stageView
│ ~~~~~~~~~
╰→ android.widget.RelativeLayout instance
​ Leaking: YES (ObjectWatcher was watching this because android.widget.
​ RelativeLayout received View#onDetachedFromWindow() callback)
​ Retaining 1.7 kB in 37 objects
​ key = f8ab425e-a992-47fd-8b92-4b209925b054
​ watchDurationMillis = 5262
​ retainedDurationMillis = 224
​ key = bfb77bf7-2c19-430a-8b3a-049ced24122f
​ key = 2383ccf8-6ff7-4f82-82ab-16aba79fc564
​ watchDurationMillis = 5263
​ key = 125a0c09-786f-4d1a-8414-81d3d81a695b
​ retainedDurationMillis = 225
​ View not part of a window view hierarchy
​ View.mAttachInfo is null (view detached)
​ View.mWindowAttachCount = 4
​ mContext instance of com.zbs.android.App

METADATA

Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: Xiaomi
LeakCanary version: 2.6
App process name: com.zbs.android
Stats: LruCache[maxSize=3000,hits=5711,misses=65587,hitRate=8%]
RandomAccess[bytes=3694801,reads=65587,travel=27211795232,range=22255045,size=26
931632]
Heap dump reason: 4 retained objects, app is not visible
Analysis duration: 6717 ms

  • Device: Xiaomi mi 9 lite
  • OS: Android 10

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.