GithubHelp home page GithubHelp logo

youxiang / blockcanary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from markzhai/androidperformancemonitor

0.0 2.0 0.0 461 KB

A transparent ui-block detection library for Android.

Home Page: http://blog.zhaiyifan.cn/2016/01/16/BlockCanaryTransparentPerformanceMonitor/

License: Apache License 2.0

Java 100.00%

blockcanary's Introduction

中文

BlockCanary Maven Central

A transparent ui-block detection library for Android. App only needs one-line-code to setup and provide application context.

Getting started

dependencies {
    // or you can use compile directly if want to enable it in release package and upload log file to server
    // compile 'com.github.moduth:blockcanary:1.0.1'
    debugCompile 'com.github.moduth:blockcanary:1.0.1'
    releaseCompile 'com.github.moduth:blockcanary-no-op:1.0.1'
}

Usage

public class DemoApplication extends Application {
    @Override
    public void onCreate() {
        ...
        // Do it on main process
        BlockCanary.install(this, new AppBlockCanaryContext()).start();
    }
}

Implement BlockCanaryContext context:

public class AppBlockCanaryContext extends BlockCanaryContext {
    // override to provide context like app qualifier, uid, network type, block threshold, log save path

    // this is default block threshold, you can set it by phone's performance
    @Override
    public int getConfigBlockThreshold() {
        return 500;
    }

    // if set true, notification will be shown, else only write log file
    @Override
    public boolean isNeedDisplay() {
        return BuildConfig.DEBUG;
    }

    // path to save log file
    @Override
    public String getLogPath() {
        return "/blockcanary/performance";
    }
}

How does it work?

See BlockCanary.

  1. BlockCanary.install() initializes context and internal data structures.
  2. BlockCanary.start() starts monitor by Looper.getMainLooper().setMessageLogging(mMainLooperPrinter);
  3. ThreadStackSampler and CpuSampler start catching thread stack and cpu data.
  4. Each time a message dispatch costs time over that set by BlockCanaryContext.getConfigBlockThreshold, it triggers a block notify.
  5. Write log file with data for analysis.
  6. If BlockCanaryContext.isNeedDisplay is true, a notification is shown, developer can click and check directly.

Screenshot

Block detail Block list

blockcanary's People

Contributors

markzhai avatar nimengbo avatar android-cjj avatar

Watchers

James Cloos avatar xiaoyao 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.