1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.layoutlib.bridge.intensive.util.perf; 18 19 import com.android.layoutlib.bridge.intensive.util.perf.LongStatsCollector.Stats; 20 21 import java.text.DecimalFormat; 22 23 /** 24 * Result value of a {@link TimedStatement} 25 */ 26 public class TimedStatementResult { 27 private static final DecimalFormat UNITS_FORMAT = new DecimalFormat("#.##"); 28 29 private final int mWarmUpIterations; 30 private final int mRuns; 31 private final double mCalibrationTimeMs; 32 private final Stats mTimeStats; 33 private final Stats mMemoryStats; 34 TimedStatementResult(int warmUpIterations, int runs, double calibrationTimeMs, Stats timeStats, Stats memoryStats)35 TimedStatementResult(int warmUpIterations, int runs, 36 double calibrationTimeMs, 37 Stats timeStats, 38 Stats memoryStats) { 39 mWarmUpIterations = warmUpIterations; 40 mRuns = runs; 41 mCalibrationTimeMs = calibrationTimeMs; 42 mTimeStats = timeStats; 43 mMemoryStats = memoryStats; 44 } 45 46 @Override toString()47 public String toString() { 48 return String.format( 49 "Warm up %d. Runs %d\n" + "Time: %s ms (min: %s, max %s)\n" + 50 "Calibration Time: %f ms\n" + 51 "Calibrated Time: %s units (min: %s, max %s)\n" + 52 "Sampled %d times\n" + 53 " Memory used: %d bytes (max %d)\n\n", 54 mWarmUpIterations, mRuns, 55 mTimeStats.getMedian(), mTimeStats.getMin(), mTimeStats.getMax(), 56 mCalibrationTimeMs, 57 UNITS_FORMAT.format((mTimeStats.getMedian() / mCalibrationTimeMs) * 100000), 58 UNITS_FORMAT.format((mTimeStats.getMin() / mCalibrationTimeMs) * 100000), 59 UNITS_FORMAT.format((mTimeStats.getMax() / mCalibrationTimeMs) * 100000), 60 mMemoryStats.getSampleCount(), 61 (long)mMemoryStats.getMedian() - mMemoryStats.getMin(), 62 mMemoryStats.getMax() - mMemoryStats.getMin()); 63 } 64 } 65