diff options
author | Tenghui Zhu <ztenghui@google.com> | 2016-07-12 20:41:57 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-07-12 20:41:59 +0000 |
commit | 19c6ae310c4d5cf86fd38126db7c342c6f56976b (patch) | |
tree | 0d952976200ff308de60e20aba7902962233c518 /apct-tests/perftests/utils | |
parent | 3b457c74d98f8498e6cee85666d26482c220fb6c (diff) | |
parent | a9cebd628c53b900d48600a5e7ced546c91522e6 (diff) |
Merge "Add layout perf test into APCT"
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 2c5a9eac481d..4213e4a3aa2b 100644 --- a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java +++ b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java @@ -176,10 +176,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(); + } + } +} |