Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8e1219c authored by Konstantin Lopyrev's avatar Konstantin Lopyrev
Browse files

Improving profiling of views.

Change-Id: I1abb8c21f1769ad55416f37e7bfa1458b80ace63
parent 739cdab7
Loading
Loading
Loading
Loading
+77 −60
Original line number Diff line number Diff line
@@ -916,6 +916,24 @@ public class ViewDebug {
            out = new BufferedWriter(new OutputStreamWriter(clientStream), 32 * 1024);

            if (view != null) {
                profileViewAndChildren(view, out);
            } else {
                out.write("-1 -1 -1");
                out.newLine();
            }
            out.write("DONE.");
            out.newLine();
        } catch (Exception e) {
            android.util.Log.w("View", "Problem profiling the view:", e);
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }

    private static void profileViewAndChildren(final View view, BufferedWriter out)
            throws IOException {
        final long durationMeasure = profileViewOperation(view, new ViewOperation<Void>() {
            public Void[] pre() {
                forceLayout(view);
@@ -957,10 +975,13 @@ public class ViewDebug {
        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 Bitmap bitmap =
                        Bitmap.createBitmap(metrics.widthPixels, metrics.heightPixels,
                                Bitmap.Config.RGB_565);
                final Canvas canvas = new Canvas(bitmap);
                        return new Object[] { bitmap, canvas };
                return new Object[] {
                        bitmap, canvas
                };
            }

            public void run(Object... data) {
@@ -978,15 +999,11 @@ public class ViewDebug {
        out.write(' ');
        out.write(String.valueOf(durationDraw));
        out.newLine();
            } else {
                out.write("-1 -1 -1");
                out.newLine();
            }
        } catch (Exception e) {
            android.util.Log.w("View", "Problem profiling the view:", e);
        } finally {
            if (out != null) {
                out.close();
        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);
            }
        }
    }