am 6fcf3a51: Merge "Improving profiling of views." into gingerbread
Merge commit '6fcf3a518526d4f844830735ca1a2ae82a7500d8' into gingerbread-plus-aosp * commit '6fcf3a518526d4f844830735ca1a2ae82a7500d8': Improving profiling of views.
This commit is contained in:
@@ -916,72 +916,13 @@ public class ViewDebug {
|
|||||||
out = new BufferedWriter(new OutputStreamWriter(clientStream), 32 * 1024);
|
out = new BufferedWriter(new OutputStreamWriter(clientStream), 32 * 1024);
|
||||||
|
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
final long durationMeasure = profileViewOperation(view, new ViewOperation<Void>() {
|
profileViewAndChildren(view, out);
|
||||||
public Void[] pre() {
|
|
||||||
forceLayout(view);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void forceLayout(View view) {
|
|
||||||
view.forceLayout();
|
|
||||||
if (view instanceof ViewGroup) {
|
|
||||||
ViewGroup group = (ViewGroup) view;
|
|
||||||
final int count = group.getChildCount();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
forceLayout(group.getChildAt(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(Void... data) {
|
|
||||||
view.measure(view.mOldWidthMeasureSpec, view.mOldHeightMeasureSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void post(Void... data) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final long durationLayout = profileViewOperation(view, new ViewOperation<Void>() {
|
|
||||||
public Void[] pre() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(Void... data) {
|
|
||||||
view.layout(view.mLeft, view.mTop, view.mRight, view.mBottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void post(Void... data) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final long durationDraw = profileViewOperation(view, new ViewOperation<Object>() {
|
|
||||||
public Object[] pre() {
|
|
||||||
final DisplayMetrics metrics = view.getResources().getDisplayMetrics();
|
|
||||||
final Bitmap bitmap = Bitmap.createBitmap(metrics.widthPixels,
|
|
||||||
metrics.heightPixels, Bitmap.Config.RGB_565);
|
|
||||||
final Canvas canvas = new Canvas(bitmap);
|
|
||||||
return new Object[] { bitmap, canvas };
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(Object... data) {
|
|
||||||
view.draw((Canvas) data[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void post(Object... data) {
|
|
||||||
((Bitmap) data[0]).recycle();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
out.write(String.valueOf(durationMeasure));
|
|
||||||
out.write(' ');
|
|
||||||
out.write(String.valueOf(durationLayout));
|
|
||||||
out.write(' ');
|
|
||||||
out.write(String.valueOf(durationDraw));
|
|
||||||
out.newLine();
|
|
||||||
} else {
|
} else {
|
||||||
out.write("-1 -1 -1");
|
out.write("-1 -1 -1");
|
||||||
out.newLine();
|
out.newLine();
|
||||||
}
|
}
|
||||||
|
out.write("DONE.");
|
||||||
|
out.newLine();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
android.util.Log.w("View", "Problem profiling the view:", e);
|
android.util.Log.w("View", "Problem profiling the view:", e);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -991,6 +932,82 @@ public class ViewDebug {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void profileViewAndChildren(final View view, BufferedWriter out)
|
||||||
|
throws IOException {
|
||||||
|
final long durationMeasure = profileViewOperation(view, new ViewOperation<Void>() {
|
||||||
|
public Void[] pre() {
|
||||||
|
forceLayout(view);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void forceLayout(View view) {
|
||||||
|
view.forceLayout();
|
||||||
|
if (view instanceof ViewGroup) {
|
||||||
|
ViewGroup group = (ViewGroup) view;
|
||||||
|
final int count = group.getChildCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
forceLayout(group.getChildAt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Void... data) {
|
||||||
|
view.measure(view.mOldWidthMeasureSpec, view.mOldHeightMeasureSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void post(Void... data) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final long durationLayout = profileViewOperation(view, new ViewOperation<Void>() {
|
||||||
|
public Void[] pre() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Void... data) {
|
||||||
|
view.layout(view.mLeft, view.mTop, view.mRight, view.mBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void post(Void... data) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final long durationDraw = profileViewOperation(view, new ViewOperation<Object>() {
|
||||||
|
public Object[] pre() {
|
||||||
|
final DisplayMetrics metrics = view.getResources().getDisplayMetrics();
|
||||||
|
final Bitmap bitmap =
|
||||||
|
Bitmap.createBitmap(metrics.widthPixels, metrics.heightPixels,
|
||||||
|
Bitmap.Config.RGB_565);
|
||||||
|
final Canvas canvas = new Canvas(bitmap);
|
||||||
|
return new Object[] {
|
||||||
|
bitmap, canvas
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(Object... data) {
|
||||||
|
view.draw((Canvas) data[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void post(Object... data) {
|
||||||
|
((Bitmap) data[0]).recycle();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
out.write(String.valueOf(durationMeasure));
|
||||||
|
out.write(' ');
|
||||||
|
out.write(String.valueOf(durationLayout));
|
||||||
|
out.write(' ');
|
||||||
|
out.write(String.valueOf(durationDraw));
|
||||||
|
out.newLine();
|
||||||
|
if (view instanceof ViewGroup) {
|
||||||
|
ViewGroup group = (ViewGroup) view;
|
||||||
|
final int count = group.getChildCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
profileViewAndChildren(group.getChildAt(i), out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface ViewOperation<T> {
|
interface ViewOperation<T> {
|
||||||
T[] pre();
|
T[] pre();
|
||||||
void run(T... data);
|
void run(T... data);
|
||||||
|
|||||||
Reference in New Issue
Block a user