Summary: Let's introduce a set of new cost analysis issue types that are raised when the function is statically determined to run on the UI thread. For this, we rely on the existing `runs_on_ui_thread` check that is developed for RacerD. We also update the cost summary and `jsonbug.cost_item` to include whether a method is on the ui thread so that we don't repeatedly compute this at diff time for complexity increase issues. Note that `*_UI_THREAD` cost issues are assumed to be more strict than `*_COLD_START` reports at the moment. Next, we can also consider adding a new issue type that combines both such as `*_UI_THREAD_AND_COLD_START` (i.e. for methods that are both on cold start and run on ui thread). Reviewed By: ngorogiannis Differential Revision: D18428408 fbshipit-source-id: f18805716master
parent
e66a23a04c
commit
94f4ded9b4
@ -1 +1 @@
|
|||||||
{"top":{"current":4,"previous":2},"zero":{"current":17,"previous":15},"degrees":[{"degree":0,"current":8,"previous":7},{"degree":100,"current":3,"previous":4},{"degree":101,"current":4,"previous":0},{"degree":200,"current":2,"previous":4}]}
|
{"top":{"current":4,"previous":2},"zero":{"current":21,"previous":19},"degrees":[{"degree":0,"current":11,"previous":10},{"degree":100,"current":4,"previous":5},{"degree":101,"current":4,"previous":0},{"degree":200,"current":2,"previous":4}]}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.support.annotation.UiThread;
|
||||||
|
|
||||||
|
// This class has the following costs:
|
||||||
|
// 3 constant, 1 linear
|
||||||
|
// constructor: constant
|
||||||
|
// f1: constant
|
||||||
|
// f2: linear
|
||||||
|
// f3: constant
|
||||||
|
|
||||||
|
public class DiffExampleUIThread {
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public void f1(int x) {
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public void f2(int x) {
|
||||||
|
for (int i = 0; i < x; i++) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public void f3(int x) {
|
||||||
|
f1(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.support.annotation.UiThread;
|
||||||
|
|
||||||
|
// This class has the following costs:
|
||||||
|
// 3 constant, 1 linear
|
||||||
|
// constructor: constant
|
||||||
|
// f1: linear
|
||||||
|
// f2: constant
|
||||||
|
// f3: constant
|
||||||
|
|
||||||
|
public class DiffExampleUIThread {
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public void f1(int x) {
|
||||||
|
for (int i = 0; i < x; i++) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public int f2(int x) {
|
||||||
|
return x+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public int f3(int x) {
|
||||||
|
return f2(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package codetoanalyze.java.checkers;
|
||||||
|
|
||||||
|
import android.support.annotation.UiThread;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
@interface OnBind {}
|
||||||
|
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
@interface OnEvent {}
|
||||||
|
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
@interface OnMount {}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
class AllMethodsOnUiThread {
|
||||||
|
int f;
|
||||||
|
|
||||||
|
void foo_UIThread_constant() {
|
||||||
|
f = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bar_UIThread_linear() {
|
||||||
|
for (int i = 0; i < f; i++) {
|
||||||
|
foo_UIThread_constant();
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExtendsClassOnUiThread extends AllMethodsOnUiThread {
|
||||||
|
@Override
|
||||||
|
void foo_UIThread_constant() {
|
||||||
|
f = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int bar_UIThread_linear() {
|
||||||
|
return super.bar_UIThread_linear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UIAnnotationTest {
|
||||||
|
|
||||||
|
// NOT All annotations that start with "On" are on the main thread
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
@interface OnXYZ {}
|
||||||
|
|
||||||
|
class WeirdAnnotation {
|
||||||
|
int f;
|
||||||
|
|
||||||
|
@OnXYZ
|
||||||
|
void foo_linear() {
|
||||||
|
for (int i = 0; i < f; i++) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Annotations {
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public void loop_UIThread_linear(int x) {
|
||||||
|
for (int i = 0; i < x; i++) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void constant() {
|
||||||
|
// not on UI thread
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loop_linear(int x) {
|
||||||
|
for (int i = 0; i < x; i++) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// anything annotated with OnEvent is modeled as running on the UIThread
|
||||||
|
@OnEvent
|
||||||
|
public void onClick_linear(int x) {
|
||||||
|
for (int i = 0; i < x; i++) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnBind
|
||||||
|
public void onBindMethod_linear(int x) {
|
||||||
|
loop_linear(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue