Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 1.3.0 #62

Merged
merged 18 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

You can watch releases [on Maven](https://oss.sonatype.org/content/groups/public/com/github/moduth/).

## Version 1.3

- Code refactor.
- Support white-list and concern packages.

## Version 1.2 *(2016-03-16)*

- Much faster! It now has almost none side-effect at run-time.
Expand Down
168 changes: 145 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Chinese README](https://github.com/moduth/blockcanary/blob/master/README_CN.md)

# BlockCanary [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.moduth/blockcanary-android/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.github.moduth/blockcanary-android)
A transparent ui-block detection library for Android, app only needs one-line-code to setup. Author: [markzhai](https://github.com/markzhai), [Contributors](https://github.com/moduth/blockcanary#contributors)
A transparent ui-block detection library for Android, app only needs one-line-code to setup.

The naming is to pay respect to the great library [LeakCanary](https://github.com/square/leakcanary), ui-related codes are modified from leakcanary's ui part.

Expand All @@ -12,28 +12,28 @@ You may choose how to assemble them as you like.
```gradle
dependencies {
// most often used way, enable notification to notify block event
compile 'com.github.moduth:blockcanary-android:1.2.1'
compile 'com.github.moduth:blockcanary-android:1.3.0'

// this way you only enable BlockCanary in debug package
// debugCompile 'com.github.moduth:blockcanary-android:1.2.1'
// releaseCompile 'com.github.moduth:blockcanary-no-op:1.2.1'
// debugCompile 'com.github.moduth:blockcanary-android:1.3.0'
// releaseCompile 'com.github.moduth:blockcanary-no-op:1.3.0'
}
```

PS: As this library uses `getMainLooper().setMessageLogging()`, please check if you also set that in your app. (check related issue https://github.com/moduth/blockcanary/issues/27)
As this library uses `getMainLooper().setMessageLogging()`, please check if you set it in your app (related issue https://github.com/moduth/blockcanary/issues/27)

# Usage

Maximum log count is set to 100, you can rewrite it in your app `int.xml`.
Maximum log count is set to 500, you can rewrite it in your app `int.xml`.
```xml
<integer name="block_canary_max_stored_count">100</integer>
<integer name="block_canary_max_stored_count">1000</integer>
```

```java
public class DemoApplication extends Application {
@Override
public void onCreate() {
...
// ...
// Do it on main process
BlockCanary.install(this, new AppBlockCanaryContext()).start();
}
Expand All @@ -43,24 +43,144 @@ public class DemoApplication extends Application {
Implement BlockCanaryContext context:
```java
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;
/**
* Implement in your project.
*
* @return Qualifier which can specify this installation, like version + flavor.
*/
public String provideQualifier() {
return "unknown";
}

// if set true, notification will be shown, else only write log file
@Override
public boolean isNeedDisplay() {
return BuildConfig.DEBUG;
/**
* Implement in your project.
*
* @return user id
*/
public String provideUid() {
return "uid";
}

// path to save log file
@Override
public String getLogPath() {
return "/blockcanary/performance";
/**
* Network type
*
* @return {@link String} like 2G, 3G, 4G, wifi, etc.
*/
public String provideNetworkType() {
return "unknown";
}

/**
* Config monitor duration, after this time BlockCanary will stop, use
* with {@code BlockCanary}'s isMonitorDurationEnd
*
* @return monitor last duration (in hour)
*/
public int provideMonitorDuration() {
return -1;
}

/**
* Config block threshold (in millis), dispatch over this duration is regarded as a BLOCK. You may set it
* from performance of device.
*
* @return threshold in mills
*/
public int provideBlockThreshold() {
return 1000;
}

/**
* Thread stack dump interval, use when block happens, BlockCanary will dump on main thread
* stack according to current sample cycle.
* <p>
* Because the implementation mechanism of Looper, real dump interval would be longer than
* the period specified here (especially when cpu is busier).
* </p>
*
* @return dump interval (in millis)
*/
public int provideDumpInterval() {
return provideBlockThreshold();
}

/**
* Path to save log, like "/blockcanary/", will save to sdcard if can.
*
* @return path of log files
*/
public String providePath() {
return "/blockcanary/";
}

/**
* If need notification to notice block.
*
* @return true if need, else if not need.
*/
public boolean displayNotification() {
return true;
}

/**
* Implement in your project, bundle files into a zip file.
*
* @param src files before compress
* @param dest files compressed
* @return true if compression is successful
*/
public boolean zip(File[] src, File dest) {
return false;
}

/**
* Implement in your project, bundled log files.
*
* @param zippedFile zipped file
*/
public void upload(File zippedFile) {
throw new UnsupportedOperationException();
}


/**
* Packages that developer concern, by default it uses process name,
* put high priority one in pre-order.
*
* @return null if simply concern only package with process name.
*/
public List<String> concernPackages() {
return null;
}

/**
* Filter stack without any in concern package, used with @{code concernPackages}.
*
* @return true if filter, false it not.
*/
public boolean filterNonConcernStack() {
return false;
}

/**
* Provide white list, entry in white list will not be shown in ui list.
*
* @return return null if you don't need white-list filter.
*/
public List<String> provideWhiteList() {
LinkedList<String> whiteList = new LinkedList<>();
whiteList.add("org.chromium");
return whiteList;
}

/**
* Whether to delete files whose stack is in white list, used with white-list.
*
* @return true if delete, false it not.
*/
public boolean deleteFilesInWhiteList() {
return true;
}
}
```
Expand All @@ -86,9 +206,9 @@ Principle flow picture:

# Contributors

This library is initially created by [markzhai](https://github.com/markzhai), and is maintained under the organization [moduth](https://github.com/moduth) with [nimengbo](https://github.com/nimengbo) and [zzz40500](https://github.com/zzz40500).
This library is initially created by [markzhai](https://github.com/markzhai), and maintained under the organization [moduth](https://github.com/moduth) with [nimengbo](https://github.com/nimengbo) and [zzz40500](https://github.com/zzz40500).

Special thanks to [android-cjj](https://github.com/android-cjj), [Mr.Bao](https://github.com/baoyongzhang), [chiahaolu](https://github.com/chiahaolu) to contribute when this library is still young.
Special thanks to [android-cjj](https://github.com/android-cjj), [Mr.Bao](https://github.com/baoyongzhang), [chiahaolu](https://github.com/chiahaolu) to contribute.

# Change Log

Expand All @@ -100,6 +220,8 @@ If you would like to contribute code to BlockCanary you can do so through GitHub

# License

Copyright (C) 2016 MarkZhai (http://zhaiyifan.cn).

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
Expand Down
10 changes: 6 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ BlockCanary是一个Android平台的一个非侵入式的性能监控组件,

```gradle
dependencies {
compile 'com.github.moduth:blockcanary-android:1.2.1'
compile 'com.github.moduth:blockcanary-android:1.3.0'

// 仅在debug包启用BlockCanary进行卡顿监控和提示的话,可以这么用
debugCompile 'com.github.moduth:blockcanary-android:1.2.1'
releaseCompile 'com.github.moduth:blockcanary-no-op:1.2.1'
debugCompile 'com.github.moduth:blockcanary-android:1.3.0'
releaseCompile 'com.github.moduth:blockcanary-no-op:1.3.0'
}
```

Expand Down Expand Up @@ -55,7 +55,7 @@ public class AppBlockCanaryContext extends BlockCanaryContext {
见[BlockCanary — 轻松找出Android App界面卡顿元凶](http://blog.zhaiyifan.cn/2016/01/16/BlockCanaryTransparentPerformanceMonitor/).

或见下图
![flow](art/flow-cn.png "flow")
![flow](art/flow.png "flow")

# 如何分析log
除了图形界面可以供开发、测试阶段直接看卡顿原因外,更多的使用场景其实在于大范围的log采集和分析:如线上环境和monkey,或者测试同学们在整个测试阶段的log收集和分析。
Expand Down Expand Up @@ -91,6 +91,8 @@ public class AppBlockCanaryContext extends BlockCanaryContext {

# 协议

Copyright (C) 2016 MarkZhai (http://zhaiyifan.cn).

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
Expand Down
Binary file removed art/flow-cn.png
Binary file not shown.
1 change: 1 addition & 0 deletions blockcanary-analyzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
24 changes: 24 additions & 0 deletions blockcanary-analyzer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.library'
apply from: 'gradle-mvn-push.gradle'

android {
compileSdkVersion LIBRARY_COMPILE_SDK_VERSION
buildToolsVersion LIBRARY_BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion LIBRARY_MIN_SDK_VERSION
targetSdkVersion LIBRARY_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Loading