diff options
author | Teng-Hui Zhu <ztenghui@google.com> | 2016-07-07 10:51:40 -0700 |
---|---|---|
committer | Teng-Hui Zhu <ztenghui@google.com> | 2016-07-12 10:52:49 -0700 |
commit | a9cebd628c53b900d48600a5e7ced546c91522e6 (patch) | |
tree | ea8d29dfc36abffcbb55baeb952f853ea53d5de5 /apct-tests/perftests/utils | |
parent | 88dece9144e4806ef54f41cc9273d7c07ee53371 (diff) |
Add layout perf test into APCT
Change-Id: I32971176cdf60e8848180f2c923ca2f88fc19e4d
Diffstat (limited to 'apct-tests/perftests/utils')
-rw-r--r-- | apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java | 13 | ||||
-rw-r--r-- | apct-tests/perftests/utils/src/android/perftests/utils/LayoutUtils.java | 58 |
2 files changed, 67 insertions, 4 deletions
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java index 8e1674abae08..80ffbd5eaa60 100644 --- a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java +++ b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java @@ -145,10 +145,15 @@ public class BenchmarkState { private String summaryLine() { StringBuilder sb = new StringBuilder(); sb.append("Summary: "); - sb.append("median=" + median() + "ns, "); - sb.append("mean=" + mean() + "ns, "); - sb.append("sigma=" + standardDeviation() + ", "); - sb.append("iteration=" + mResults.size()); + sb.append("median=").append(median()).append("ns, "); + sb.append("mean=").append(mean()).append("ns, "); + sb.append("sigma=").append(standardDeviation()).append(", "); + sb.append("iteration=").append(mResults.size()).append(", "); + // print out the first few iterations' number for double checking. + int sampleNumber = Math.min(mResults.size(), MIN_REPEAT_TIMES); + for (int i = 0; i < sampleNumber; i++) { + sb.append("No ").append(i).append(" result is ").append(mResults.get(i)).append(", "); + } return sb.toString(); } diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/LayoutUtils.java b/apct-tests/perftests/utils/src/android/perftests/utils/LayoutUtils.java new file mode 100644 index 000000000000..c64af8fccb36 --- /dev/null +++ b/apct-tests/perftests/utils/src/android/perftests/utils/LayoutUtils.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.perftests.utils; + +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; +import java.util.List; + +public class LayoutUtils { + + private static void recursivelyGather(ViewGroup currentNode, List<View> nodeList) { + nodeList.add(currentNode); + int count = currentNode.getChildCount(); + for (int i = 0; i < count; i++) { + View view = currentNode.getChildAt(i); + if (view instanceof ViewGroup) { + recursivelyGather((ViewGroup) view, nodeList); + } else { + nodeList.add(view); + } + } + } + + /** + * Flattern the whole view tree into a list of View. + */ + public static List<View> gatherViewTree(ViewGroup root) { + List<View> result = new ArrayList<View>(); + recursivelyGather(root, result); + return result; + } + + /** + * For every node in the list, call requestLayout. + */ + public static void requestLayoutForAllNodes(List<View> nodeList) { + int count = nodeList.size(); + for (int i = 0; i < count; i++) { + nodeList.get(i).requestLayout(); + } + } +} |