1 /* 2 * Copyright 2024 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 androidx.benchmark 18 19 import android.os.Bundle 20 import androidx.benchmark.Errors.PREFIX 21 import androidx.benchmark.json.BenchmarkData 22 23 internal class MicrobenchmarkOutput( 24 val definition: TestDefinition, 25 val metricResults: List<MetricResult>, 26 val profilerResults: List<Profiler.ResultFile>, 27 val totalRunTimeNs: Long, 28 val warmupIterations: Int, 29 val repeatIterations: Int, 30 val thermalThrottleSleepSeconds: Long, 31 val reportMetricsInBundle: Boolean 32 ) { createBundlenull33 fun createBundle() = 34 Bundle().apply { 35 if (reportMetricsInBundle) { 36 // these 'legacy' CI output metrics are considered output 37 metricResults.forEach { it.putInBundle(this, PREFIX) } 38 } 39 InstrumentationResultScope(this) 40 .reportSummaryToIde( 41 testName = definition.outputTestName, 42 measurements = 43 Measurements(singleMetrics = metricResults, sampledMetrics = emptyList()), 44 profilerResults = profilerResults 45 ) 46 } 47 createJsonTestResultnull48 fun createJsonTestResult() = 49 BenchmarkData.TestResult( 50 name = definition.outputMethodName, 51 className = definition.fullClassName, 52 totalRunTimeNs = totalRunTimeNs, 53 metrics = metricResults, 54 warmupIterations = warmupIterations, 55 repeatIterations = repeatIterations, 56 thermalThrottleSleepSeconds = thermalThrottleSleepSeconds, 57 profilerOutputs = profilerResults.map { BenchmarkData.TestResult.ProfilerOutput(it) } 58 ) 59 } 60