Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jafu888 committed Aug 31, 2022
1 parent 0b849d3 commit edf84cc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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";
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -126,15 +126,19 @@ 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;
mSimpleEquations = metrics.mSimpleEquations;
mNumberOfMeasures = metrics.mNumberOfMeasures;
mNumberOfLayouts = metrics.mNumberOfLayouts;
mMeasureDuration = metrics.mMeasureDuration;
mChildCount = metrics.mChildCount;
mChildCount = metrics.mChildCount;
mMeasureCalls = metrics.mMeasureCalls;
measuresWidgetsDuration = metrics.measuresWidgetsDuration;
mSolverPasses = metrics.mSolverPasses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit edf84cc

Please sign in to comment.