From edf84cca52fdd3c06ec1bd4b525704528e106000 Mon Sep 17 00:00:00 2001 From: John Hoford Date: Wed, 31 Aug 2022 14:56:59 -0700 Subject: [PATCH] resolve comments --- .../widget/ConstraintLayout.java | 2 +- .../widget/ConstraintLayoutStatistics.java | 38 +++++++++++++++++-- .../constraintlayout/core/LinearSystem.java | 1 - .../constraintlayout/core/Metrics.java | 14 ++++--- .../app/CheckPerformanceMetric.java | 10 ++--- 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayout.java b/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayout.java index e74ae497f..a20071df6 100644 --- a/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayout.java +++ b/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayout.java @@ -1790,7 +1790,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mMetrics != null) { time = System.nanoTime(); mMetrics.mChildCount = getChildCount(); - mMetrics.mMeasureCalls ++; + mMetrics.mMeasureCalls++; } mDirtyHierarchy |= dynamicUpdateConstraints(widthMeasureSpec, heightMeasureSpec); diff --git a/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayoutStatistics.java b/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayoutStatistics.java index 0a3d8a8bc..e684b7c68 100644 --- a/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayoutStatistics.java +++ b/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/widget/ConstraintLayoutStatistics.java @@ -99,10 +99,17 @@ public ConstraintLayoutStatistics clone() { return new ConstraintLayoutStatistics(this); } - private String fmt(DecimalFormat df, float val, int sp) { - String s = new String(new char[sp]).replace('\0', ' '); + /** + * Format a float value outputting a string of fixed length + * @param df format to use + * @param val + * @param length + * @return + */ + private String fmt(DecimalFormat df, float val, int length) { + String s = new String(new char[length]).replace('\0', ' '); s = (s + df.format(val)); - return s.substring(s.length() - sp); + return s.substring(s.length() - length); } /** @@ -134,6 +141,12 @@ private void log(String tag) { Log.v(tag, log( NUMBER_OF_SIMPLE_EQUATIONS)); } + /** + * Generate a formatted String for the parameter formatting as a float + * @param df + * @param param + * @return + */ private String log(DecimalFormat df, int param) { String value = fmt(df, getValue(param) * 1E-6f, 7); @@ -143,6 +156,12 @@ private String log(DecimalFormat df, int param) { title += " = "; return "CL Perf: " + title + value; } + + /** + * Generate a formatted String for the parameter + * @param param + * @return + */ private String log(int param) { String value = Long.toString(this.getValue(param)); String title = geName(param); @@ -152,6 +171,13 @@ private String log(int param) { return "CL Perf: " + title + value; } + /** + * Generate a float formatted String for the parameter comparing current value with value in relative + * @param df Format the float using this + * @param relative compare against + * @param param the parameter to compare + * @return + */ private String compare(DecimalFormat df, ConstraintLayoutStatistics relative, int param) { String value = fmt(df, getValue(param) * 1E-6f, 7); value += " -> " + fmt(df, relative.getValue(param) * 1E-6f, 7) + "ms"; @@ -162,6 +188,12 @@ private String compare(DecimalFormat df, ConstraintLayoutStatistics relative, i return "CL Perf: " + title + value; } + /** + * Generate a formatted String for the parameter comparing current value with value in relative + * @param relative compare against + * @param param the parameter to compare + * @return + */ private String compare(ConstraintLayoutStatistics relative, int param) { String value = this.getValue(param) + " -> " + relative.getValue(param); String title = geName(param); diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/LinearSystem.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/LinearSystem.java index 760f22841..309a25b05 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/LinearSystem.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/LinearSystem.java @@ -31,7 +31,6 @@ public class LinearSystem { public static final boolean FULL_DEBUG = false; public static final boolean DEBUG = false; private static final boolean DO_NOT_USE = false; - // public static final boolean MEASURE = false; private static final boolean DEBUG_CONSTRAINTS = FULL_DEBUG; diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/Metrics.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/Metrics.java index 9590a8d7d..70da2cfad 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/Metrics.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/Metrics.java @@ -64,9 +64,9 @@ public class Metrics { public long mMeasureDuration; // time spent in measure in nanoseconds public long mChildCount; // number of child Views of ConstraintLayout public long mMeasureCalls; // number of time CL onMeasure is called - public long mSolverPasses; - public long mEquations; - public long mVariables; + public long mSolverPasses; + public long mEquations; + public long mVariables; public long mSimpleEquations; // @TODO: add description @@ -126,7 +126,11 @@ public void reset() { mEquations = 0; mSimpleEquations = 0; } - + + /** + * Copy the values from and existing Metrics class + * @param metrics + */ public void copy(Metrics metrics) { mVariables = metrics.mVariables; mEquations = metrics.mEquations; @@ -134,7 +138,7 @@ public void copy(Metrics metrics) { mNumberOfMeasures = metrics.mNumberOfMeasures; mNumberOfLayouts = metrics.mNumberOfLayouts; mMeasureDuration = metrics.mMeasureDuration; - mChildCount = metrics.mChildCount; + mChildCount = metrics.mChildCount; mMeasureCalls = metrics.mMeasureCalls; measuresWidgetsDuration = metrics.measuresWidgetsDuration; mSolverPasses = metrics.mSolverPasses; diff --git a/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/CheckPerformanceMetric.java b/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/CheckPerformanceMetric.java index 4e1fbb43a..f8c7896ea 100644 --- a/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/CheckPerformanceMetric.java +++ b/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/CheckPerformanceMetric.java @@ -32,11 +32,11 @@ */ public class CheckPerformanceMetric extends AppCompatActivity { private static final String TAG = "CheckPerformanceMetric"; - String layout_name; - ConstraintLayout mConstraintLayout; - ConstraintLayoutStatistics performance; - ConstraintLayoutStatistics prePerformance; - int loop; + String layout_name = null; + ConstraintLayout mConstraintLayout = null; + ConstraintLayoutStatistics performance = null; + ConstraintLayoutStatistics prePerformance = null; + int loop = 0; @Override protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {