├── .gitignore ├── BlockIndigo.iml ├── LICENSE ├── README.md ├── block_demo ├── .gitignore ├── block_demo.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── dodola │ │ └── block │ │ └── demo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── dodola │ │ │ └── block │ │ │ └── demo │ │ │ ├── FragmentPagerActivity.java │ │ │ ├── MainActivity.java │ │ │ └── WatcherApplication.java │ └── res │ │ ├── layout │ │ ├── activity_anr_test.xml │ │ ├── activity_main.xml │ │ └── activity_scroll.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── dodola │ └── block │ └── demo │ └── ExampleUnitTest.java ├── blockindigo ├── .gitignore ├── blockindigo.iml ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── dodola │ └── blockindigo │ ├── ANRAnalysis.java │ ├── BlockIndigo.java │ └── ChoreographerAnalysis.java ├── blockindigo_.iml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | 34 | .idea 35 | .idea/ 36 | -------------------------------------------------------------------------------- /BlockIndigo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 dodola 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blockindigo 2 | 3 | ##简介 4 | 5 | 之前在Blockcanary的issue里讨论过,使用Blockcanary监测细粒度的卡顿会产生很多日志。 6 | 另一方面Blockcanary和我们项目里所使用的日志系统有冲突。 7 | 8 | 所以直接把Blockcanary的日志采样机制和UI拿过来写了这个,是的你没有看错。 9 | 10 | 在此之前一直使用Debug的MethodTrace进行分析,好像会有效率问题,放弃使用了。 11 | 12 | 框架的原理使用的是黄油项...(Project Butter) 中的`Choreographer`来监测类似界面绘制时候的丢帧(Skipped Frame)情况。 13 | 14 | 原理具体可以参照:http://bugly.qq.com/blog/?p=166 15 | 16 | ##使用 17 | ```groovy 18 | 19 | repositories { 20 | maven { 21 | url "http://dl.bintray.com/dodola/maven" 22 | } 23 | } 24 | 25 | compile 'com.dodola:blockindigo:1.0' 26 | ``` 27 | 28 | ```java 29 | public class WatcherApplication extends Application { 30 | @Override 31 | public void onCreate() { 32 | super.onCreate(); 33 | BlockIndigo.install(this, new BlockCanaryContext()); 34 | } 35 | } 36 | public class FragmentPagerActivity extends AppCompatActivity { 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.activity_scroll); 42 | 43 | BlockIndigo.get().start(this); 44 | } 45 | 46 | @Override 47 | protected void onDestroy() { 48 | super.onDestroy(); 49 | BlockIndigo.get().stop(); 50 | } 51 | 52 | } 53 | 54 | ``` 55 | 56 | 57 | ##相关项目 58 | [blockcanary](https://github.com/moduth/blockcanary) 59 | [leakcanary](https://github.com/square/leakcanary) 60 | 61 | -------------------------------------------------------------------------------- /block_demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /block_demo/block_demo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /block_demo/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Baidu, Inc. All Rights Reserved. 3 | */ 4 | apply plugin: 'com.android.application' 5 | repositories { 6 | maven { 7 | url "http://dl.bintray.com/dodola/maven" 8 | } 9 | } 10 | android { 11 | compileSdkVersion 'Google Inc.:Google APIs:23' 12 | buildToolsVersion "23.0.2" 13 | 14 | defaultConfig { 15 | applicationId "dodola.block.demo" 16 | minSdkVersion 18 17 | targetSdkVersion 23 18 | versionCode 1 19 | versionName "1.0" 20 | } 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | } 28 | 29 | dependencies { 30 | compile fileTree(include: ['*.jar'], dir: 'libs') 31 | testCompile 'junit:junit:4.12' 32 | compile 'com.android.support:appcompat-v7:23.+' 33 | // compile 'com.dodola:blockindigo:1.0' 34 | compile project(':blockindigo') 35 | } 36 | -------------------------------------------------------------------------------- /block_demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/baidu/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /block_demo/src/androidTest/java/dodola/block/demo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package dodola.block.demo; 5 | 6 | import android.app.Application; 7 | import android.test.ApplicationTestCase; 8 | 9 | /** 10 | * Testing Fundamentals 11 | */ 12 | public class ApplicationTest extends ApplicationTestCase { 13 | public ApplicationTest() { 14 | super(Application.class); 15 | } 16 | } -------------------------------------------------------------------------------- /block_demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /block_demo/src/main/java/dodola/block/demo/FragmentPagerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package dodola.block.demo; 5 | 6 | import java.util.Random; 7 | 8 | import android.graphics.Color; 9 | import android.os.Bundle; 10 | import android.support.v4.app.Fragment; 11 | import android.support.v4.app.FragmentActivity; 12 | import android.support.v4.app.FragmentManager; 13 | import android.support.v4.app.FragmentPagerAdapter; 14 | import android.support.v4.view.ViewPager; 15 | import android.support.v7.app.AppCompatActivity; 16 | import android.view.LayoutInflater; 17 | import android.view.View; 18 | import android.view.ViewGroup; 19 | import android.widget.LinearLayout; 20 | 21 | import dodola.blockindigo.BlockIndigo; 22 | 23 | public class FragmentPagerActivity extends AppCompatActivity { 24 | static final int NUM_ITEMS = 10; 25 | MyAdapter mAdapter; 26 | ViewPager mPager; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_scroll); 32 | BlockIndigo.get().start(this); 33 | 34 | mAdapter = new MyAdapter(getSupportFragmentManager()); 35 | 36 | mPager = (ViewPager) findViewById(R.id.viewpager); 37 | mPager.setAdapter(mAdapter); 38 | } 39 | 40 | @Override 41 | protected void onDestroy() { 42 | super.onDestroy(); 43 | BlockIndigo.get().stop(); 44 | } 45 | 46 | public static class MyAdapter extends FragmentPagerAdapter { 47 | public MyAdapter(FragmentManager fm) { 48 | super(fm); 49 | } 50 | 51 | @Override 52 | public int getCount() { 53 | return NUM_ITEMS; 54 | } 55 | 56 | @Override 57 | public Fragment getItem(int position) { 58 | return ArrayListFragment.newInstance(); 59 | } 60 | } 61 | 62 | public static class ArrayListFragment extends Fragment { 63 | 64 | static ArrayListFragment newInstance() { 65 | return new ArrayListFragment(); 66 | } 67 | 68 | @Override 69 | public void onCreate(Bundle savedInstanceState) { 70 | super.onCreate(savedInstanceState); 71 | } 72 | 73 | @Override 74 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 75 | try { 76 | Thread.sleep(500); 77 | } catch (InterruptedException e) { 78 | e.printStackTrace(); 79 | } 80 | LinearLayout rootView = new LinearLayout(getActivity()); 81 | Random rand = new Random(System.currentTimeMillis()); 82 | int r = rand.nextInt(255); 83 | int g = rand.nextInt(255); 84 | int b = rand.nextInt(255); 85 | int randomColor = Color.rgb(r, g, b); 86 | rootView.setBackgroundColor(randomColor); 87 | return rootView; 88 | } 89 | 90 | @Override 91 | public void onActivityCreated(Bundle savedInstanceState) { 92 | super.onActivityCreated(savedInstanceState); 93 | } 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /block_demo/src/main/java/dodola/block/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package dodola.block.demo; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.View; 10 | import android.widget.Button; 11 | 12 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | Button btn = (Button) this.findViewById(R.id.anr_test); 19 | btn.setOnClickListener(this); 20 | 21 | } 22 | 23 | @Override 24 | public void onClick(View v) { 25 | switch (v.getId()) { 26 | case R.id.anr_test: 27 | startActivity(new Intent(this, FragmentPagerActivity.class)); 28 | break; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /block_demo/src/main/java/dodola/block/demo/WatcherApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package dodola.block.demo; 5 | 6 | import android.app.Application; 7 | 8 | import com.github.moduth.blockcanary.BlockCanaryContext; 9 | 10 | import dodola.blockindigo.BlockIndigo; 11 | 12 | /** 13 | * Created by sunpengfei on 16/1/17. 14 | */ 15 | public class WatcherApplication extends Application { 16 | @Override 17 | public void onCreate() { 18 | super.onCreate(); 19 | BlockIndigo.install(this, new BlockCanaryContext()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /block_demo/src/main/res/layout/activity_anr_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /block_demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 12 | 13 |